Skip to content

fix(browser): report SVG xlink:href links in dom_urls - #1602

Merged
morluto merged 2 commits into
morluto:mainfrom
sathariels:fix/dom-urls-svg-xlink-href
Oct 10, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
sathariels:fix/dom-urls-svg-xlink-href

Conversation

@sathariels

Copy link
Copy Markdown
Contributor

fix(browser): report SVG xlink:href links in dom_urls

Summary

inspect-web-page omitted dom_urls entries for SVG links written only as xlink:href. Chromium still follows those links: an SVG <a> with only xlink:href has href.baseVal set and matches :any-link, while an HTML <a xlink:href> does not. This reports the SVG value as href when href itself is missing, so the dom_urls schema stays the same.

Fixes #1586.

Problem and expected behavior

On an SVG <a xlink:href="/xl-s2h"> with no href, domMetadata in src/browser/CdpCaptureDocuments.ts looked up only href, src, action, formaction, and poster. The node was present with attribute_names including xlink:href, and dom_urls had no entry.

Expected: the same entry dom_urls already produces for <a href="/xl-s2h">: attribute href, URL resolved against the document base, and the existing origin policy. When both attributes are present, href wins, including an empty href. An HTML element with only xlink:href stays unreported.

Change and scope

DOMSnapshot.captureSnapshot does not include a namespace URI (confirmed on Chrome 148: document and node keys have no namespace field). SVG context is therefore structural:

  • the element nodeName is svg, or
  • an ancestor nodeName is svg, and
  • a closer ancestor is not foreignObject.

Chrome's HTML parser records those local names as svg and foreignObject. HTML elements are uppercase (A), so an HTML anchor is not SVG context. HTML inside foreignObject stops the walk; a nested svg starts it again. A cyclic or out-of-range parent index fails closed and does not report xlink:href.

Inside that context, a missing href falls back to the exact attribute name xlink:href. The fallback uses the same first-wins attribute map, base URL, and domDestination policy as href, and is stored with attribute "href". browserObservationSchemas.ts is unchanged.

Intentionally not included:

  • MathML and div href behavior (already reported today; left as-is).
  • A tag whitelist. rect and other SVG elements that carry xlink:href are reported the same way REA already reports href on elements Chromium does not treat as links. Chrome's href IDL reflects xlink:href for a, image, use, script, feImage, textPath, gradients, pattern, filter, and mpath, and does not for rect.
  • SVG elements created with createElementNS and inserted outside any svg ancestor. Chrome does treat an orphan SVG <a xlink:href> as a link, but the snapshot cannot distinguish that nodeName a from a MathML or XHTML a.

Contract and boundary impact

  • Semantic owner and earliest changed stage: domMetadata in the browser CDP capture adapter, while normalizing a DOMSnapshot.captureSnapshot result into metadata.dom_urls. No earlier capture stage changes.
  • CLI and MCP/tool-catalog contract: none. The dom_urls[].attribute enum stays href | src | action | formaction | poster. Pages that previously omitted SVG xlink:href links now include those URLs as href.
  • Provider, bridge, target-format, or platform compatibility: Chrome-family CDP DOM snapshots only. No bridge or target-format change. Behavior depends on Chrome's nodeName casing (svg / foreignObject / uppercase HTML).
  • Evidence, artifact, provenance, or reconstruction contract: none. The added entries are the same derived URL records as existing href values (resolved URL plus destination_scope). Observed attribute names on the DOM node stay xlink:href.
  • Process execution, authorization, cleanup, or containment impact: none. Destination policy and URL sanitization are unchanged. The new test launches a local headless Chrome only when an executable is already installed.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in skill-src/ and never commit build outputs): none. No authored skill, schema, or package metadata change.

Evidence and regression coverage

  • Tests added or updated:
    • src/browser/CdpCaptureDocuments.baseUrl.test.ts: xlink-only SVG <a> (first duplicate wins), href wins in either order, HTML <a> and MathML mrow with only xlink:href stay unlisted, outside-policy origin, SVG image and use resolved against the document base, foreignObject stops SVG context and a nested svg resumes it, empty href beats xlink: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) and CdpBrowserProvider.inspectPage checks metadata.dom_urls. Skipped when no Chrome-family executable is installed.
  • Base reproduction or other evidence: executed. On 6d8f95e3 (upstream/main), before the production change, npm run test:focused -- src/browser/CdpCaptureDocuments.baseUrl.test.ts failed 6 tests. Each xlink-only case received urls: [] instead of an href entry. Example: "reports an SVG anchor that only has xlink:href" expected https://app.example.test/xl-s2h and received []. The href-wins, empty-href, and non-SVG cycle cases already passed because no xlink:href fallback existed.
  • User-visible CLI/MCP output (if applicable): CdpBrowserProvider.inspectPage is 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-use on the loopback origin as href / approved, reported the https://cdn.example.test/out link as href / outside_policy with url: null, and left the HTML <a xlink:href="/xl-html"> out of dom_urls. The compiled CLI was not invoked.

  • Remaining proof gaps:
    • An SVG element with no svg ancestor (script-inserted orphan) is not reported.
    • xlink:href on SVG elements whose IDL href does not read it, such as rect, is reported.
    • Firefox and Safari were not tested.
    • npm run verify:browser was not run.
    • npm run docs:check was not run; no docs or contracts changed.
    • npm run check did not finish verify:architecture-guards because format:check fails on two pre-existing files. That guard was run separately and passed.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

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.ts on the base revision, tests only - exit 1. 6 failed, 26 passed (32). Failing cases received [] for xlink-only SVG a, HTML-page SVG a, outside-policy, image/use, nested svg, and javascript: xlink:href.
  • npm run test:focused -- src/browser/CdpCaptureDocuments.baseUrl.test.ts after 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:check reports pre-existing issues in src/apktool/ApktoolProvider.ts and src/application/UpdateMaintenance.ts. Those two files are unmodified and fail the same check on upstream/main (6d8f95e3). Lint in that run finished with 623 warnings and 0 errors. Turbo stopped the check script before verify: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.
  • Pre-push npm run check:fast (typecheck and lint) - exit 0 during git push.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The result schema is unchanged. Inspections of pages that contain SVG xlink:href without href gain dom_urls entries. Callers that assumed those links were absent will now see them.
  • Real Hopper/Ghidra, browser, or OS coverage: headless Google Chrome 148.0.7778.96 on Linux, one loopback page through CdpBrowserProvider.inspectPage. Not the full verify:browser lane. No Hopper, Ghidra, Firefox, or Safari run.
  • Package or release metadata impact: none. No changelog edit.
  • Security, privacy, process, or containment review: destinations still go through the existing http(s) allowlist and URL sanitizer. Outside-policy and non-http values stay url: null with an explicit scope. The Chrome test binds 127.0.0.1 and deletes its profile directory. No new process authority.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

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
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: The PR fixes #1586. SVG links with only xlink:href now show up in dom_urls, in HTML and XHTML pages. One new gap is left: a prefixed <svg:a> in an XHTML page still gets no entry.

