Skip to content

fix(permissions): withhold root-dotted webfetch host allows - #3851

Merged
dyoshikawa merged 3 commits into
dyoshikawa:mainfrom
jdotc1:fix/3822-webfetch-trailing-root-dot
Nov 17, 2026
Merged

dyoshikawa merged 3 commits into
dyoshikawa:mainfrom
jdotc1:fix/3822-webfetch-trailing-root-dot

Conversation

@jdotc1

@jdotc1 jdotc1 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • Compare both the original host reading and a reading with one final DNS root dot removed, after isolating any port. Keeping the original reading guarantees the change cannot remove overlaps the base branch detected.
  • Preserve original emitted permission patterns; the overlap check can withhold an additional unsafe allow but cannot grant permission.
  • Cover exact and wildcard hosts, port-bearing URLs, IDNs, uppercase hostnames, both wildcard-dot asymmetries, unrelated hosts, and the full all-tools-deny-to-webfetch-allow flow.

Verification

  • Regression-first: four overlap cases and four end-to-end withholding cases failed against the reviewed implementation, then passed with the fix.
  • ./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, and tsgo --noEmit — passed.
  • Full repository suite: 17,025 passed, one unrelated test blocked (src/features/hooks/amp-hooks.test.ts requires a Bun executable unavailable on this runner: spawn bun ENOENT).
  • No new dependencies or configuration surface.

Other cases in #3822 (userinfo/query, absent categories, other adapters) remain out of scope.

Copilot AI lite review requested due to automatic review settings November 15, 2026 15:07

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.

🟡 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 dyoshikawa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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.

Copilot AI lite review requested due to automatic review settings November 16, 2026 14:25

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

@dyoshikawa
dyoshikawa merged commit 8a8e557 into dyoshikawa:main Nov 17, 2026
6 checks passed
@dyoshikawa

Copy link
Copy Markdown
Owner

Thanks @jdotc1! Adding the root-dot reading on top of the original one keeps the check monotonic, and the IDN and *. cases are covered. Merged. A few small follow-ups (a JSDoc note, port/IPv6 test cases, repeated trailing dots) are tracked in #3861.

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.

3 participants