Skip to content

fix(web): escape < in JSON-LD serialization to block script-tag breakout - #14476

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
hridaya423:fix/jsonld-script-breakout
Sep 19, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
hridaya423:fix/jsonld-script-breakout

Conversation

@hridaya423

@hridaya423 hridaya423 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

web/app JsonLd and web/frontend generateStructuredData feed app name/description/author, community-supplied marketplace fields, into dangerouslySetInnerHTML via JSON.stringify, which does not escape <. A </script> inside app metadata closes the ld+json element 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: new serializeJsonLd(), JSON.stringify(data).replace(/</g, '\\u003c'). \u003c parses 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 inline JSON.stringify JSON-LD block (same sink, same fields).

How verified

  • web/app: new src/components/seo/__tests__/JsonLd.test.tsx renders JsonLd with a x</script><script>...</script> payload and asserts a single script element survives (jsdom HTML parsing would have created a sibling <script> before the fix); serializeJsonLd round-trip and no-</script> assertions. 3/3 pass.
  • web/app vitest suite: 88 files / 490 tests pass; the 11 failures in Sidebar.test.tsx/StartupModals.test.tsx (jsdom localStorage/confetti) reproduce identically on clean main.
  • web/frontend: new src/__tests__/app-detail-json-ld.test.mjs static checker (node:test; the page can't be imported, matching the existing app-detail-not-found convention). 1/1 pass.
  • bun run typecheck: clean.

Product invariants affected

none

Failure-Class: none

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
@Git-on-my-level

Copy link
Copy Markdown
Member

Nice catch and a clean, minimal fix — thank you! I verified both sinks statically at the current head.

  • web/app/src/components/seo/JsonLd.tsx — serializeJsonLd() centralizes JSON.stringify(data).replace(/</g, '\\u003c') for all four JSON-LD components (JsonLd, BreadcrumbJsonLd, SoftwareAppJsonLd, CollectionPageJsonLd). The replacement literal is exactly right: \u003c parses back to < as JSON, so the structured data is unchanged, while </script> inside any string value can no longer terminate the element.
  • web/frontend/src/app/apps/[id]/page.tsx — same escape applied to the inline JSON.stringify([...]) in generateStructuredData(). App name/description/author are community-supplied marketplace fields, so this was a stored-XSS path on the public /apps/<id> pages — good catch covering both web properties.
  • web/app/src/components/seo/__tests__/JsonLd.test.tsx — solid behavioral coverage: the x</script><script>… payload renders a single script element plus a round-trip assertion, and the file is picked up by vitest.config.mts (src/**/*.test.{ts,tsx} include, @ → ./src alias).
  • web/frontend/src/__tests__/app-detail-json-ld.test.mjs — honest static checker given that page.tsx is a Next server component that node:test can't import; the regex matches the current source, the node --test src/__tests__/*.test.mjs script picks it up, and it follows the existing app-detail-not-found convention.

I also checked the remaining dangerouslySetInnerHTML / ld+json sites in the repo: web/admin/components/ui/chart.tsx is the recharts wrapper (not ld+json, no community metadata), and the ld+json reference in backend/utils/retrieval/tools/web_tools.py is a parser, not an emitter — so these two changes cover the repo's JSON-LD emitters.

One correction needed: the PR body declares Failure-Class: new, which per product/failure-classes.md means the change adds exactly one FC-*.json definition file alongside the fix — but no definition file is included. For a code-only fix like this, please switch the token to Failure-Class: none; if you'd like to register the class (script-element breakout via unescaped serialization), add the .github/failure-classes/FC-<slug>.json definition alongside instead.

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 need human response.

@Git-on-my-level Git-on-my-level added frontend positive-signal Automation verified a genuine fix/quality contribution security-review Touches auth, provider routing, secrets, or security-sensitive surfaces labels Sep 18, 2026
@hridaya423

Copy link
Copy Markdown
Contributor Author

Done — Failure-Class: none now, since no FC-*.json definition ships with the fix. Thanks for the pointer; registering a class for script-element breakout makes sense as a follow-up if it recurs.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified real unescaped JSON.stringify XSS in JSON-LD serialization, correct minimal fix, tests added, 5/5 confidence.

@kodjima33
kodjima33 merged commit c3a79ae into BasedHardware:main Sep 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend positive-signal Automation verified a genuine fix/quality contribution security-review Touches auth, provider routing, secrets, or security-sensitive surfaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants