Skip to content

Malware scanners: --max-file-size flag and single-file scan targets - #297

Merged
jasperf merged 1 commit into
mainfrom
add/scanner-max-file-size
Nov 17, 2026
Merged

jasperf merged 1 commit into
mainfrom
add/scanner-max-file-size

Conversation

@jasperf

@jasperf jasperf commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

This PR extends the malware scanners in wp-cli/security/ with a configurable pattern-scan size cap and single-file targeting, resolving #230. Previously, both scanner-general.php and scanner-targeted.php hardcoded a 5MB limit on pattern scanning and only accepted a directory as the target, which meant a large file not covered by any checksum manifest received neither a pattern scan nor a checksum comparison. Both scanners now accept --max-file-size= in raw bytes or KB/MB/GB form, and a single file can be passed as the scan path — in that case the file is pattern-scanned without a size cap and without checksum filtering. malware-scan.sh passes the new option through to the streamed scanners over SSH and Trellis VM shells, with option construction that avoids empty-array expansion for bash 3.2 compatibility under set -u, and the script catalog (go/internal/catalog/catalog.json) was regenerated.

Scanner size cap and single-file targets:

  • Both scanner-general.php and scanner-targeted.php parse a --max-file-size= flag (plain bytes or a 20MB-style value) instead of hardcoding the 5MB pattern-scan threshold, letting operators trade scan time for coverage on large files.
  • The scan path argument now accepts a single file as well as a directory: a file target is pattern-scanned directly, with no size cap applied and no checksum-based filtering, closing the gap where an oversized file skipped both checks.
  • scanner-wrapper.php routes the new flag and target type through to both scanners.

Shell wrapper and stream passthrough:

  • malware-scan.sh adds a --max-file-size SIZE option and documents it in the usage text, catalog annotations, and examples (--max-file-size 20MB). --path now also accepts a single file on the target host.
  • The flag is forwarded as --max-file-size=$VALUE next to the positional scan path for both remote modes (SSH and trellis vm shell), and is omitted entirely when not set because bash 3.2 with set -u treats an empty array expansion as unbound.

Catalog and changelog:

  • go/internal/catalog/catalog.json was regenerated to reflect the updated malware-scan.sh metadata and annotations.
  • CHANGELOG.md records the new --max-file-size option and single-file targeting under [Unreleased].

Verification (all run on this branch):

  • php -l clean on all three edited PHP files.
  • /bin/bash -n wp-cli/security/malware-scan.sh (system bash 3.2) — clean; go test ./... passes, including the bash-3.2 parse guard.
  • Single-file scan of a 6MB file (php .../scanner-targeted.php /tmp/scantest/bigfile.js): Max File Size: not applied (single file), Found 1 files to scan, checksum verification skipped as intended. Same for scanner-general.php.
  • Directory scan of the same tree with default cap: Found 0 files to scan, skip reason File too large (5.72 MB); with --max-file-size=10MB: Found 1 files to scan.
  • --max-file-size=abc exits 1 with Error: Invalid --max-file-size: abc.
  • No risk areas: scanners stay read-only; nothing is written to target hosts.

Files Changed:

Both scanners hardcoded a 5MB pattern-scan cap and only accepted a
directory as a target, so a large file not covered by any checksum
manifest got neither check. Both now read --max-file-size= (bytes or a
KB/MB/GB form), and accept a single file as the scan path: the file is
pattern-scanned as asked, with no size cap and no checksum filtering.
malware-scan.sh passes a --max-file-size option through to the
streamed scanners, built without empty-array expansion for bash 3.2
set -u. Catalog regenerated.

Resolves #230.
@jasperf
jasperf merged commit 8596dc9 into main Nov 17, 2026
2 checks passed
@jasperf
jasperf deleted the add/scanner-max-file-size branch November 17, 2026 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant