Fix stored XSS in product JSON-LD via unescaped JSON.stringify (CWE-79)#1527
Open
alanturing881 wants to merge 1 commit into
Open
Fix stored XSS in product JSON-LD via unescaped JSON.stringify (CWE-79)#1527alanturing881 wants to merge 1 commit into
alanturing881 wants to merge 1 commit into
Conversation
…aping (CWE-79) JSON.stringify does not escape `<` or `>`, so a product title or description containing `</script>` breaks out of the JSON-LD <script> block, allowing an injected <script> tag to execute. Escape `<` and `>` as their Unicode equivalents `<`/`>` — valid JSON that browsers parse correctly but that cannot form a raw `</script>` sequence in HTML. Co-Authored-By: iaohkut <thb2601@gmail.com>
Contributor
|
Someone is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security Fix — Stored XSS in Product JSON-LD (CWE-79)
Summary
Product pages render a JSON-LD
<script>block usingdangerouslySetInnerHTMLwith rawJSON.stringifyoutput. BecauseJSON.stringifydoes not escape<or>, a product title or description containing</script>terminates the JSON-LD block prematurely, allowing an attacker-controlled<script>tag to execute in the customer's browser.This is a stored XSS affecting any customer who visits a product page with a malicious title, description, or image URL — injected via the Shopify admin (compromised credentials, rogue admin, API abuse).
Affected file
app/product/[handle]/page.tsxline 79–82Root cause
A product title of
</script><script>alert(1)</script>produces:The browser terminates the JSON-LD block at the first
</script>, then executes the injected script.Fix
</>are valid JSON Unicode escapes that browsers and JSON parsers decode as</>, so structured-data consumers see the correct values — but no</script>sequence can appear in the raw HTML.Impact
write_productsscope)Verification
Confirmed via Node.js runtime —
JSON.stringifydoes not escape angle brackets: