The Next.js example can let dynamic product data escape JSON-LD and execute browser code
Source references: 2The example places an object containing `product.name` into `dangerouslySetInnerHTML` after only applying `JSON.stringify`. JSON serialization does not make `<` safe for inline HTML; a dynamic field containing `</script>` can close the JSON-LD element early and cause following content to be parsed as executable HTML or JavaScript.
If an attacker can control a product name or another schema field, they could execute script in visitors' browsers, potentially reading accessible data, acting as the user, or altering the page.
The risk is plausible, although this is a Next.js example users may copy, not code the Skill itself executes. It places dynamic `product.name` into an object and passes `JSON.stringify` output directly to `dangerouslySetInnerHTML`; `JSON.stringify` does not HTML-safely escape `<`. If an untrusted party can control a product field containing `</script>`, the browser could terminate the JSON-LD element early and parse injected content, potentially executing code in visitors’ browsers. Users can ask the author to use a JSON-LD serializer that escapes `<` and to constrain or sanitize dynamic fields.
```jsxexport default function ProductPage({ product }) { const schema = { "@context": "https://schema.org", "@type": "Product", name: product.name, // ... other properties }; return ( <> <Head> <script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }} /> </Head>Show 1 other places
### Dynamic Sites (React, Next.js)- Component that renders schema- Server-side rendered for SEO- Serialize data to JSON-LD