Skip to content

fix(core): look publish refuses a logo browsers can't render - #703

Merged
allisonmahmood merged 1 commit into
mainfrom
fix/597-logo-strict-xml
Oct 15, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
fix/597-logo-strict-xml

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

look publish read logo.svg with parse5's HTML parser, which recovers from mistakes. Every place a logo appears loads it as an image, and browsers parse images as strict, namespace-aware XML. So an inline <svg> copied from a company's site during onboarding (no xmlns, &nbsp;, an undeclared xlink: prefix) passed every check, then showed as a broken image in the specimen and in every patch.

Fix

checkLogo in @patchy/core/look now parses the logo with saxes, with namespaces on, and walks that parse. saxes is about 8 KB, ISC and pure JS, so the module stays browser-safe. parse5 stays in core for the HTML policy.

  • A logo that isn't well-formed or namespace-valid is refused with one line: the position, saxes' problem, and the general fix. The general fix is always included because saxes sometimes names the wrong thing (a bare & in <title> reports unclosed tag: title). It also tells the agent to run an inline <svg> through new XMLSerializer().serializeToString(svg):
    logo.svg:1:56 is not well-formed XML (undefined entity); a logo is XML, not HTML, so quote every attribute, close every tag, declare prefixes such as xmlns:xlink, and write & as &amp; and &nbsp; as &#160;. For an inline <svg> copied from a page, serialize it with new XMLSerializer().serializeToString(svg) in a browser.
  • A <!DOCTYPE> is refused. The root must be svg in the http://www.w3.org/2000/svg namespace, as resolved from the declarations. That covers a missing or wrong xmlns, and only xmlns:svg on an unprefixed root.
  • A namespace declaration with spaces around its value is refused. saxes trims declarations, but browsers compare them exactly: a padded root xmlns, or a padded reserved xmlns:xml, is a broken image in Chromium and Firefox.
  • An XML declaration other than version="1.0" is refused: Firefox shows any XML 1.1 logo as a broken image.
  • Every existing logo check keeps its message. Attribute names still match case-insensitively, as parse5's did. xlink:href counts as a reference, xmlns:* declarations don't, and <style> text, including CDATA, goes to the CSS reference check.

With #678's bounds

#678 bounded the logo's parse5 parse (512 deep, 256 attributes, a repair budget) so that no upload could stall the server. The XML parse replaces that for the logo. saxes has no error repair and no recursion, but it has three costs of its own that I measured:

  • It finds each element's namespace by searching every open element, which is quadratic in depth. A 20,000-deep logo took 2.4 s, and 220,000 deep took over 300 s.
  • It pairs each namespace with every prefixed attribute's name: a 16 KB namespace across 20k attributes took 0.9 s.
  • It builds an Error with a stack trace for every problem: about 0.5 s for 175k undefined entities in 512 KiB.

So a logo nests at most 64 elements deep, and a namespace is at most 256 characters. Real logos nest a few elements deep, Chromium and Firefox render well past 5,000, and real namespaces are short URIs, so both are purely cost bounds. Problems are recorded without building an Error, and a logo past the look's 512 KiB limit is refused for its size without being parsed. Measured warm against main's bounded parse5 on the same inputs:

Input This branch main
500 KiB of <rect/> siblings 28 ms 24 ms
500 KiB of <g/> siblings at depth 63 (the worst case left) 99 ms 30 ms
500 KiB nested or left unclosed 1 ms, refused 1 ms, refused
500 KiB of undefined entities 14 ms 30 ms
500 KiB of prefixed attributes under a 250-character namespace 57 ms not measured
any shape at 1.5 MiB (the request cap) 1–2 ms, refused for size 64–93 ms

#678's logo-bounds test is replaced by the 64/65 depth threshold. All of its inputs are malformed XML now.

Surfaces

  • Wire contract: the publish endpoint's description lists the logo rule, including both bounds, and docs/API.md is re-rendered. No request or response shape changed.
  • CLI: the patchy README's look section describes the rule. There is no new command, flag or exit code, so ADR-0004 is unchanged. The global skill gains one sentence in look-capture.md's logo.svg section. SKILL.md is unchanged, so skills-lock.json is untouched.
  • Not applicable: dev loop, vocabulary and product shape, migrations, company resources, served pages (the HTML policy is untouched), reverse states and repo layout.

Tried by hand

In Chromium (Playwright), I took two inline logos as a browser reads them back through the DOM: GitHub's header mark from github.com, and the brief's typical site logo after parsing it as HTML. Each went into a look folder next to a fixture look.css and LOOK.md. Both read-backs render as broken images, and main's checks accept both.

Against this branch's dev environment (pnpm dev up, team scenario), using the environment's packed CLI as Ada:

  • patchy look preview on GitHub's mark printed look publish would refuse this look: - logo.svg's <svg> is not in the SVG namespace; set xmlns="http://www.w3.org/2000/svg" on it. --json carried the same line in failures, where it used to report none.
  • patchy look publish refused both read-backs with exit 1 and invalid_look. The brief's logo gave the logo.svg:1:56 … undefined entity … line above.
  • I also POSTed both read-backs straight to /api/look/publish with curl, skipping the CLI's own check. The instance answered 422 invalid_look with the same lines.
  • I ran new XMLSerializer().serializeToString(svg) on both logos in Chromium. Preview then reported no failures, and publish stored them as revisions 1 and 2.
  • Opened in Chromium, the specimen for the read-back showed a broken-image icon followed by the alt text Linear's look, which reads like a wordmark (naturalWidth 0). The specimen for the serialized logo rendered it (naturalWidth 300).