I ran inspect-web-page on 0d8997833 (main) and on 2eb66a15e (this PR), then compared both with what Chromium says about each element. The pages with href only gave the same output on both builds.

Case Chromium main PR
SVG a with only xlink:href, our #1586 page, HTML and XHTML a link no entry href entry
SVG image and use with only xlink:href href.baseVal is set, not a link no entry href entry
href and xlink:href together, either order href wins href entry same as main
Empty href plus xlink:href href wins page URL as href same as main
HTML a with only xlink:href not a link no entry no entry
HTML a or div inside foreignObject, with only xlink:href not a link no entry no entry
svg nested in foreignObject or in svg, and svg in an iframe a link no entry href entry
Relative xlink:href under a <base> element a link no entry URL resolved against <base>
javascript:, data: and other-origin xlink:href a link no entry unsupported or outside_policy, same as href
use xlink:href="#frag" href.baseVal is #frag, not a link no entry page URL plus #frag
Prefixed <svg:a xlink:href> in XHTML a link no entry no entry
Our #1516 pages (uppercase HREF, SRC and so on) unchanged same as f6009d007 same as main
  • The prefixed case: Chromium names those nodes svg:svg and svg:a, and the PR looks for the exact name svg.
  • The PR lists a second gap itself: a script-made SVG a with no svg parent. I saw it too: Chromium treats it as a link, and neither build lists it.
  • The PR also lists xlink:href on rect, script, gradients and textPath. Chromium does not treat those as links, and main already lists plain href on them.
  • The PR's two test files pass on the PR on Node 22, 24 and 26 (33 tests each). On main, with Node 24, 7 of them fail. npm run check:fast passes on the PR.

Not run

  • Firefox, Safari, or any Chromium besides 154.
  • The full test suite, npm run check, verify:browser and docs:check.
  • capture-browser-scenario and the MCP route. I used the CLI.
  • Real-world SVG pages. I only used small test pages.

Thanks, sathariels, for the quick fix and the clear tests.

Commands
git --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 2eb66a15e

The truth2.mjs script walks every element that has an id, same-origin iframes too. For each one it prints the href value Chromium holds, the resolved URL, and whether the element matches :any-link.

Test pages

Each XHTML page has the same elements as the HTML page of the same name, plus the xmlns and xmlns:xlink declarations.

case1.html

<!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>

case2.html

<!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>

case3.html

<!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>

frame.html

<!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>

case4.html

<!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>

case5.html (the fragment cases)

<!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
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1 (both trees built with 24.18.0)
  • Head / main at test time: 2eb66a15e / 0d8997833
  • Other: the Chromium browser, version 154
  • Licence: BSD-3-Clause
  • Build: 154.0.8037.57, the one Fedora 44 ships
  • Browser run: headless, with a fresh profile for each tree

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto
morluto merged commit 0f605bc into morluto:main Oct 10, 2026
17 of 19 checks passed
@morluto

morluto commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Welcome to REA, @sathariels! Thanks for adding SVG xlink:href discovery and covering href precedence, document bases, and origin policy. I added a per-document ancestry cache to keep deeply nested pages from slowing down capture. The source tests and headless Chrome regression test passed locally. Squash-merged.

@sathariels

Copy link
Copy Markdown
Contributor Author

Thanks @CassieFox23 for checking, and thanks @morluto for the merge and the cache! I reproduced the prefixed case in Chrome: <svg:a xlink:href> in an XHTML page gets no dom_urls entry, and neither does a default-namespace SVG <a x:href> where x is bound to XLink. The snapshot keeps the xmlns:* declarations, so I'll send a small follow-up PR that resolves prefixes through them in XML documents only, leaving HTML pages unchanged and keeping the ancestry cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] dom_urls skips SVG links written only as xlink:href

4 participants