Repository navigation
[Test Quality] test: pin emitted raw-IP deny ACL patterns in squid config - #11865
Merged
Merged
Conversation
The existing 'Direct IP bypass protection' tests only checked that the dst_ipv4/dst_ipv6 ACL and deny lines appear as substrings. A broken or over-broad regex body would still pass. Evaluate the emitted patterns against IP literals and domain names so the test fails for the intended reason. Verified with three temporary mutations of the generated regexes (never-matching IPv4, unanchored IPv4, widened IPv6 character class): the original suite passes all three; the updated suite fails each one. Production code is unchanged. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for this test-only expansion of raw-IP ACL regression coverage.
No open issues 🎉
What changed in this PR
This test-only PR strengthens regression coverage for AWF’s generated raw-IP deny ACLs without changing production behavior.
Changes:
- Extracts IPv4 and IPv6 regex patterns directly from generated Squid configuration.
- Adds positive and negative cases to check literal-IP matching and avoid matching domain names.
- Evaluates patterns with JavaScript regex semantics; real Squid behavior remains outside this unit coverage.
| File | Description |
|---|---|
src/squid-config-security.test.ts |
Adds two tests covering emitted IPv4 and IPv6 ACL patterns. |
Review effort: Balanced (adaptive)
Contributor
Author
|
✅ Copilot review passed with no inline comments. @github-actions[bot] Add the |
Contributor
Author
|
| Metric | Base | PR | Delta |
|---|---|---|---|
| Lines | 94.40% | 94.39% | 📉 -0.01% |
| Statements | 93.01% | 93.00% | 📉 -0.01% |
| Functions | 93.61% | 93.57% | 📉 -0.04% |
| Branches | 87.28% | 87.27% | 📉 -0.01% |
📁 Per-file Coverage Changes (2 files)
| File | Lines (Before → After) | Statements (Before → After) |
|---|---|---|
src/nvx/one-shot-process.ts |
84.0% → 81.5% (-2.47%) | 76.8% → 74.7% (-2.11%) |
src/routing/bootstrap.ts |
91.0% → 90.0% (-1.00%) | 86.6% → 85.3% (-1.34%) |
Coverage comparison generated by scripts/ci/compare-coverage.ts
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.
Contract
Raw IPv4 and IPv6 literals in CONNECT/HTTP destinations must be denied by the
dst_ipv4/dst_ipv6ACLs emitted insrc/squid/config-generator.ts. Domain names must not match those ACLs, or they would be denied before domain allowlisting runs. This is the direct-IP bypass protection described indocs/test-analysis/domain-network.md(test #9, "should block IP address access when only domain is allowed") anddocs/api-proxy-sidecar.md.Weakness
src/squid-config-security.test.ts("Direct IP bypass protection") checks only that the stringsacl dst_ipv4 dstdom_regexandhttp_access deny dst_ipv4appear in the generated config. It never evaluates the regex. A broken, unanchored, or over-broad pattern passes every existing assertion.Missed regressions (verified)
Each mutant was applied to
src/squid/config-generator.tsin a working copy, run against the original test file, then restored (checksum verified).Expected: true, Received: false^/$removed)1.2.3.4.example.com.cafe.bad.fadeChange
Test-only, one file (
src/squid-config-security.test.ts, +35 lines, no production code changes). Adds a nesteddescribewith two tests:dst_ipv4matches1.2.3.4,10.0.0.1,192.168.1.1,255.255.255.255, and does not matchgithub.com,api.github.com,1.2.3.4.example.com,1.2.3.dst_ipv6matches::1,[::1],fe80::1,[2001:db8::1], and does not matchgithub.com,api.github.com,cafe.bad.fade,abc.def.The emitted pattern is read from the generated config, so the test checks what Squid receives rather than a copy of the regex. Positive and negative inputs are fixed literals, independent of the production expression. The negatives include all-hex dotted hostnames, which is what catches the widened-class mutant.
The one
new RegExp(...)on trusted generator output carries a scopedeslint-disable-next-line security/detect-non-literal-regexp. Lint on the file reports zero warnings, as before the change.Validation
Commands run from the repository root:
npm run build: passes../node_modules/.bin/jest --runInBand --no-coverage --runTestsByPath src/squid-config-security.test.ts: 37/37 pass on the unchanged code../node_modules/.bin/jest --runInBand --no-coverage --runTestsByPath src/squid-config-security.test.ts src/squid-config-core.test.ts src/squid-config-policy.test.ts src/squid/policy-manifest.test.ts src/squid/policy-rules/section-builders.test.ts: 125/125 pass across 5 suites../node_modules/.bin/eslint src/squid-config-security.test.ts: 0 errors, 0 warnings.npm run type-check: passes.Discovery and CI: the file is under
src/, so root Jest (npm test, run by.github/workflows/root-unit-tests.ymlandbuild.yml) picks it up.Limitations
This is process-level unit evidence. It checks the regex text that AWF generates and evaluates it with JavaScript regex semantics. Squid uses POSIX ERE through
dstdom_regex, so the test does not prove identical matching in a real Squid process. Integration tests that exercise real raw-IP blocking need Docker and sudo, which were not available in this environment, so they did not run.