Skip to content

fix(scanner): stop scanning the current directory when YARA is disabled#150

Merged
Karib0u merged 1 commit into
Karib0u:mainfrom
ymat19:fix/empty-yara-scanner
Jul 9, 2026
Merged

fix(scanner): stop scanning the current directory when YARA is disabled#150
Karib0u merged 1 commit into
Karib0u:mainfrom
ymat19:fix/empty-yara-scanner

Conversation

@ymat19

@ymat19 ymat19 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

When scanner.yara_enabled = false (or when loading the configured rules fails), all three platform runtimes built the fallback "empty" scanner with Scanner::new(Path::new(".")). Since Scanner::new recursively walks the given directory looking for .yar/.yara files, the agent ended up scanning whatever its current working directory happened to be at startup — with YARA explicitly disabled.

  • Add Scanner::empty(), which builds a zero-rule scanner without any filesystem access.
  • Use it in the disabled / load-failure fallbacks in runtime/windows.rs, runtime/linux.rs, and runtime/macos.rs (the now-unneeded Path imports are removed).
  • The normal rule-loading path (Scanner::new) is untouched.

Fixes #134

Verification

  • Unit test added: Scanner::empty() reports zero found/compiled/failed rule files. Full cargo test --locked passes on Linux and Windows.
  • cargo fmt --check and cargo clippy --locked --all-targets -- -D clippy::all pass on Linux and Windows targets.

End-to-end (Windows 11, YARA disabled, cwd = a large user-profile directory)

Startup (launch → ETW trace session started) Loading YARA rules from: "." in log spurious YARA compile warnings
before (b4e0293) >300 s (timed out, sensors never started) yes 7
after (this branch) 1.5 s no 0

No-regression checks (Windows 11, on this branch)

  • YARA disabled: the detection pipeline still works end to end — file create/write/rename/delete operations fire the corresponding Sigma rules, even when the agent is launched from the same large working directory that previously blocked startup.
  • YARA enabled: the configured rules directory loads normally (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.

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>
@ymat19 ymat19 marked this pull request as ready for review July 9, 2026 20:23
@Karib0u Karib0u merged commit 979d725 into Karib0u:main Jul 9, 2026
11 checks passed
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.

Agent recursively scans the current working directory when YARA is disabled

2 participants