Scan only the WHP scan scope: whp-scan-scope + clamscan --file-list, scan attestation in report.json
- Dockerfile: multi-stage Go build of whp-scan-scope (CGO off, stdlib only) from a PINNED commit of the WHP repo (ARG WHP_COMMIT, currently the merge of WHP #331; bump it to the merge of the 2000 MiB limit PR before publishing an image meant to enforce it). Private repo: the BuildKit secret whp_token in CI; --build-context whp-src=<checkout> for local builds. - scan-files.php: whp-scan-scope -> /tmp/scan.list + stats, then clamscan --file-list with --max-filesize=2000M --max-scansize=4000M --max-scantime=0 --alert-exceeds-max=yes --tempdir on the disk scratch. A missing/failing tool, clamscan exit >= 2 or 0 loaded signatures is FATAL (no fall back to an unscoped scan). Writes the attestation (the tool's stats + engine_version, signature_db_version, signatures_loaded, clamscan_exit). - entrypoint.sh: passes --attestation/--scratch, removes the scratch, embeds the attestation as report.json "scan" (objects kept as objects). - Tests: tests/run-tests.sh (stub clamscan, real tool, fail-closed cases), tests/build-scope-tree.sh (polyglot, web-root symlink, docroot under tmp, handler dir, uploads, EICAR, sparse 2001 MiB mp4), tests/image-scope-test.sh (end to end on the built image; CI runs it). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
This commit is contained in:
1 parent
228eb94ad5
commit
7da863cfd1
9 files changed
+469
-137
No files matched your search
+18
-2
@@ -162,13 +162,19 @@ if [[ "$IMPORT_INCLUDE_MAIL" == "true" ]]; then
|
||||
# The extracted mail tree is not scanned (see scan-files.php --skip-mail).
|
||||
SCAN_FILES_EXTRA+=(--skip-mail)
|
||||
fi
|
||||
# clamscan unpacks archives into --tempdir: on the disk-backed bind mount (never the RAM tmpfs /tmp,
|
||||
# which counts against --memory). Removed again right after the scan.
|
||||
CLAM_SCRATCH="$WORK_DIR/clamtmp"
|
||||
php /scripts/scan-files.php \
|
||||
--extract "$EXTRACT_DIR" \
|
||||
--quarantine "$QUARANTINE_DIR" \
|
||||
--report /tmp/scan-files-report.json \
|
||||
--attestation /tmp/scan-attestation.json \
|
||||
--scratch "$CLAM_SCRATCH" \
|
||||
--import-id "$IMPORT_ID" \
|
||||
"${SCAN_FILES_EXTRA[@]}" \
|
||||
|| die "scan-files.php failed; see stderr above"
|
||||
|| { rm -rf "$CLAM_SCRATCH"; die "scan-files.php failed (scope tool or clamscan error: the scan did not complete); see stderr above"; }
|
||||
rm -rf "$CLAM_SCRATCH"
|
||||
|
||||
# --- DB engine swap + WP content scan -------------------------------------
|
||||
|
||||
@@ -216,6 +222,15 @@ $dbsPath = $argv[4];
|
||||
$strippedPath = $argv[5];
|
||||
$outPath = $argv[6];
|
||||
$mailIncluded = $argv[7] === "true";
|
||||
$attestPath = $argv[8];
|
||||
|
||||
// The scan attestation (engine fields + the whole scope stats of whp-scan-scope), written by scan-files.php.
|
||||
// Decoded as objects so an empty skipped_by_class stays {} (not []). No attestation = no report.
|
||||
$scan = is_file($attestPath) ? json_decode(file_get_contents($attestPath)) : null;
|
||||
if (!is_object($scan)) {
|
||||
fprintf(STDERR, "report: scan attestation missing or unreadable: %s\n", $attestPath);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$files = is_file($filesPath) ? json_decode(file_get_contents($filesPath), true) : null;
|
||||
$dbs = is_file($dbsPath) ? json_decode(file_get_contents($dbsPath), true) : null;
|
||||
@@ -280,6 +295,7 @@ $report = [
|
||||
// mail tree. Older images never write the key; the panel treats a
|
||||
// missing/false value as "mail was not extracted".
|
||||
"mail_included" => $mailIncluded,
|
||||
"scan" => $scan,
|
||||
"actions" => $actions,
|
||||
"databases" => $databases,
|
||||
"summary_for_panel" => [
|
||||
@@ -291,7 +307,7 @@ $report = [
|
||||
|
||||
file_put_contents($outPath, json_encode($report, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n");
|
||||
fprintf(STDERR, "report written: %s\n", $outPath);
|
||||
' "$IMPORT_ID" "$DURATION" /tmp/scan-files-report.json /tmp/scan-dbs-report.json "$STRIPPED_SYMLINKS_FILE" "$SANITIZED_DIR/report.json" "$IMPORT_INCLUDE_MAIL" \
|
||||
' "$IMPORT_ID" "$DURATION" /tmp/scan-files-report.json /tmp/scan-dbs-report.json "$STRIPPED_SYMLINKS_FILE" "$SANITIZED_DIR/report.json" "$IMPORT_INCLUDE_MAIL" /tmp/scan-attestation.json \
|
||||
|| die "report merge failed"
|
||||
|
||||
log "done — exited cleanly after ${DURATION}s"
|
||||
|
||||
Reference in new issue
Block a user