Skip to content

[Test Quality] test: pin emitted raw-IP deny ACL patterns in squid config - #11865

Merged
lpcox merged 1 commit into
mainfrom
test-quality/raw-ip-acl-patterns-eff96f994b797a30
Nov 20, 2026
Merged

lpcox merged 1 commit into
mainfrom
test-quality/raw-ip-acl-patterns-eff96f994b797a30

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Contract

Raw IPv4 and IPv6 literals in CONNECT/HTTP destinations must be denied by the dst_ipv4 / dst_ipv6 ACLs emitted in src/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 in docs/test-analysis/domain-network.md (test #9, "should block IP address access when only domain is allowed") and docs/api-proxy-sidecar.md.

Weakness

src/squid-config-security.test.ts ("Direct IP bypass protection") checks only that the strings acl dst_ipv4 dstdom_regex and http_access deny dst_ipv4 appear 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.ts in a working copy, run against the original test file, then restored (checksum verified).

Mutant Change Original suite (35 tests) Updated suite (37 tests)
M1 IPv4 regex replaced with one that never matches 35/35 pass (missed) 1 fails: Expected: true, Received: false
M2 IPv4 regex unanchored (^ / $ removed) 35/35 pass (missed) 1 fails on 1.2.3.4.example.com
M3 IPv6 character class widened to include . 35/35 pass (missed) 1 fails on cafe.bad.fade

Change

Test-only, one file (src/squid-config-security.test.ts, +35 lines, no production code changes). Adds a nested describe with two tests:

  • dst_ipv4 matches 1.2.3.4, 10.0.0.1, 192.168.1.1, 255.255.255.255, and does not match github.com, api.github.com, 1.2.3.4.example.com, 1.2.3.
  • dst_ipv6 matches ::1, [::1], fe80::1, [2001:db8::1], and does not match github.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 scoped eslint-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.yml and build.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.

Generated by Test Quality Improver · copilot · routed: haiku55 xhigh · ~22 AIC · ⌖ ~2 AIC · ⊞ 5.4K · ◷

  • expires on Dec 20, 2026, 12:45 PM UTC

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]>
@lpcox
lpcox marked this pull request as ready for review November 20, 2026 14:39
Copilot AI adaptive review requested due to automatic review settings November 20, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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)

@github-actions

Copy link
Copy Markdown
Contributor Author

✅ Copilot review passed with no inline comments.

@github-actions[bot] Add the ready-for-aw label to this PR to trigger agentic CI smoke tests.

@github-actions

Copy link
Copy Markdown
Contributor Author

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

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

@lpcox
lpcox merged commit a59c736 into main Nov 20, 2026
39 of 41 checks passed
@lpcox
lpcox deleted the test-quality/raw-ip-acl-patterns-eff96f994b797a30 branch November 20, 2026 17:40
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.

2 participants