Repository navigation
refactor: read URL schemes with one Rust reader on the server (#601) - #718
Merged
Merged
Conversation
Every server-side check that reads a URL's scheme now calls one Rust function, `url_scheme` / `url_scheme_is` in crates/citry_html_transform/src/url_scheme.rs, written to the WHATWG URL rules. It decodes no character references; callers keep decoding where they did. - The output checks (`is_javascript_url`) and the `data:` document and meta refresh readers use it directly. - A private PyO3 function, `_read_url_scheme`, is wrapped once in the new `citry._urls`, which `Redirect`, the no-JavaScript redirect resolver and Citry UI's link and image checks now call. - The browser copies (client.js `redirectScheme`, CAvatar/CImage `isImageUrlAllowed`) are unchanged and tested against a shared table, crates/citry_html_transform/tests/fixtures/url_schemes.json, as are the Rust reader, the binding and every Python caller. A Playwright test checks the table against real browsers. The output checks no longer report `javascript:` spelled with the long s or a dotted or dotless i, which browsers read as relative URLs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
4 tasks done
…me-reader # Conflicts: # docs/design/trust_boundaries.md
JuroOravec
added a commit
that referenced
this pull request
Nov 16, 2026
* docs: record the security reviews of #713, #714, #718 and #722 Adds the Mechanism 7 step 7 records for four merged pull requests: GHSA-x773 (#713, reserved attribute names as c-bind keys), #714 (out-of-date pages and the rolling-deploy check), #718 (one Rust URL scheme reader), and GHSA-7fjh (#722, reserved data-* names in Citry UI attribute maps). The two advisory records name the advisory and the affected and fixed versions; the facts come from the pull requests. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * docs: link the #720 follow-up from the #714 review record Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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.
Follow-up to #601 for citry 1.0.0, implementing the approved C10 plan (v2).
Merge order: this PR should merge last, right before the 1.0.0 release candidate. See "Expected red
pyodide-smoke" below.What changes
Each server-side check that read a URL's scheme had its own copy of the rule: four in Python and three in Rust. Now one Rust function reads it the way the browser's URL parser does, and every server-side check calls it.
url_schemeandurl_scheme_islive incrates/citry_html_transform/src/url_scheme.rs. They skip leading U+0000 to U+0020, drop tab, LF and CR anywhere, accept an ASCII letter followed by ASCII letters, digits,+,-or.up to:, and compare letters as ASCII only. They decode no character references. Callers keep decoding exactly where they did before (decode_html_attribute, fix(ui): read a Markup URL the way Citry writes it in the link checks #697'sattribute_textand_written_attribute_text).is_javascript_urlnow callsurl_scheme_is(letter_matchesis deleted).decode_data_url_documentandrefresh_data_urlkeep their own trimming and slicing and ask the reader only "is itdata", so their answers stay the same._read_url_scheme(stub in_rust.pyi), is wrapped once in the new private modulecitry._urls.actions.redirect_url_scheme(Redirect),routes._resolve_redirect_url(the no-JavaScript form path) and Citry UI'scheck_link_urlandis_image_url_allowedcall it. Their own scheme readers and constants are deleted.redirectSchemeinclient.jsandisImageUrlAllowedin CAvatar and CImage are not edited, soruntime.jsdoes not change. They are tested against the same table.crates/citry_html_transform/tests/fixtures/url_schemes.jsonholds 93 rows. The Rust tests, the binding, every Python caller, the JS redirect test, the Citry UI browser image rule and a Playwright test all read it.tests/test_urls_module.pylocks the names and signatures ofcitry._urlsfor 1.x, because Citry UI imports the module.The one change users can see
security_csp,security_javascriptandcitry checkno longer reportjavaſcript:,javascrıpt:orjavascrİpt:, including when written asſorıin attribute text. Browsers read these as relative URLs and run nothing. A Playwright test clicks such links in Chromium, Firefox and WebKit and checks that nothing runs, next to a control link that does run. This makes the check less strict, which the 1.x rules allow. The changelog has one entry. Redirect, the Events redirect resolver, Citry UI and thedata:readers keep their exact answers.Expected red
pyodide-smokeThe
pyodide-smokejob buildscitryandcitry-uifrom the checkout, but installs the published citry-core named indocs_site/static/playground/runtime.json(2.0.0).citry._urlsimports the new_read_url_schemeat module level, and citry-core 2.0.0 does not have it. So the job fails on this PR, and on every later PR, until the docs release after 1.0.0 updatesruntime.json.The job is not a required check. The required checks (
check,citry-ui-wheel-build) use the citry-core wheel built from the checkout. Moving the import inside a function to keep the job green would hide a real version mismatch, so this PR does not do that. That is why it should merge last, right before the release candidate.Not in this PR (the release PR owns these)
citry-core==pin in citry, anduv.lock.Cargo.lockgains one line, for aserde_jsondev-dependency ofcitry_html_transform(already pinned in the workspace).citry>=1.0.0,<2. Until then, Citry UI onmaindeclarescitry>=0.9.0but needscitry._urls. No Citry UI release is planned before 1.0.0.Checks
cargo test -p citry_html_transform -p citry_core_py,cargo clippy,cargo fmt: pass. The Rust tests compare the reader with a separately written reference reader over the table and over 20,000 strings from a fixed seed. The alphabet includesſ,ı,İ, U+212A, U+000B, U+007F, U+00A0, U+FEFF and U+200B.data:readers: a test locks their answers. Before locking them, I ran the same inputs through the code onorigin/mainand through this branch, and the answers were identical.scripts/check.py --profile fast:PASSED, every phase. It ran before the review edits; after them I reran the focused Rust, Python and JS checks and mypy.--platform linux: clean.CITRY_OUTPUT_POLICY_DIFFERENTIAL=1run of the output-policy tests: pass. The Python reference regex is now ASCII-only, and the page generator rarely picks the lookalike letters, so most generated URLs still read asjavascript:.da\tta:andda\nta:at all, so they load nothing; the test allows that for those two named rows only.check_output_htmlin a release build on a 470 KB page with 10,000 URL attributes. Median 9.57 ms and 9.66 ms after the change, against 9.71 ms and 9.76 ms before. No slowdown; the budget was 5%.Independent review
xss-url,xss-url-svg,sanitizer-bypass,open-redirect,redos,header-injandclient-url. The change introduces none of them. Findings fixed in this PR:docs/design/trust_boundaries.mdrows whose files this change moved: updated.citry._urlsandurl_scheme.rsoverclaimed "every server-side check": they now name the callers.https:base could hide a relative row. It now runs against two bases and allows parse failures only for the two named Firefox rows.data:image/rule it tests. The scheme and the rest still come from the table, so the reader itself is tested.trust_boundaries.md, which fix(ui): read a Markup URL the way Citry writes it in the link checks #697 asked to delete on merge.docs-cold-readerwas not run, because no docs page or public docstring changed (citry._urlsis private).🤖 Generated with Claude Code