That run was on the commit before the rebase onto #678. On the rebased commit, pnpm patchy look preview from source gives the same four results.

I checked every refusal or acceptance added after review as an image in both Chromium and Firefox: padded xmlns and xmlns:xml, XML 1.1, namespace declarations, uppercase attributes, depth, and the brief's must-pass logos, including Patchy's own. WebKit couldn't launch on this machine.

Review

GPT 6.1 Sol reviewed at xhigh over three rounds.

  • Round 1 found six issues and I fixed five: a padded xmlns, XML 1.1 (widened after Firefox showed any 1.1 logo broken), namespace declarations read as href/on*, attribute-name case, and README wording. The sixth is dismissed in a comment below.
  • Round 2, after the rebase onto fix(core): pathological markup can no longer stall the server #678, found a padded reserved xmlns:xml and the long-namespace cost. Both are fixed.
  • Round 3 found nothing.

Left out

  • Per the brief: the forceStates gaps and logo <style> cascade rules stay accepted. Stored revisions aren't re-checked, and publish never repairs a logo.
  • css-tree throws on a non-CSS attribute value containing url(, e.g. data-x="fill:url(#g)", which makes checkLook throw instead of refusing. This predates this PR on main and needs its own fix.

Closes #597

Made by Claude Opus 5.5 in Claude Code, running in T3 Code.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Sol review: one finding dismissed, with reason

Round 1, low: "Inputs with no root element (a truncated <svg xmlns=… start tag, or a <!DOCTYPE svg> alone) get logo.svg must be one <svg> element. instead of the XML message with a position."

Dismissed. This is main's behaviour for the same inputs: parse5 drops an unterminated start tag and ignores a lone DOCTYPE, so they reach the same message. The brief keeps every existing message. The same rule keeps an empty file, PNG bytes and plain text on that message too, which names what's actually wrong better than an XML parse error would. Once the file has a root, every XML problem gets the positioned line.

All other findings across the three rounds are fixed in this PR; the description lists them.

@github-actions github-actions Bot added area:server Touches the server area area:cli Touches the cli area area:core Touches the core area area:docs Touches the docs area size:m 100-500 changed lines labels Oct 15, 2026
The look checks read logo.svg with parse5's forgiving HTML parser, but every
consumer shows the logo as an image, which browsers parse as strict,
namespace-aware XML. An inline <svg> copied from a page passed the checks and
then showed as a broken image in the specimen and in every patch.

checkLogo now parses logo.svg with saxes (xmlns on) and walks that parse. A
logo that isn't well-formed or namespace-valid is refused with its position,
saxes' problem and the general fix, including XMLSerializer for an inline
<svg>. A DOCTYPE, an XML 1.1 declaration and a namespace with spaces around it
(saxes trims it, browsers don't) are refused, and the root must be svg in the
SVG namespace. Every existing logo check keeps its message; attribute names
still match case-insensitively, xlink:href counts as a reference, namespace
declarations don't, and <style> CDATA goes to the CSS reference check.

The XML parse replaces the bounded HTML parse from #678 for the logo. saxes
has no repair or recursion, but resolves each element's namespace by
searching the open elements, pairs each namespace with every prefixed
attribute's name, and builds an Error per problem. So a logo nests at most 64
elements deep, a namespace is at most 256 characters, problems are recorded
without Errors, and a logo past the look's size limit is refused for its size
without being parsed.

Closes #597

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the fix/597-logo-strict-xml branch from b142c35 to 6a84ca2 Compare October 15, 2026 22:02
@allisonmahmood
allisonmahmood merged commit 170c6f2 into main Oct 15, 2026
13 checks passed
@allisonmahmood
allisonmahmood deleted the fix/597-logo-strict-xml branch October 15, 2026 22:12
allisonmahmood added a commit that referenced this pull request Oct 16, 2026
…u when they fail (#720)

Release 13's What's new entry, written from `c9b8fc4`, ahead of
deploying it. `patchy` and `CURRENT_RELEASE` move to `0.13.0`, so CLIs
and patch repos installed before this deploy are told to upgrade.

| Change | PRs |
| --- | --- |
| New: Home puts the patches you use first | #713, #716, #719 |
| New: Every patch in one list | #715 |
| Improved: Each patch's page leads with Open | #717 |
| New: See when your tools are failing | #718 |
| Fixed: Everyone has a name | #687 |
| Improved: Your company's look is easier to get right | #697, #696,
#703, #688 |
| Improved: Forms follow your look's error states | #691, #692 |
| Improved: Clearer answers when a publish goes wrong | #686, #685, #689
|
| Fixed: Your agent's Patchy commands are steadier | #695, #704, #680,
#681 |
| Behind the scenes: stricter checks on static pages and tools' database
requests; malformed requests are logged | #682, #693, #683 |
| Behind the scenes: usage numbers count every publish, sharing change
and restore | #698, #699, #700, #690 |
| Test and tooling only, no line | #705, #702, #701, #694, #684, #607 |

Made by Claude Opus 5.5 in Claude Code, running in T3 Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli Touches the cli area area:core Touches the core area area:docs Touches the docs area area:server Touches the server area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

look checks: accepted gaps to decide on

1 participant