T09 · Insecure Skill Coding Practices
- Location
references/schema-examples.md:385- Finding
Unsafe JSON-LD Serialization Can Enable Stored Cross-Site Scripting
- Content
View full analysis
` sequence. HTML parsing rules recognize `` even when it appears inside a JSON string. Consequently, a malicious product name or another dynamic schema property could terminate the JSON-LD element and introduce attacker-controlled HTML or JavaScript. For example, an attacker-controlled field containing a payload conceptually equivalent to: ```text ``` could break out of the non-executable `application/ld+json` block. The newly introduced regular script element would then execute in the origin of the affected website. This is especially relevant when product information comes from a CMS, marketplace seller, catalog import, API integration, or another source that is not fully trusted. ### Attack Path 1. An attacker obtains the ability to create or modify a product field consumed by the schema generator, such as `product.name`. 2. The attacker places a script-closing sequence and malicious markup in that fi ...[truncated 1324 chars]- Remediation
View remediation
` sequence cannot occur: ```jsx function serializeJsonLd(value) { return JSON.stringify(value) .replace(//g, "\\u003e") .replace(/&/g, "\\u0026") .replace(/\u2028/g, "\\u2028") .replace(/\u2029/g, "\\u2029"); } ` and verify that no additional DOM elements or executable scripts are created. 7. Update the documentation example so users do not copy an unsafe implementation into production applications. ]]>
