Open redirection in OAuth
The OAuth authorisation endpoint redirected to the supplied redirect_uri even when the requested scope was invalid, instead of showing an error. An attacker could use their own app to turn the endpoint into an open redirect and send victims to a phishing page.
- Triaged in 6 days
- Fixed in 55 days
- Paid in 6 days
- Disclosed after 3 months
Hello,
When we specify an invalid scope then the authorize url redirects to the site mentioned in redirect_uri. So, attacker can create an app and use it as open redirector to redirect victims to fake sites.
eg. Attacker can host same phishing page and hack the victims.
Proof Of Concept :
- I created an app
- Now, visit this ...
This will redirect ...
- This will redirect with an error to ...
Simple patch :
Only a error should be shown and no redirection should take place so as to protect users.
Thanks, Pranav
Context
Shopify's OAuth authorisation endpoint lives under a shop's admin path, at /admin/oauth/authorize. An app is identified by its client_id, asks for a set of permissions through scope, and tells the server where to send the user afterwards through redirect_uri. In a normal flow the user is sent back to the app's registered callback with a code or an error.
The report shows that when the requested scope is invalid, the endpoint still honours the redirect_uri and forwards the user there with an error in the query string. Because the redirect target is taken from the request, an app owner can use their own authorisation URL as an open redirector.
Setup
The researcher registered an app on a Shopify shop, prans.myshopify.com, which gave them a client_id to work with. No other tooling, version or precondition is described. The only requirement visible in the report is a valid app and its client identifier.
Finding it
The observation is simple: supplying an invalid scope causes the authorise URL to redirect to whatever site is named in redirect_uri. The researcher frames this as an attacker creating an app and using it as an open redirector to send victims to fake sites, for example a hosted phishing page.
Exploitation
Step 1: create an app and build the authorise URL
The researcher created an app and produced this URL, which requests a legitimate scope and points redirect_uri at an external site:
https://prans.myshopify.com/admin/oauth/authorize?client_id=[redacted]&scope=read_customers&redirect_uri=http://www.facebook.com/abc/
client_id identifies the attacker's app, scope=read_customers is a valid permission, and redirect_uri is the external destination. The report does not show what this first URL returned.
Step 2: send the victim to the URL with an invalid scope
The researcher then visits a variant where the scope is replaced with a value that is not a valid permission:
https://prans.myshopify.com/admin/oauth/authorize?client_id=[redacted]&scope=a&redirect_uri=https://www.facebook.com/abc
Here scope=a is the invalid scope and redirect_uri is again the external site. The report says this redirects, with an error, to the destination.
Step 3: the redirect that arrives at the external site
The browser ends up at the external site with the error parameters attached:
https://www.facebook.com/abc?error=invalid_scope&hmac=[redacted]&shop=prans.myshopify.com&[redacted]×tamp=1428607537
The query string carries error=invalid_scope, the shop domain in shop, a timestamp, and the hmac and signature values. The key point is that the user has left the Shopify domain and landed on the attacker-chosen host, with a URL that looks like a genuine Shopify OAuth error response.
Root cause
When the scope is invalid, the endpoint still redirects to the caller-supplied redirect_uri. The report does not describe how redirect_uri is validated on the success path, so whether the same weakness exists there is not established; the behaviour shown is specific to the invalid-scope error flow.
Impact
An attacker who owns an app can craft a link on a trusted Shopify shop domain that forwards victims to any site they choose. The researcher's example is hosting a copy of a phishing page and using the redirect to lend it credibility. The victim has to follow the crafted authorise URL, and the redirect lands them on the attacker's page with Shopify-looking error parameters in the query string, which can make the fake page more convincing.
Fix
The researcher's suggested patch is that only an error should be shown and no redirection should take place, so that users are protected.
Variants to test
- Replace the scope with other invalid values (empty, unknown permission names, malformed strings) and see whether the redirect still fires. A positive result is a 302 to the external
redirect_uriwitherror=invalid_scopein the query. - Change
redirect_urito a host you control and confirm the browser actually leaves the shop domain. A positive result is your server receiving the request with the error parameters. - Try the same
redirect_urisubstitution on the success path with a valid scope. A positive result is a redirect to your host carrying a code or token rather than an error. - Test other error conditions on the same endpoint (unknown
client_id, missing parameters) to see whether they also redirect to the supplied URI. A positive result is any error response that still honours the external destination.
Hunting notes
OAuth authorisation endpoints are a good place to look because they are designed to redirect, and error branches are often written separately from the success branch and validated less carefully. During recon, collect the authorise URLs used by apps on the target and note which parameters control the destination. Then vary the parameters that trigger errors, such as scope, and watch whether the response is a redirect to the supplied URI. The researcher showed a crafted link on the shop domain that redirects off-site with error parameters in the query string. That combination, rather than the redirect alone, is what makes the case for a phishing vector.
What happened, in plain words
Shopify is a platform that lets people run online shops. Besides the shop itself, Shopify lets outside developers build small add-on programs, called apps, that plug into a shop. To let an app act on a shop, Shopify uses a system called OAuth, which is a standard way for one website to ask a user for permission to access their account on another website.
When you install such an app, your browser is sent to a Shopify address that asks you to approve the app. That address is called the authorisation endpoint. It takes a few pieces of information in the link itself: which app is asking (client_id), what permissions it wants (scope), and where to send you once you have decided (redirect_uri).
The researcher found that if the requested permission (scope) is not a real one, Shopify still sends the user on to whatever address is written in redirect_uri, together with an error message. Because that address comes from the link, anyone who owns an app can build a link on a genuine Shopify shop domain that quietly forwards visitors to any site they like. The researcher's example is sending victims to a fake page that copies a real one, a technique called phishing.
Background you need first
A few ideas come up repeatedly, so here they are from scratch.
- OAuth: a way for a website to ask you to grant an app access to your account without giving the app your password. You are shown a consent screen, you approve, and the app receives a short-lived code or token instead.
- Authorisation endpoint: the web address that shows that consent screen. It is the door you are sent to when an app wants permission.
client_id: a public identifier for an app, a bit like a name badge. It tells Shopify which app is asking.scope: the list of permissions the app is requesting, for example reading your customer list. Think of it as the tick boxes on a permission slip.redirect_uri: the address the user is sent back to after approving or refusing. Think of it as the return address written on an envelope.- Query string: the part of a web address after the
?, made ofname=valuepairs joined by&. It is how a link carries extra information, such as an error code. - Open redirect: a flaw where a trusted site will forward a visitor to any address supplied in the link. It matters because the link starts on a domain people trust, which makes the destination look more believable.
- Phishing: a fake page that imitates a real service to trick people into typing passwords or payment details.
- HMAC and signature: values computed with a secret key so that the receiver can check a message really came from the sender and was not altered. They are like a wax seal on a letter.
Context
Shopify's OAuth authorisation endpoint sits under a shop's admin path, at /admin/oauth/authorize. An app is identified by its client_id, asks for a set of permissions through scope, and tells the server where to send the user afterwards through redirect_uri. In a normal flow the user is sent back to the app's registered callback with a code or an error.
The report shows that when the requested scope is invalid, the endpoint still honours the redirect_uri and forwards the user there with an error in the query string. Because the redirect target is taken from the request, an app owner can use their own authorisation URL as an open redirector.
Setup
The researcher registered an app on a Shopify shop, prans.myshopify.com, which gave them a client_id to work with. No other tooling, version or precondition is described. The only requirement visible in the report is a valid app and its client identifier.
In plain terms: the researcher used an app of their own, which supplied the client_id in the link. Registering one is a normal, allowed action for a developer, and it hands you the identifier you put in the link.
Finding it
The observation is simple: supplying an invalid scope causes the authorise URL to redirect to whatever site is named in redirect_uri. The researcher frames this as an attacker creating an app and using it as an open redirector to send victims to fake sites, for example a hosted phishing page.
Why does this matter? Instead the server treats the bad permission as an error worth reporting, and reports it by sending the browser to the return address in the link.
Exploitation
Step 1: create an app and build the authorise URL
The researcher created an app and produced this URL, which requests a legitimate scope and points redirect_uri at an external site:
https://prans.myshopify.com/admin/oauth/authorize?client_id=[redacted]&scope=read_customers&redirect_uri=http://www.facebook.com/abc/
Line by line, reading the address from left to right:
https://prans.myshopify.comis the shop's own domain, so the link begins on a host that visitors recognise as Shopify./admin/oauth/authorizeis the consent endpoint described above.client_id=[redacted]identifies the researcher's app.scope=read_customersasks for a valid permission, reading the shop's customers. This is the normal, working case.redirect_uri=http://www.facebook.com/abc/is the return address, here an external site rather than the app's own callback.
The report does not show what this first URL returned. The step exists to establish the shape of a working authorisation link before changing one piece of it.
Step 2: send the victim to the URL with an invalid scope
The researcher then visits a variant where the scope is replaced with a value that is not a valid permission:
https://prans.myshopify.com/admin/oauth/authorize?client_id=[redacted]&scope=a&redirect_uri=https://www.facebook.com/abc
Again line by line:
- The domain and path are unchanged, so the link still looks like a genuine Shopify consent link.
client_idis the same app identifier.scope=ais the change.ais not a permission Shopify knows, so the request is invalid.redirect_uri=https://www.facebook.com/abcis the external destination, this time overhttpsand without the trailing slash.
Here scope=a is the invalid scope and redirect_uri is again the external site. The report says this redirects, with an error, to the destination. The point of the step is to trigger the error branch and watch where the browser is sent.
Step 3: the redirect that arrives at the external site
The browser ends up at the external site with the error parameters attached:
https://www.facebook.com/abc?error=invalid_scope&hmac=[redacted]&shop=prans.myshopify.com&[redacted]×tamp=1428607537
What each part means:
https://www.facebook.com/abcis the attacker-chosen destination, taken straight fromredirect_uri.error=invalid_scopesays the requested permission was not recognised. This is the error the server wanted to report.hmac=...andsignature=...are additional values in the query string.shop=prans.myshopify.comnames the shop the request was about.timestamp=1428607537is a value in the query string.
The query string carries error=invalid_scope, the shop domain in shop, a timestamp, and the hmac and signature values. The key point is that the user has left the Shopify domain and landed on the attacker-chosen host, with a URL that looks like a genuine Shopify OAuth error response.
Root cause
When the scope is invalid, the endpoint still redirects to the caller-supplied redirect_uri. The report does not describe how redirect_uri is validated on the success path, so whether the same weakness exists there is not established; the behaviour shown is specific to the invalid-scope error flow.
In everyday terms: the front door checks your permission slip, sees it is filled in wrongly, and instead of asking you to fill it in again, hands you to whoever wrote the return address on the envelope. The check happened, but the result of the check did not stop the forwarding.
Impact
An attacker who owns an app can craft a link on a trusted Shopify shop domain that forwards victims to any site they choose. The researcher's example is hosting a copy of a phishing page and using the redirect to lend it credibility. The victim has to follow the crafted authorise URL, and the redirect lands them on the attacker's page with Shopify-looking error parameters in the query string, which can make the fake page more convincing.
The victim must click the crafted link. Within those limits, the value is that the first hop is a real Shopify address, which is exactly what a cautious user might check before clicking.
Fix
The researcher's suggested patch is that only an error should be shown and no redirection should take place, so that users are protected.
Variants to test
- Replace the scope with other invalid values (empty, unknown permission names, malformed strings) and see whether the redirect still fires. A positive result is a 302 to the external
redirect_uriwitherror=invalid_scopein the query. - Change
redirect_urito a host you control and confirm the browser actually leaves the shop domain. A positive result is your server receiving the request with the error parameters. - Try the same
redirect_urisubstitution on the success path with a valid scope. A positive result is a redirect to your host carrying a code or token rather than an error. - Test other error conditions on the same endpoint (unknown
client_id, missing parameters) to see whether they also redirect to the supplied URI. A positive result is any error response that still honours the external destination.
A 302 is the standard HTTP status code meaning "the thing you asked for has moved, go here instead", and it is how a redirect is delivered to the browser.
Hunting notes
OAuth authorisation endpoints are a good place to look because they are designed to redirect, and error branches are often written separately from the success branch and validated less carefully. During recon, collect the authorise URLs used by apps on the target and note which parameters control the destination. Then vary the parameters that trigger errors, such as scope, and watch whether the response is a redirect to the supplied URI. The researcher showed a crafted link on the shop domain that redirects off-site with error parameters in the query string. That combination, rather than the redirect alone, is what makes the case for a phishing vector.
Glossary
- OAuth: a standard way for one website to ask a user for permission to let an app access their account on another website, without sharing the password.
- Authorisation endpoint: the web address that shows the consent screen where a user approves or refuses an app's request.
client_id: a public identifier for an app, used so the server knows which app is asking.scope: the set of permissions an app requests, such as reading customers.redirect_uri: the address the user is sent to after approving or refusing, supplied in the request.- Query string: the
name=valuepairs after the?in a web address, joined by&, used to carry extra data such as errors. - Open redirect: a flaw where a trusted site forwards visitors to any address supplied in the link.
- Phishing: a fake page imitating a real service to trick people into handing over credentials or payment details.
- HMAC: a value computed with a secret key so the receiver can verify a message came from the expected sender and was not altered.
- Signature: a similar integrity value attached to a response, checked by the receiver.
- Timestamp: a number recording when a response was produced.
- 302: an HTTP status code telling the browser to go to a different address instead.
- Recon: the information-gathering phase of security testing, where you collect the URLs and parameters a target uses.
- Error branch: the part of a program that runs when a request is invalid, often written separately from the normal path.