Repository navigation
fix(permissions): withhold root-dotted webfetch host allows - #3851
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
A critical active finding remains because root-dot normalization fails for non-ASCII DNS labels, allowing an IDN host restriction to be bypassed until the normalization and regression coverage are fixed.
1 open issue
What changed in this PR
This PR improves webfetch permission overlap checks by treating a hostname’s terminal DNS root dot as equivalent to no root dot while preserving emitted permission patterns.
Changes:
- Normalize terminal root dots during URL host overlap comparisons, including port-bearing hosts.
- Add regression coverage for exact hosts, wildcard subdomains, ports, unrelated hosts, and all-tools restrictions.
- Preserve existing permission-pattern output and withholding behavior.
| File | Description |
|---|---|
| src/features/permissions/shadowed-allows.ts | Normalizes terminal DNS root dots in parsed URL hosts used for permission overlap checks. |
| src/features/permissions/shadowed-allows.test.ts | Adds regression tests for root-dotted hostname overlap and webfetch permission withholding behavior. |
Review effort: Lite
dyoshikawa
left a comment
There was a problem hiding this comment.
Thanks for picking this up. Treating example.com. and example.com as the same host is the right call, and the end-to-end test through honorAllToolsRestrictions is a nice touch.
I can't merge it as is, though. This code is meant to only ever withhold more than main, and the one-sided normalization breaks that for a few spellings. Because the dot is stripped only after [a-z0-9], a host ending in *. (or a non-ASCII label, _, ]) keeps its dot while the other side loses it, and a pair that main reported as overlapping no longer does. For example, with {"*": {"evil.*.": "deny"}, "webfetch": {"https://evil.com./x": "allow"}}, main withholds the allow: the hosts evil.*. and evil.com. intersect. With this PR it compares evil.*. against evil.com, which don't intersect, and the whole-string check doesn't catch it either, so the allow is written. The reverse direction (restriction evil.com., allow https://evil.*./x) behaves the same way. These spellings are unusual, but output that is looser than main is the one thing we avoid in this module.
The fix I'd suggest is to add a reading rather than replace the host, the same way stripUrlSchemeLoosely keeps the old interpretation around. Compare both the original host and the host with one trailing dot removed unconditionally (host.endsWith(".") ? host.slice(0, -1) : host), and count an overlap if any reading overlaps. Every pair main compared is still compared, so the change can only add overlaps. It also covers the non-ASCII case Copilot pointed out (example.рф.), which this PR doesn't fix yet. That one isn't a regression, just incomplete.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain, and the changes include targeted regression and adapter-level coverage for root-dotted host overlap and permission withholding.
No open issues 🎉
1 resolved since last review
Review effort: Lite

Addresses one narrow, previously open case in #3822 item 4; the other permission gaps remain open.
Security fix
A DNS hostname with a final root dot is equivalent to the same hostname without it. Before this change,
{"*":{"example.com":"deny"},"webfetch":{"https://example.com./private":"allow"}}could retain an auto-allow that the canonical deny should shadow.Verification
./node_modules/.bin/vp test run src/features/permissions/shadowed-allows.test.ts --silent=true— 128 passed../node_modules/.bin/vp test run src/features/permissions --silent=true— 2,864 passed, 58 files.vp fmt --check,vp lint --max-warnings 0, andtsgo --noEmit— passed.src/features/hooks/amp-hooks.test.tsrequires a Bun executable unavailable on this runner:spawn bun ENOENT).Other cases in #3822 (userinfo/query, absent categories, other adapters) remain out of scope.