Repository navigation
fix(ui): read a Markup URL the way Citry writes it in the link checks - #697
Merged
Merged
Conversation
Citry decodes the character references in a Markup value when it writes the value into an attribute. Citry UI's URL checks read the text before that decoding, so a scheme spelled with references passed the check and reached the page decoded. CButton href, CForm action and the formaction in CButton attrs and CSplitButton primary_attrs passed Markup through; the other URL inputs copy it to a plain string first. The checks now run Citry's own attribute writer and undo only its escaping, so they read exactly the text the browser gets. The security_javascript check of structured Script and Style dependencies had the same mismatch: in "omit" mode it left such a URL on the page. It now reads the value the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Read a non-str object with __html__ in a Script or Style attribute the way Citry writes it, too. - Say in the comments which characters the browser still reads differently (NUL, CR) and why that cannot let a refused scheme through, and update the Rust doc of _classify_dependency_attribute. - Check the exact URL each input writes for an ordinary Markup value, and cover Script(url=Markup(...)). - Lead both changelog entries with the outcome. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 15, 2026
This was referenced Nov 15, 2026
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.
Citry decodes the character references in a
Markupvalue when it writes the value into an attribute (escape_attribute_value, and the same for Vue data). Citry UI's URL checks read the text before that decoding, so a URL whose scheme is spelled with references, such asMarkup("javascript:alert(1)"), passed the check and reached the page ashref="javascript:alert(1)".What changes
citry_ui/components/_url.py: a newattribute_text()runs Citry's own attribute writer and undoes only its escaping.check_link_urlandis_image_url_allowedread the URL through it, so the check reads the text the page gets and cannot drift from the writer.CButton: theformactioncheck inattrspasses the value itself instead ofstr(value), which kept the references undecoded.CButtonhref,CFormaction, and theformactioninCButtonattrsandCSplitButtonprimary_attrs. The other URL inputs (CListItem,CMenuItem,CPagination,CBreadcrumbItem,CNavigationMenuLink,CAvatar,CImage) copy aMarkupvalue to a plain string before they check and write it, so the page shows its text as typed; tests now lock that too.citry/_javascript_policy.pyhad the same mismatch for structuredScriptandStyledependencies: withsecurity_javascript="omit", aMarkupjavascript:URL was reported but left on the page. It now reads the value the same way. (warnandforbidalready caught it through the whole-page check.)packages/py/citry_ui/CHANGELOG.mdand the rootCHANGELOG.md.A later change (C10) moves Citry UI's scheme reading into a shared Rust function; this one stays small so that change can build on it.
Checks
:,:,:, encoded letters, mixed case) for every link and image input, ordinaryMarkupURLs still accepted with the exact written text, andScript/Styledependencies inomitmode.test_url_schemes,test_serialize_security,test_output_policy, CButton, CForm, CSplitButton, CImage, CAvatar). Thecitryandcitry_uinon-browser suites pass locally except one type-check test that fails the same way onorigin/main(local citry-lsp setup) and one metadata test that reads the shared venv's stale install.--platform linux), rustfmt on the changed Rust doc comment.Review
An independent reviewer ran a security pass (every route a URL takes into Citry UI output, server HTML and Vue data,
attrs=arguments, cached renders) and tried about 38 spellings per input in Chromium, reading.href,.actionand.formAction; none reached a refused scheme after the fix. It also checked the change against the maintainers' advisory survey (URL scheme, second render path,srcset, decoding differences). Folded in:__html__in aScriptattribute skipped the decode; it is now read the same way.accept ordinary Markuptests only proved nothing raised; they now check the exact written URL. AddedScript(url=Markup(...))._classify_dependency_attributeupdated; changelog entries reworded to lead with the outcome.Left out of scope, not security-relevant (same root cause, noted for a follow-up):
validate_html_idreads aMarkupid before decoding (can give a broken id),_script_type_should_wrapreads aMarkuptypebefore decoding, and CAvatar's clientimg_attrscopy does not decodeMarkupwhile the server HTML does.attribute_text(Citry UI) and_written_attribute_text(citry) are the same two lines; Citry UI cannot import a new citry helper while it supportscitry>=0.9.0.🤖 Generated with Claude Code