Repository navigation
fix(browser): report SVG xlink:href links in dom_urls - #1602
Conversation
DOM snapshots have no namespace URI, so SVG context is an svg ancestor outside foreignObject. When href is missing, report xlink:href as href with the same base URL and origin policy. Fixes morluto#1586
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
TL;DR: The PR fixes #1586. SVG links with only I ran
Not run
Thanks, sathariels, for the quick fix and the clear tests. Commandsgit --git-dir=$HOME/code/rea-mirror/rea.git archive <sha> | tar -x -C <dir>
npm ci --no-audit --no-fund && npm run build # Node 24
chromium-browser --headless=new --remote-debugging-port=<port> --user-data-dir=<fresh dir> --password-store=basic about:blank
python3 -I -m http.server 8751 --bind 127.0.0.1 --directory site
node truth2.mjs <port> <target> http://127.0.0.1:8751/<page> # Chromium's own view
node scripts/rea.mjs inspect-web-page http://127.0.0.1:<port> <target> --format json
node scripts/run-development-tests.mjs focused src/browser/CdpCaptureDocuments.baseUrl.test.ts tests/boundary/browser/cdpSvgXlinkHref.test.ts
npm run check:fast # from a clone at 2eb66a15eThe Test pagesEach XHTML page has the same elements as the HTML page of the same name, plus the
<!doctype html><title>case1-h</title>
<svg width="40" height="40">
<defs><g id="g0"/></defs>
<a id="a1" xlink:href="/xl-a1"><text>a</text></a>
<image id="im1" xlink:href="/xl-im1.png" width="1" height="1"/>
<use id="u1" xlink:href="/sprite.svg#icon"/>
<use id="u2" xlink:href="#g0"/>
</svg>
<!doctype html><title>case2-h</title>
<svg width="40" height="40">
<a id="b1" href="/href-wins1" xlink:href="/xl-loses1"><text>1</text></a>
<a id="b2" xlink:href="/xl-loses2" href="/href-wins2"><text>2</text></a>
<a id="e1" href="" xlink:href="/xl-e1"><text>3</text></a>
<a id="e2" xlink:href="/xl-e2" href=""><text>4</text></a>
<a id="e3" href=""><text>5</text></a>
</svg>
<a id="h1" xlink:href="/xl-html-h1">html h1</a>
<a id="h2" href="/href-h2" xlink:href="/xl-html-h2">html h2</a>
<a id="h3" href="" xlink:href="/xl-html-h3">html h3</a>
<!doctype html><title>case3</title>
<svg id="o1" width="300" height="200">
<a id="p1" xlink:href="/xl-p1"><text>p1</text></a>
<foreignObject id="fo1" width="200" height="100">
<div id="fd1" xlink:href="/xl-fd1">div</div>
<a id="fa1" xlink:href="/xl-fa1">html a in foreignObject</a>
<a id="fa3" href="/href-fa3">html a href in foreignObject</a>
<p><span><a id="fa2" xlink:href="/xl-fa2">deep html a</a></span></p>
<svg id="ns1"><a id="na1" xlink:href="/xl-na1"><text>x</text></a></svg>
</foreignObject>
<svg id="ns2"><a id="na2" xlink:href="/xl-na2"><text>y</text></a></svg>
<g id="g1"><g id="g2"><image id="im1" xlink:href="/xl-im1.png"/></g></g>
</svg>
<iframe id="fr1" src="/frame.html"></iframe>
<!doctype html><title>frame</title>
<svg width="20" height="20"><a id="fr-a1" xlink:href="/xl-fr-a1"><text>f</text></a><a id="fr-a2" href="/href-fr-a2"><text>g</text></a></svg>
<a id="fr-h1" xlink:href="/xl-fr-h1">html</a>
<!doctype html><base href="/sub/dir/"><title>case4</title>
<svg width="40" height="40">
<a id="r1" xlink:href="rel/x"><text>1</text></a>
<a id="r2" href="rel/x"><text>2</text></a>
<a id="j1" xlink:href="javascript:void(1)"><text>j</text></a>
<a id="j2" href="javascript:void(1)"><text>j</text></a>
<a id="d1" xlink:href="data:text/plain,hi"><text>d</text></a>
<a id="d2" href="data:text/plain,hi"><text>d</text></a>
<a id="c1" xlink:href="https://cdn.example.test/out"><text>c</text></a>
<a id="c3" xlink:href="http://localhost:8751/other-origin"><text>c</text></a>
</svg>
<!doctype html><title>case5</title>
<svg width="40" height="40">
<defs><g id="g0"/></defs>
<use id="u1" xlink:href="#g0"/>
<use id="u2" href="#g0"/>
<image id="im3" xlink:href="#g0" width="1" height="1"/>
<a id="a1" xlink:href="#sec"><text>a1</text></a>
<rect id="rc1" xlink:href="/xl-rect" width="1" height="1"/>
</svg>The prefixed XHTML case: <svg:svg xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="10" height="10">
<svg:a id="pa1" xlink:href="/xl-pa1"><svg:text>p</svg:text></svg:a>
</svg:svg>Test setup
🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
Welcome to REA, @sathariels! Thanks for adding SVG |
|
Thanks @CassieFox23 for checking, and thanks @morluto for the merge and the cache! I reproduced the prefixed case in Chrome: |
fix(browser): report SVG xlink:href links in dom_urls
Summary
inspect-web-pageomitteddom_urlsentries for SVG links written only asxlink:href. Chromium still follows those links: an SVG<a>with onlyxlink:hrefhashref.baseValset and matches:any-link, while an HTML<a xlink:href>does not. This reports the SVG value ashrefwhenhrefitself is missing, so thedom_urlsschema stays the same.Fixes #1586.
Problem and expected behavior
On an SVG
<a xlink:href="/xl-s2h">with nohref,domMetadatainsrc/browser/CdpCaptureDocuments.tslooked up onlyhref,src,action,formaction, andposter. The node was present withattribute_namesincludingxlink:href, anddom_urlshad no entry.Expected: the same entry
dom_urlsalready produces for<a href="/xl-s2h">: attributehref, URL resolved against the document base, and the existing origin policy. When both attributes are present,hrefwins, including an emptyhref. An HTML element with onlyxlink:hrefstays unreported.Change and scope
DOMSnapshot.captureSnapshotdoes not include a namespace URI (confirmed on Chrome 148: document and node keys have no namespace field). SVG context is therefore structural:svg, orsvg, andforeignObject.Chrome's HTML parser records those local names as
svgandforeignObject. HTML elements are uppercase (A), so an HTML anchor is not SVG context. HTML insideforeignObjectstops the walk; a nestedsvgstarts it again. A cyclic or out-of-range parent index fails closed and does not reportxlink:href.Inside that context, a missing
hreffalls back to the exact attribute namexlink:href. The fallback uses the same first-wins attribute map, base URL, anddomDestinationpolicy ashref, and is stored with attribute"href".browserObservationSchemas.tsis unchanged.Intentionally not included:
divhrefbehavior (already reported today; left as-is).rectand other SVG elements that carryxlink:hrefare reported the same way REA already reportshrefon elements Chromium does not treat as links. Chrome'shrefIDL reflectsxlink:hreffora,image,use,script,feImage,textPath, gradients,pattern,filter, andmpath, and does not forrect.createElementNSand inserted outside anysvgancestor. Chrome does treat an orphan SVG<a xlink:href>as a link, but the snapshot cannot distinguish that nodeNameafrom a MathML or XHTMLa.Contract and boundary impact
domMetadatain the browser CDP capture adapter, while normalizing aDOMSnapshot.captureSnapshotresult intometadata.dom_urls. No earlier capture stage changes.dom_urls[].attributeenum stayshref | src | action | formaction | poster. Pages that previously omitted SVGxlink:hreflinks now include those URLs ashref.svg/foreignObject/ uppercase HTML).hrefvalues (resolved URL plusdestination_scope). Observed attribute names on the DOM node stayxlink:href.docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs andskills/; edit authored instructions inskill-src/and never commit build outputs): none. No authored skill, schema, or package metadata change.Evidence and regression coverage
src/browser/CdpCaptureDocuments.baseUrl.test.ts: xlink-only SVG<a>(first duplicate wins),hrefwins in either order, HTML<a>and MathMLmrowwith onlyxlink:hrefstay unlisted, outside-policy origin, SVGimageanduseresolved against the document base,foreignObjectstops SVG context and a nestedsvgresumes it, emptyhrefbeatsxlink:href,javascript:is unsupported, cyclic and dangling parent indexes are not SVG.tests/boundary/browser/cdpSvgXlinkHref.test.ts: real headless Chrome loads the issue page (plus HTML, image, use, and a foreign origin) andCdpBrowserProvider.inspectPagechecksmetadata.dom_urls. Skipped when no Chrome-family executable is installed.6d8f95e3(upstream/main), before the production change,npm run test:focused -- src/browser/CdpCaptureDocuments.baseUrl.test.tsfailed 6 tests. Each xlink-only case receivedurls: []instead of anhrefentry. Example: "reports an SVG anchor that only has xlink:href" expectedhttps://app.example.test/xl-s2hand received[]. Thehref-wins, empty-href, and non-SVG cycle cases already passed because noxlink:hreffallback existed.CdpBrowserProvider.inspectPageis the provider behind CLI and MCP. For the issue anchor the entry is:{ "node_index": 3, "attribute": "href", "url": "https://app.example.test/xl-s2h", "destination_scope": "approved" }The real Chrome run resolved
/xl-s2h,/href-wins,/xl-image, and/xl-useon the loopback origin ashref/approved, reported thehttps://cdn.example.test/outlink ashref/outside_policywithurl: null, and left the HTML<a xlink:href="/xl-html">out ofdom_urls. The compiled CLI was not invoked.svgancestor (script-inserted orphan) is not reported.xlink:hrefon SVG elements whose IDLhrefdoes not read it, such asrect, is reported.npm run verify:browserwas not run.npm run docs:checkwas not run; no docs or contracts changed.npm run checkdid not finishverify:architecture-guardsbecauseformat:checkfails on two pre-existing files. That guard was run separately and passed.For evidence-bearing changes:
Validation performed
npm ci(Node v24.18.0, npm 11.16.0) - exit 0, 376 packages installed.npm run test:focused -- src/browser/CdpCaptureDocuments.baseUrl.test.tson the base revision, tests only - exit 1. 6 failed, 26 passed (32). Failing cases received[]for xlink-only SVGa, HTML-page SVGa, outside-policy, image/use, nested svg, andjavascript:xlink:href.npm run test:focused -- src/browser/CdpCaptureDocuments.baseUrl.test.tsafter the fix - exit 0. 32 passed.npm run test:focused -- tests/boundary/browser/cdpSvgXlinkHref.test.ts- exit 0. 1 passed (headless Chrome 148.0.7778.96). Repeated after a small assertion tightening; still 1 passed.npm run test:focused -- src/browser/CdpCaptureDocuments.baseUrl.test.ts tests/boundary/browser/cdpSvgXlinkHref.test.ts- exit 0. 33 passed.npm run verify:test-discovery- exit 0. Discovered all 766 test files exactly once.npm run check- exit 1.format:checkreports pre-existing issues insrc/apktool/ApktoolProvider.tsandsrc/application/UpdateMaintenance.ts. Those two files are unmodified and fail the same check onupstream/main(6d8f95e3). Lint in that run finished with 623 warnings and 0 errors. Turbo stopped thecheckscript beforeverify:architecture-guards.npm run typecheck- exit 0.npm run knip- exit 0.npm run verify:architecture-guards- exit 0. Architecture guards passed across 1076 source files.npm run check:fast(typecheck and lint) - exit 0 duringgit push.Compatibility, safety, and release
xlink:hrefwithouthrefgaindom_urlsentries. Callers that assumed those links were absent will now see them.CdpBrowserProvider.inspectPage. Not the fullverify:browserlane. No Hopper, Ghidra, Firefox, or Safari run.url: nullwith an explicit scope. The Chrome test binds127.0.0.1and deletes its profile directory. No new process authority.Review checklist
type(scope): outcome.