Repository navigation
Read numeric references in attribute values as the browser does - #610
Merged
Merged
Conversation
… does The HTML parser Citry uses to read its own output decodes attribute values with `html.unescape`, which drops some code points (U+0001 to U+0008, U+000B, U+000E to U+001F, U+007F, noncharacters such as U+FDD0) that the browser keeps. The page id check and the other output parsers then read values that differ from the page the browser builds. `LongReferenceSafeParser` now hands its subclasses the values a browser reads, decoded with `decode_attribute_entities` from each tag's original text. The rewrite of long references keeps the text the same length, so the parser splits the rewritten tag as `HTMLParser` did and reads each value from the same span of the original. When the original text cannot be lined up with the tag, the handler gets the values `HTMLParser` gives. The parser keeps the original text only when one of its start tag handlers receives the browser's values, drops the part before the tag being read, and joins chunks only for a tag that spans more than one. Parsers that never read attribute values opt out of decoding them a second time. The warning for a repeated `id` writes control characters in an id as escapes, because an id can now hold one, such as ESC, that the old reading dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec
force-pushed
the
hardening/attribute-numeric-references
branch
from
November 14, 2026 15:29
b71b6e0 to
130bbb8
Compare
JuroOravec
marked this pull request as ready for review
November 14, 2026 15:29
This was referenced Nov 14, 2026
JuroOravec
added a commit
that referenced
this pull request
Nov 14, 2026
… checks (#674) A browser keeps the first of two attributes with the same name on one tag. The citry_ui checks of rendered fills read `dict(attrs)`, which keeps the last, so `<span tabindex="0" tabindex="-1">` passed the Listbox option check while the browser makes the span focusable. - `LongReferenceSafeParser` hands the start tag handlers of subclasses that read attributes each repeated name once, with its first value. The repeated `id` warning now counts only the first `id` of an element, and the Vue mount host check reads a repeated `id` the same way, so `<div id="app" ID="x">` is the host with one attribute. - The citry_ui checks read their tags through their own `first_attribute_occurrences`, because Citry UI also runs on Citry releases whose parser keeps every occurrence. - `LongReferenceSafeParser` holds back a lone `&` at the end of a chunk until the next chunk arrives, so a long decimal reference split right after the `&` no longer raises `ValueError`. That error made Citry skip its preload links for such a page. - The citry_ui check messages write control characters in a tag name as escapes such as `\x1b`. The citry_ui changelog also gets the entry for #610's stricter reading of numeric references in attribute values. Co-authored-by: Claude Opus 5.5 <[email protected]>
JuroOravec
added a commit
that referenced
this pull request
Nov 14, 2026
…ight merged changes (#682) Add one record under docs/security/reviews/ for each of the eight published 0.8.0 advisories (GHSA-4hj5, -8xvf, -7qpw, -g658, -x6rm, -h524, -xmx5, -xg8c) and for each of the pull requests that Mechanism 7, step 7 owes one: #610, #640, #651, #652, #653, #658, #674 and #675. Each record says only what the public pull request, the published advisory, the merged code and its tests show, and lists what was not checked. The reviews README describes how a record for a published advisory differs from a pull request record. The Mechanism 7 list in CLAUDE.md gains the two places that GHSA-7qpw added: parser rules browsers differ on, and the page's declared encoding. Co-authored-by: Claude Opus 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.
The HTML parsers that Citry uses to read its own output decoded attribute values with Python's
html.unescape. It drops some code points that a browser keeps, such as U+0001 and U+FDD0. With this change, those parsers (the repeated-id warning, the Vue host check, and the citry_ui output parsers) read the attribute values the browser reads.Changes
LongReferenceSafeParser(citry/util/html.py) now gives its start tag handlers the attribute values a browser reads, decoded withdecode_attribute_entitiesfrom each tag's original text. It keeps the original text only when one of its start tag handlers receives these values, and drops the part before the tag it is reading, so a page fed in small chunks costs time and memory in step with its length.HTMLParsergives. The same holds for a handler added after the class is created, set on an instance, or defined by a mixin that comes before the parser class; the class docstring says so._PreparedMarkupTrackerand_PreloadHeadLocatorin citry,_DirectMenuParserand_DirectItemParserin citry_ui.decode_attribute_entitiesalready decodes numeric references this way onmain, so its behavior does not change.CHANGELOG.mdhas one entry under## Unreleased, for the repeated-id warning.What the browser reads
The tests hold the table below. Chromium 156 and Firefox 157 each loaded a page with
title="a&#xN;b"for every row and returned the same value.to,,to,,,,,,€,Ÿ€,Ÿ, ,	�,�,�One difference is outside this change:
decodes to a carriage return, which Citry writes as is and the browser's HTML parser turns into a line feed. Plain string values behave the same way, so that belongs in a separate change.Tests
tests/test_attribute_numeric_references.py: the table above for the decoder and the parser, class and style pieces, static and interactive pages on both render paths, and the parser cases (quoted and unquoted values, long references including one in an attribute name, input split into many small feeds and a bound on the text the parser keeps, subclasses, handlers called by hand and throughsuper(), the opt-outs, the two cases above where a handler keepsHTMLParser's values, and the Vue host check).tests/test_page_ids.py: two ids that differ by a reference are different ids, and the warning spells out a control character.citry_ui/tests/test_output_parsers.py: the two opt-outs, and apopovervalue read as the browser reads it.main: ruff, and mypy (including--platform linux), are clean, and the focused citry and citry_ui suites pass. Three tests intests/test_check.py(reserved names inv-forandv-slot) need a citry_core build newer than the one I used, and fail the same way onmainwith it. About 6,000 generated start tags, split in many ways, read the same asmain's parser (names) and as a known answer (values) on CPython 3.11.15, 3.11.17, 3.12.15, 3.13.17, 3.14.9 and 3.15.1. Deleting any one of five guards in the parser (the alignment check, the name check, the chunk dropping, the ancestry check and the wrapper marker) makes a new test fail.🤖 Generated with Claude Code