Skip to content

CVE-2022-29230: XSS in Shopify Hydrogen

Analysis of CVE-2022-29230 reveals a significant flaw in the way Shopify Hydrogen handles the transition from server-side rendering to client-side interactivity. This vulnerability, classified as XSS, allows an attacker to execute arbitrary JavaScript in the context of a victim’s browser.

The vulnerability resides in the hydration phase of the React rendering lifecycle. In frameworks using SSR, the server generates the initial HTML and embeds the state data in a JSON payload within the document. The client-side JavaScript then “hydrates” this state to make the page interactive.

I observed that in affected versions (0.10.0 to 0.18.0), certain fields within this hydrating data were not strictly sanitized. When user-controlled input—such as URL parameters or metadata—is reflected in this JSON blob, it can break the data structure and inject executable code.

The attack is network-based and requires the attacker to influence data that is subsequently rendered on the storefront.

  1. Injection: The attacker identifies a field (e.g., a search query, a filtered category, or a user-profile attribute) that is reflected in the server-rendered JSON state.
  2. Delivery: The attacker crafts a URL containing a malicious payload and induces the victim to click it.
  3. Execution: Upon page load, the Hydrogen framework processes the malicious JSON string during hydration, resulting in the execution of the script.

Depending on the specific point of injection, payloads typically target the breaking of JSON strings.

  • JSON Breakout: ");alert(document.domain);("
  • Tag Injection: </script><script>alert(1)</script>

From a Forensic perspective, detection relies on observing the artifacts of the hydration failure.

  • DOM Anomalies: Presence of unexpected attributes like onerror or onload within elements that should be static.
  • Unexpected Script Execution: In an authenticated session, observe unauthorized requests to external domains (C2 exfiltration) following the load of a suspicious URL.
  • Web Logs: High frequency of requests containing characters such as <, >, and " in query strings targeting storefront endpoints.
  • Admin Metadata: Evidence of script tags within Shopify Metafields if the injection was persistent.

To identify exploitation attempts, I recommend implementing the following detection strategies.

This logic focuses on spotting classic XSS patterns within the HTTP request stream.

title: Shopify Hydrogen XSS Attempt
id: 5f3e2a1b-c2d3-4e5f-8g9h-0i1j2k3l4m5n
description: Detects common XSS payloads in HTTP requests targeting Shopify Hydrogen storefronts.
logsource:
category: web_server
detection:
selection:
url|contains:
- '<script'
- 'javascript:'
- 'onerror='
- 'onload='
- 'alert('
condition: selection
level: medium
W3CIISLog
| where csUriQuery contains "<script"
or csUriQuery contains "javascript:"
or csUriQuery contains "alert("
| project TimeGenerated, cIP, csMethod, csUriStem, csUriQuery, scStatus

The only reliable fix is to upgrade the framework.

  1. Update Hydrogen: Upgrade to version 0.19.0 or higher.
  2. Verify Dependencies: Ensure that all @shopify/hydrogen packages are aligned to the patched version.
  3. Audit Inputs: Review any custom data-fetching logic that feeds into the server state.