Repository navigation
fix: output-check reports name the component and see forms the way the browser does - #309
Merged
Merged
Conversation
…rol's form as its fallback The strict-CSP and JavaScript-policy reports named a component only when the reported element itself carried a data-cid attribute, so a finding inside a component's outer element said "settled render output". In omit mode the check also did not know that a control sits inside a <form>, so a submit button there was reported as having no fallback. The output check now reads where the browser put each element from the tree the HTML parser builds. Citry's receiver for the parser's tree (TrackingSink) records the element each start tag makes and whether the parser tied it to the form its form pointer names (the last <form> not yet closed by </form>). Each finding's list of component ids (cids) holds the element's own data-cid suffixes, then those of the elements that contain it, nearest first, so Python names the innermost known component with no change to the binding's shape. The walk also steps from a <template>'s children to the template, and it matches SVG names that the parser spells with capitals. An HTML control counts as owned by a form when the parser tied it to one, or, as in the browser, when a <form> contains it outside a template's contents; the handler-only rule uses that. Both answers are read when the parser inserts the element, so a later move by the parser's repair of a misnested formatting tag is not seen; a test records that limit. Implied end tags, misnested tags and tables move elements the way they move in the browser. The frozen Python copy reads a flat list of tags, so the differential comparison (outcomes_match) allows exactly two differences: Rust may name a component where the copy names none, and Rust may leave out a handler-only finding on a control that a form earlier in the page can submit. Every other finding, message, order, offset and warn-or-raise outcome must match. A report header's count is checked against its own lines, because a left-out finding changes it. New tests cover nested components, slot content, implied and misnested closes, tables, SVG, templates, a button inside a form, one after its form closed, one after a </form> that left its <div> open, one inside a <template> inside a form, and an SVG <button> inside a form. Fixes #290. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e side Three tests in test_output_policy.py make the Python tag reader or the Rust call fail on purpose, so with CITRY_OUTPUT_POLICY_DIFFERENTIAL=1 the comparison with the frozen Python rules reported that failure as a difference. They now skip when that flag is set, and run as before without it. 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.
Fixes #290.
What changes
With
security_csporsecurity_javascriptset,serialize()reportswhat the finished page holds. Two parts of those reports were wrong for
any element that is not a component's outermost tag:
the reported element itself carried the component's
data-cid-*attribute, so anything nested inside a component's outer tag was
reported as "settled render output". Now the report names the innermost
component whose outer element contains the reported element in the
page the browser builds. Content passed into a slot is reported under
the component that renders the slot.
omitmode misreported a control inside a form. A submit button, aninput, a
selector atextareainside a<form>was reported ashaving no fallback, although the browser can submit the form without
JavaScript. Now it is not. A
type="button"button and an input oftype
buttonorresetare still reported, because they never submit.How
The output check already reads the page with html5ever's tree builder. It
now also reads where the tree builder put each element:
TrackingSinkincrates/citry_html_transform/src/output_scanner.rs) records the elementeach start tag makes, and whether the parser tied it to the form its
form pointer names (the last
<form>not yet closed by</form>;html5ever calls
associate_with_formfor this, so a control in a tableinside a form counts too, as in the browser).
event's
cidslist the element's owndata-cid-*suffixes, then thoseof the elements that contain it, nearest first. Python already names the
first known one, so the binding's tuple shape is unchanged; only its docs and
_rust.pyisay what the list now holds.<template>'s children in a separate fragment withno parent. The sink points that fragment at its template, so an element
inside
<template v-if>still reaches the component around it.<svg>the parser spells some names with capitals(
foreignObject), so the sink matches the element name without regardto case.
or, as the browser decides for a control the parser did not tie, when a
<form>contains it. The second case covers<form><div></form>witha later button inside the
<div>. A form outside a<template>doesnot own what is inside the template, and a
<button>inside<svg>isnot a control.
is_handler_only_controluses this next to theformattribute.
Known limit: the owner and the component ids are read when the parser
inserts the element. The parser can still move an element later when it
repairs a misnested formatting tag. For example, in
<b><form><div></form><button>...</b>the</b>moves the<div>outof the form, so in the browser the button ends with no owner, but the
check counts the form. A Rust test records this answer so a later fix
changes it on purpose.
Because the positions come from the tree the browser builds, implied end
tags (
<p>closed by<div>, a second<li>), misnested tags and fosterparenting place elements the way the browser does. For example, a link
inside
<p>…<div>is not named after the<p>'s component, because the<div>closed the<p>.The walk runs only for tags that produce an event, so a clean page costs
one recorded pointer per tag.
How it was checked
Rust unit tests on the parent walk: nested components (innermost first),
SVG content, an SVG element with a capitalized name, an element inside
a
<template>and inside nested templates, a<p>closed by<div>, a second<li>, a closedcomponent followed by a link, a link the parser moves out before a
table, a misnested
</b>; and form cases: a button, an input, aselectand atextareainside a form, a button in a table inside aform, a button with a
formattribute, and, still reported, a buttonoutside any form, one after its form closed, a
type=button, and oneinside a
<template>inside a form, and an SVG<button>inside aform. Also with a fallback: a button inside a form inside a template, a button
after a
</form>that left its<div>open (the browser gives it theform that contains it), and one after
<div><form></div>(the formpointer still ties it to the form).
Python end-to-end tests serialize crafted components: a finding inside
a component's root, inside a nested component, in slot content (named
after the component that renders the slot), a link moved out of a
component's root by an implied close, a submit button inside a form, and
a button after its form closed.
The frozen Python copy of the rules reads a flat list of tags, so it
cannot see the tree. The differential comparison (seeded pages, and the
opt-in whole-suite run) goes through
outcomes_matchinpackages/py/citry/tests/_output_policy_reference.py. It allows only thetwo differences this PR makes on purpose, and each in one direction:
name the same one. Only when the copy names no component may Rust
name one.
that is not
type=button, an input that is not typebuttonorreset, aselect, atextarea). Rust may leave such a findingout, because the copy cannot see the form, but only when a
<form>start tag comes earlier in the page. Rust may not add one.
Everything else must match in both directions and in order: every other
finding (rule, detail, attribute, offsets), the result, the report
lines, and whether the check warns or raises. A report header's count
is checked against its own lines, and a warning may disappear only when
every line in it is one Rust may leave out. This is stricter than
masking both sides, which would also accept a wrong name on an
element's own
data-cid-*or an extra Rust finding. Two mistakes wouldstill pass this comparison: a wrong ancestor component for an element
with no
data-cid-*of its own, and a handler-only finding left out fora control that is not really in a form. The Rust unit tests and the
end-to-end tests above cover those. A throwaway harness confirmed that
outcomes_matchrejects a droppedtype=buttonfinding, an addedfinding, a reordered pair, and a renamed known component.
Existing locked messages that changed (findings nested inside a
component's root now name it) were updated from the observed output.
The whole-suite run with
CITRY_OUTPUT_POLICY_DIFFERENTIAL=1(thecitry and citry-ui suites) passed 11,466 tests. 3 tests failed, and none
of them involve this change: they make the Python tag reader or the
Rust call fail on purpose. The second commit in this PR (test-only) skips
those 3 tests when the flag is set. Without the flag they run and pass
as before.
The fast gate (
scripts/check.py --profile fast) passed.🤖 Generated with Claude Code