fix(scanner): stop scanning the current directory when YARA is disabled#150
Merged
Conversation
Disabling YARA (or failing to load the configured rules) built the
fallback scanner with Scanner::new("."), which recursively walks the
process working directory looking for .yar files. Depending on where
the agent is launched from, that walk can block startup for minutes
and emit misleading compile warnings for unrelated rule files.
Add Scanner::empty(), which builds a zero-rule scanner without any
filesystem access, and use it in the disabled/load-failure fallbacks
of all three platform runtimes.
Fixes Karib0u#134
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
When
scanner.yara_enabled = false(or when loading the configured rules fails), all three platform runtimes built the fallback "empty" scanner withScanner::new(Path::new(".")). SinceScanner::newrecursively walks the given directory looking for.yar/.yarafiles, the agent ended up scanning whatever its current working directory happened to be at startup — with YARA explicitly disabled.Scanner::empty(), which builds a zero-rule scanner without any filesystem access.runtime/windows.rs,runtime/linux.rs, andruntime/macos.rs(the now-unneededPathimports are removed).Scanner::new) is untouched.Fixes #134
Verification
Scanner::empty()reports zero found/compiled/failed rule files. Fullcargo test --lockedpasses on Linux and Windows.cargo fmt --checkandcargo clippy --locked --all-targets -- -D clippy::allpass on Linux and Windows targets.End-to-end (Windows 11, YARA disabled, cwd = a large user-profile directory)
Loading YARA rules from: "."in logb4e0293)No-regression checks (Windows 11, on this branch)
Found 1 rule files, compiled 1 successfully) and a YARA alert fires as expected on a process scan. No working-directory walk happens in either mode.Same behavior confirmed on Linux with a synthetic 40k-entry tree as the working directory: the walk and the misleading compile warnings occur only before the fix, and the YARA-enabled load path is unchanged.
Not verified on macOS: the macOS runtime change is the same mechanical substitution as the other two platforms, but I could not runtime-test it — coverage there is compile/test via CI (
clippy-macos,test-macos) only.