Repository navigation
fix(web): escape < in JSON-LD serialization to block script-tag breakout - #14476
Conversation
App name/description/author are community-supplied marketplace fields that reach <script type="application/ld+json"> via JSON.stringify, which does not escape `<`. A `</script>` in app metadata closes the element and injects markup on the public /apps/<id> pages. Escape to < (identical after JSON.parse) in web/app's JsonLd and web/frontend's generateStructuredData. Revives the JSON-LD portion of BasedHardware#11304 (author closed it as stale) as a minimal standalone fix. Verified: web/app vitest JsonLd.test.tsx 3/3; suite 490 pass (11 Sidebar/ StartupModals jsdom failures reproduce on clean main); web/frontend node:test checker 1/1; bun run typecheck clean. Failure-Class: new
|
Nice catch and a clean, minimal fix — thank you! I verified both sinks statically at the current head.
I also checked the remaining One correction needed: the PR body declares Left for human maintainer sign-off: this closes a stored-XSS path on the public marketplace pages, and since the write-up is public it's worth merging promptly once the Failure-Class token is corrected. Automation is not formally approving security-sensitive surfaces. Automated review posted on behalf of the Omi maintainers. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Done — |
kodjima33
left a comment
There was a problem hiding this comment.
Verified: dangerouslySetInnerHTML unescaped JSON.stringify confirmed present on main in both web/app JsonLd.tsx and web/frontend apps/[id]/page.tsx; fix is the standard \u003c-escape at the serialization boundary, tests included, no auth code touched. 5/5 confidence. Author (hridaya423) has 0/17 merged PRs — part of the elevated-scrutiny cohort flagged today; verified the diff directly rather than trusting the description.
kodjima33
left a comment
There was a problem hiding this comment.
Verified real unescaped JSON.stringify XSS in JSON-LD serialization, correct minimal fix, tests added, 5/5 confidence.
Summary
web/appJsonLdandweb/frontendgenerateStructuredDatafeed appname/description/author, community-supplied marketplace fields, intodangerouslySetInnerHTMLviaJSON.stringify, which does not escape<. A</script>inside app metadata closes theld+jsonelement on the public/apps/<id>pages and injects attacker markup (stored XSS on omi.me).The same fix was attempted inside #11304, which its author closed as stale; this revives just the escape as a minimal standalone change.
What changed
web/app/src/components/seo/JsonLd.tsx: newserializeJsonLd(),JSON.stringify(data).replace(/</g, '\\u003c').\u003cparses back to<as JSON, so the structured data is unchanged; the script element can no longer be closed from inside a string.web/frontend/src/app/apps/[id]/page.tsx: same escape on its inlineJSON.stringifyJSON-LD block (same sink, same fields).How verified
web/app: newsrc/components/seo/__tests__/JsonLd.test.tsxrendersJsonLdwith ax</script><script>...</script>payload and asserts a single script element survives (jsdom HTML parsing would have created a sibling<script>before the fix);serializeJsonLdround-trip and no-</script>assertions. 3/3 pass.web/appvitest suite: 88 files / 490 tests pass; the 11 failures inSidebar.test.tsx/StartupModals.test.tsx(jsdom localStorage/confetti) reproduce identically on cleanmain.web/frontend: newsrc/__tests__/app-detail-json-ld.test.mjsstatic checker (node:test; the page can't be imported, matching the existingapp-detail-not-foundconvention). 1/1 pass.bun run typecheck: clean.Product invariants affected
none
Failure-Class: none