- 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
71 lines
3.9 KiB
Bash
Executable File
71 lines
3.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# build-scope-tree.sh <root> [--big] -- a synthetic extracted backup that exercises the scan scope
|
|
# (policy code-risky-v1 of whp-scan-scope; the cases come from the six security-review rounds of the
|
|
# WHP scanscope package). No customer data. <root>/cpmove-scope/... is the layout of an extract.
|
|
#
|
|
# --big also add a SPARSE 2001 MiB clean mp4 (just above the 2000 MiB limit): it must show up in
|
|
# oversize_unscanned_files (named staff-review warning), never on the clamscan list.
|
|
#
|
|
# The EXPECT_* lists below are the contract tests check, one path per line relative to <root>.
|
|
set -euo pipefail
|
|
ROOT="${1:?usage: build-scope-tree.sh <root> [--big]}"
|
|
BIG=false; [[ "${2:-}" == "--big" ]] && BIG=true
|
|
T="$ROOT/cpmove-scope"
|
|
H="$T/homedir"
|
|
mkdir -p "$T/userdata" "$H/public_html/hd" "$H/public_html/uploads" "$H/tmp/site" "$H/tmp/work" "$H/etc" \
|
|
"$H/mail/example.com/alice/cur" "$H/logs"
|
|
|
|
# userdata: the main docroot and an addon docroot that lives under ~/tmp (served, so a web root)
|
|
cat > "$T/userdata/example.com" <<UD
|
|
documentroot: /home/scope/public_html
|
|
servername: example.com
|
|
UD
|
|
cat > "$T/userdata/site.example.com" <<UD
|
|
documentroot: /home/scope/tmp/site
|
|
servername: site.example.com
|
|
UD
|
|
|
|
# --- listed (scanned) ---
|
|
echo '<?php echo "hi";' > "$H/public_html/index.php" # code
|
|
printf '\xff\xd8\xff\xe0<?php system($_GET["c"]); ?>' > "$H/public_html/polyglot.jpg" # polyglot: JPEG magic + php (media under 20 MiB is always scanned)
|
|
printf '\xff\xd8\xff\xe0JFIF clean' > "$H/public_html/clean-small.jpg" # small media under a web root: scanned too
|
|
echo 'payload' > "$H/tmp/work/payload.txt"
|
|
ln -s ../tmp/work/payload.txt "$H/public_html/link.jpg" # web-root symlink: its TARGET is scanned
|
|
echo '<?php // in a docroot under ~/tmp' > "$H/tmp/site/page.php" # docroot-under-tmp: web root
|
|
echo 'plain data in a docroot under tmp' > "$H/tmp/site/notes.txt" # ... so even data is scanned there
|
|
printf 'AddHandler application/x-httpd-php .jpg\n' > "$H/public_html/hd/.htaccess" # handler directory: everything below is in scope
|
|
printf '\xff\xd8\xff\xe0JFIF in a handler dir' > "$H/public_html/hd/handled.jpg"
|
|
echo 'upload blob' > "$H/public_html/uploads/blob.dat" # uploads dir: scanned unless verified media
|
|
printf 'X5O!P%%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > "$H/public_html/eicar.php" # a real ClamAV hit
|
|
|
|
# --- skipped by policy ---
|
|
echo 'log line' > "$H/logs/access.log" # data outside a web root
|
|
echo 'a=1' > "$H/etc/data.txt"
|
|
echo 'Subject: hi' > "$H/mail/example.com/alice/cur/1700000000.M1P1.host,S=12:2,S" # mail (skipped with --skip-mail)
|
|
{ printf '\x00\x00\x00\x18ftypmp42'; head -c 22000000 /dev/zero; } > "$H/public_html/video.mp4" # clean media over 20 MiB: skipped (class media)
|
|
if $BIG; then
|
|
{ printf '\x00\x00\x00\x18ftypmp42'; } > "$H/public_html/huge.mp4"
|
|
truncate -s 2001M "$H/public_html/huge.mp4" # sparse, above the 2000 MiB limit
|
|
fi
|
|
|
|
cat > "$ROOT/EXPECT_LISTED" <<L
|
|
cpmove-scope/homedir/public_html/index.php
|
|
cpmove-scope/homedir/public_html/polyglot.jpg
|
|
cpmove-scope/homedir/public_html/clean-small.jpg
|
|
cpmove-scope/homedir/public_html/hd/.htaccess
|
|
cpmove-scope/homedir/public_html/hd/handled.jpg
|
|
cpmove-scope/homedir/public_html/uploads/blob.dat
|
|
cpmove-scope/homedir/public_html/eicar.php
|
|
cpmove-scope/homedir/tmp/site/page.php
|
|
cpmove-scope/homedir/tmp/site/notes.txt
|
|
cpmove-scope/homedir/tmp/work/payload.txt
|
|
L
|
|
cat > "$ROOT/EXPECT_NOT_LISTED" <<L
|
|
cpmove-scope/homedir/public_html/video.mp4
|
|
cpmove-scope/homedir/logs/access.log
|
|
cpmove-scope/homedir/etc/data.txt
|
|
L
|
|
# the mail message is NOT listed when --skip-mail is passed
|
|
echo "cpmove-scope/homedir/mail/example.com/alice/cur/1700000000.M1P1.host,S=12:2,S" > "$ROOT/EXPECT_MAIL"
|