llm-security/tests
Kjell Tore Guttormsen f926071348 fix(llm-security): compileRules coerces a non-string pattern instead of dropping the rule
new RegExp(pattern, 'i') never throws when pattern is a truthy non-string
(e.g. an object) — it ToString-coerces it first. The truthy-only guard
(`!rule.pattern`) let such a rule through as a real, compiled RegExp,
bypassing the try/catch meant to drop malformed rules. Worse than a silent
drop: `new RegExp("[object Object]", "i")` is parsed as a character class
over o/b/j/e/c/t/space, so the "dropped" rule instead becomes a
near-universal false-positive matcher. Same path for the built-in
commons-backed ruleset and the operator's sig.custom_rules_path (both
route through compileRules).

Fix: require typeof rule.pattern === 'string' before compiling. Verified
the golden dump pins no rule that exists only because of this coercion —
it regenerates byte-identically after the fix.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019iWrdLSVgRhgPzTB29rQGD
2026-08-13 21:51:10 +02:00
..
e2e test(llm-security): cover TRG/SIG/AST in e2e pipeline + SIG miner/hacktool/rot13 families (#58,#59) 2026-07-18 10:46:19 +02:00
fixtures refactor(llm-security): build the SIG ruleset from vendored commons (malware-signatures 0.1.0) 2026-08-13 21:28:14 +02:00
golden refactor(llm-security): build the SIG ruleset from vendored commons (malware-signatures 0.1.0) 2026-08-13 21:28:14 +02:00
helpers test(llm-security): add JetBrains fixture tree + build helper 2026-04-18 10:49:49 +02:00
hooks refactor(llm-security): build the secret table from vendored commons (secret-egress 0.3.0) 2026-08-13 21:10:14 +02:00
lib fix(llm-security): compileRules coerces a non-string pattern instead of dropping the rule 2026-08-13 21:51:10 +02:00
scanners fix(llm-security): compileRules coerces a non-string pattern instead of dropping the rule 2026-08-13 21:51:10 +02:00