Repository navigation
[Test Quality] Assert policy manifest wildcard regexes match semantically - #11503
Conversation
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported, and the changes focus on more specific wildcard-policy validation for legitimate subdomains and rejection of invalid or attacker-suffixed domains.
No open issues 🎉
What changed in this PR
Strengthens policy-manifest tests so wildcard regex entries are validated for semantic domain matching rather than merely being non-empty.
Changes:
- Requires each wildcard policy rule to emit exactly one regex entry.
- Verifies valid subdomains match the generated regexes.
- Verifies attacker-suffixed and invalid domains are rejected.
| File | Description |
|---|---|
| src/squid/policy-manifest.test.ts | Adds semantic matching and rejection assertions for blocked, HTTP-only, and HTTPS-only wildcard policy regexes. |
Review effort: Lite (auto)
|
✅ Copilot review passed with no inline comments. @github-actions[bot] Add the |
|
@copilot merge main and resolve conflicts |
…-regex-anchor-cf3fd841534c264b Co-authored-by: lpcox <[email protected]>
Merged |
Contract
generatePolicyManifestemits regex entries for wildcard allow/deny rules (deny-blocked-regex,allow-http-only-regex,allow-https-only-regex).src/logs/audit-enricher.tscompiles these entries withnew RegExpto attribute Squid log hosts to rules. The patterns come fromsrc/domain-patterns.ts, which documents them as anchored to match the full domain.Previous weakness
The three tests in
src/squid/policy-manifest.test.tsonly asserteddomains.length > 0. Any non-empty regex passed, including an unanchored one that would attributesub.evil.com.attacker.netto a rule.Change
Each of the three tests now asserts exactly one entry, then compiles it. The entry must match
sub.<host>and must rejectsub.<host>.attacker.netandnot<host>. No tests were removed.Evidence
./node_modules/.bin/jest --runInBand --no-coverage --runTestsByPath src/squid/policy-manifest.test.tspassed 19/19.$anchor insrc/domain-patterns.ts. With the original tests, the same file still passed 19/19. A first draft of my new negatives usedevil.com.attacker.net, which an unanchored pattern also rejects because of the leading\., so it also passed. After I switched tosub.<host>.attacker.net, the new tests failed 3/19, on the intended regex-match assertions.security/detect-non-literal-regexpwarnings from the intentionalnew RegExpcalls on manifest entries.CI
The file is picked up by the root Jest
src/**/*.test.tsrun in the existing build/test CI job.Limits
Component-level check only. It does not exercise real Squid or container enforcement.