Skip to content

lab-ops-hub: refuse crawl hosts whose NFKC mapping creates a delimiter (#567) - #570

Merged
dezren39 merged 1 commit into
mainfrom
sweep/567-nfkc-mapped-delimiters
Oct 22, 2026
Merged

dezren39 merged 1 commit into
mainfrom
sweep/567-nfkc-mapped-delimiters

Conversation

@dezren39

@dezren39 dezren39 commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Fixes #567

Problem

PR #533's decode-and-judge checked host delimiters on the percent-decoded form, but validate_crawl_url then NFKC-mapped the host with no structural re-check. A percent-encoded compatibility character decodes to an innocent codepoint whose NFKC mapping is a delimiter — U+FF0F → /, U+FF1A → :, U+FF20 → @, U+FF03 → #, U+FF1F → ?, U+FF3C → \, U+FF3B/U+FF3D → [/], U+FF05 → %, U+2100 → a/c, U+2105 → c/o — and the mapped delimiter was spliced into the returned URL. Reproduced on main 87624089:

  • http://localhost%ef%bc%8fexample.com/ → ALLOW, returned http://localhost/example.com/ (fetcher connects to localhost, never judged)
  • same ALLOW for 127.0.0.1 / 192.168.0.1 + %ef%bc%8f, and every delimiter case in the issue battery
  • the Worker blocks every case; raw fullwidth spellings are blocked by urlparse's NFKC netloc guard, but the percent spelling is pure ASCII in the raw netloc so that guard never fires. Exposed via _ValidatingRedirectHandler (raw Location, no Worker gate).

Solution

In pkgs/lab-ops-hub/container/app.py, after the full mapping pipeline (NFKC → ideographic-dot translation → UTS-46 ignored deletion), re-check the structural characters on the mapped form and refuse any mapped delimiter in % # / : ? @ [ \ ] — including a mapped %, which the decode step guarantees cannot survive and mapping must not reintroduce. A colon is exempt only inside a bracketed IPv6 literal; an unbracketed mapped colon is a delimiter, not an address. This also covers raw (non-percent) hosts as defence in depth.

Verification

  • Issue battery (14 spellings, incl. localhost/127.0.0.1/192.168.0.1 + U+FF0F and the U+2100/U+2105 expansions): all BLOCK in Python, matching the Worker verdicts probed directly against src/lib.ts.
  • Controls unchanged: %65xample.com, 8%2e8%2e8%2e8, U+FF5E→~ (exam~ple.com) still ALLOW in both validators; bracketed IPv6, fullwidth public names, port/userinfo substitution intact.
  • Suites: TS 26/26 (was 25), Python 25/25 (was 22). New tests: Python mapped-delimiter battery, redirect-handler refusal for a 192.168.0.1%ef%bc%8f target, re-parse invariant (every accepted percent-encoded URL re-parses to exactly the judged host), TS parity battery.
  • Ablation: reverting only app.py fails the new refusal tests (2 failures); with the fix all pass. ruff format --check clean on both Python files.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Bug Fixes
    • Improved URL validation to reject addresses whose normalized host contains URL delimiters, including percent-encoded compatibility characters. This helps prevent ambiguous host interpretations during validation and redirects.
    • Added coverage for rejected delimiter mappings and accepted normalized hosts.

#567)

_percent_decode_host refused delimiters in the percent-decoded form,
but validate_crawl_url then NFKC-mapped the host with no structural
re-check: a percent-encoded compatibility character (U+FF0F -> /,
U+FF1A -> :, U+FF20 -> @, U+FF05 -> %, U+2100 -> a/c) spliced a
delimiter into the returned URL, so the container fetched a host
that was never judged — localhost%ef%bc%8fexample.com validated as
http://localhost/example.com/. Re-check % # / : ? @ [ \ ] on the
fully mapped form (colon exempt only inside a bracketed IPv6
literal) and refuse any mapped delimiter.

Tests: Python battery of 14 mapped-delimiter spellings plus the
localhost/127.0.0.1/192.168.0.1 + U+FF0F cases, a redirect-handler
refusal for a mapped-delimiter target, and a re-parse invariant for
accepted percent-encoded URLs (returned URL re-parses to exactly
the judged host); TS parity battery in lib.test.ts (Worker already
refuses all of these). Ablation: reverting app.py fails the new
refusal tests.
@dezren39
dezren39 requested a review from a team as a code owner October 22, 2026 08:04
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-22T08:04:59.750467Z bac38fe PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 17094089-0826-42f4-a46f-631f566c4382
📥 Commits

Reviewing files that changed from the base of the PR and between 8762408 and bac38fe.

📒 Files selected for processing: 3
  • pkgs/lab-ops-hub/container/app.py
  • pkgs/lab-ops-hub/test/lib.test.ts
  • pkgs/lab-ops-hub/test/test_container_validate.py
+-----------------------------------------------------------------------------------------------------------------------------------+
| Don't use manual procedures. A shell script or batch file will execute the same instructions, in the same order, time after time. |
+-----------------------------------------------------------------------------------------------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dezren39
dezren39 merged commit 7a9ac87 into main Oct 22, 2026
4 of 5 checks passed
@dezren39
dezren39 deleted the sweep/567-nfkc-mapped-delimiters branch October 22, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant