Skip to content

fix(ui): read a Markup URL the way Citry writes it in the link checks - #697

Merged
JuroOravec merged 3 commits into
mainfrom
fix/ui-url-check-markup
Nov 15, 2026
Merged

JuroOravec merged 3 commits into
mainfrom
fix/ui-url-check-markup

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

Citry decodes the character references in a Markup value 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 as Markup("javascript:alert(1)"), passed the check and reached the page as href="javascript:alert(1)".

What changes

  • citry_ui/components/_url.py: a new attribute_text() runs Citry's own attribute writer and undoes only its escaping. check_link_url and is_image_url_allowed read the URL through it, so the check reads the text the page gets and cannot drift from the writer.
  • CButton: the formaction check in attrs passes the value itself instead of str(value), which kept the references undecoded.
  • Affected inputs: CButton href, CForm action, and the formaction in CButton attrs and CSplitButton primary_attrs. The other URL inputs (CListItem, CMenuItem, CPagination, CBreadcrumbItem, CNavigationMenuLink, CAvatar, CImage) copy a Markup value 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.py had the same mismatch for structured Script and Style dependencies: with security_javascript="omit", a Markup javascript: URL was reported but left on the page. It now reads the value the same way. (warn and forbid already caught it through the whole-page check.)
  • Changelog entries in packages/py/citry_ui/CHANGELOG.md and the root CHANGELOG.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

  • New tests fail on the old code and pass now: entity-encoded schemes (:, :, :, encoded letters, mixed case) for every link and image input, ordinary Markup URLs still accepted with the exact written text, and Script/Style dependencies in omit mode.
  • Focused suites pass (test_url_schemes, test_serialize_security, test_output_policy, CButton, CForm, CSplitButton, CImage, CAvatar). The citry and citry_ui non-browser suites pass locally except one type-check test that fails the same way on origin/main (local citry-lsp setup) and one metadata test that reads the shared venv's stale install.
  • ruff, mypy (also --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, .action and .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:

  • A non-str object with __html__ in a Script attribute skipped the decode; it is now read the same way.
  • The comment claiming the unescaped text is "exactly" the browser's was too strong (the browser also maps NUL to U+FFFD and CR to LF); reworded, with why it cannot let a scheme through.
  • The accept ordinary Markup tests only proved nothing raised; they now check the exact written URL. Added Script(url=Markup(...)).
  • Rust doc of _classify_dependency_attribute updated; 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_id reads a Markup id before decoding (can give a broken id), _script_type_should_wrap reads a Markup type before decoding, and CAvatar's client img_attrs copy does not decode Markup while 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 supports citry>=0.9.0.

🤖 Generated with Claude Code

JuroOravec and others added 2 commits November 15, 2026 12:44
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]>
@JuroOravec
JuroOravec merged commit aed98a9 into main Nov 15, 2026
1 of 15 checks passed
@JuroOravec
JuroOravec deleted the fix/ui-url-check-markup branch November 15, 2026 15:12
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.

1 participant