Repository navigation
Malware scanners: --max-file-size flag and single-file scan targets - #297
Merged
Merged
Conversation
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.
This was referenced Nov 17, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR extends the malware scanners in
wp-cli/security/with a configurable pattern-scan size cap and single-file targeting, resolving #230. Previously, bothscanner-general.phpandscanner-targeted.phphardcoded 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.shpasses 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 underset -u, and the script catalog (go/internal/catalog/catalog.json) was regenerated.Scanner size cap and single-file targets:
scanner-general.phpandscanner-targeted.phpparse a--max-file-size=flag (plain bytes or a20MB-style value) instead of hardcoding the 5MB pattern-scan threshold, letting operators trade scan time for coverage on large files.scanner-wrapper.phproutes the new flag and target type through to both scanners.Shell wrapper and stream passthrough:
malware-scan.shadds a--max-file-size SIZEoption and documents it in the usage text, catalog annotations, and examples (--max-file-size 20MB).--pathnow also accepts a single file on the target host.--max-file-size=$VALUEnext to the positional scan path for both remote modes (SSH andtrellis vm shell), and is omitted entirely when not set because bash 3.2 withset -utreats an empty array expansion as unbound.Catalog and changelog:
go/internal/catalog/catalog.jsonwas regenerated to reflect the updatedmalware-scan.shmetadata and annotations.CHANGELOG.mdrecords the new--max-file-sizeoption and single-file targeting under[Unreleased].Verification (all run on this branch):
php -lclean 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.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 forscanner-general.php.Found 0 files to scan, skip reasonFile too large (5.72 MB); with--max-file-size=10MB:Found 1 files to scan.--max-file-size=abcexits 1 withError: Invalid --max-file-size: abc.Files Changed:
CHANGELOG.md(Modified)go/internal/catalog/catalog.json(Modified)wp-cli/security/malware-scan.sh(Modified)wp-cli/security/scanner-general.php(Modified)wp-cli/security/scanner-targeted.php(Modified)wp-cli/security/scanner-wrapper.php(Modified)