Skip to content
OAuth / SSO Write-up Intermediate

Bug or Feature? GitHub Adventure #001

GitHub's OAuth implementation allows the redirect_uri to point to any subdomain of the registered callback domain, not just the exact host as documented. An attacker who controls a subdomain (e.g., via subdomain takeover) could redirect OAuth flows to capture authorization tokens.

Dominik Opyd Follow

Published on medium.com

When dealing with Internet security, you can often discover the unprecedented functionality of the tested systems. Some of these discoveries are incompatible with the documentation and contradict the business logic of the entire system and the company — some are funny, some are surprising and sometimes some are…

oritwoen, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

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. 6 min read.

Context

This write-up looks at how GitHub's OAuth authorisation endpoint handles the redirect_uri parameter, and at the gap between what GitHub's documentation promises and what the service actually accepts. The feature in question is the standard OAuth authorisation flow: a developer registers an OAuth application, configures a callback URL, and GitHub sends users back to that callback after they approve access. The redirect_uri parameter lets the application ask for a slightly different return address at request time, and the documentation is supposed to constrain that choice tightly.

The report is framed as the first entry in a series called "Bug or Feature", covering findings that can threaten users and application owners but are treated as known, low-risk issues rather than fixed.

Setup

The only precondition described is the ability to create your own OAuth application on GitHub, which the author does in order to test the behaviour. No specific account roles, tool versions or third-party tooling are mentioned. The test application is configured with a callback URL, and the author then manipulates the redirect_uri sent to the authorisation endpoint.

Finding it

The starting point is GitHub's own documentation on authorising OAuth apps, specifically the section on redirect URLs at https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/#redirect-urls. The documentation states:

The redirect_uri parameter is optional. If left out, GitHub will redirect users to the callback URL configured in the OAuth Application settings. If provided, the redirect URL's host and port must exactly match the callback URL. The redirect URL's path must reference a subdirectory of the callback URL.

The documented examples are:

Text
CALLBACK: http://example.com/path

GOOD: http://example.com/path
GOOD: http://example.com/path/subdir/other
BAD: http://example.com/bar
BAD: http://example.com/
BAD: http://example.com:8080/path
BAD: http://oauth.example.com:8080/path
BAD: http://example.org

The key sentence is that the redirect URL's host and port must exactly match the callback URL. Taken literally, that would mean only the exact host in the callback configuration is acceptable. The author found that the real behaviour is different: the check is not limited to the domain set in the settings but accepts any subdomain of it. In practice the accepted and rejected cases look like this:

Text
CALLBACK: http://example.com

GOOD: http://example.com/path
GOOD: http://example.com/path/subdir/other
GOOD: http://hack.example.com
GOOD: http://admin.example.com
GOOD: http://user.example.com
GOOD: http://domain.taken.over.example.com
GOOD: http://custom.subdomain.registered.by.user.example.com

So a callback registered as example.com also authorises hack.example.com, admin.example.com, and any other subdomain, including ones an unrelated party can register or take over. This contradicts the documentation's "exactly match" wording.

Exploitation

Step 1: Register a test OAuth application

The author creates an OAuth application on GitHub and tests the redirect_uri against its configured callback. The screenshot shows the application settings used for the test.

From the original on medium.com

Step 2: Send an authorisation request with a subdomain redirect_uri

With the application in place, the author visits the authorisation endpoint with a redirect_uri pointing at a subdomain of the configured callback domain:

HTTP
https://github.com/login/oauth/authorize?client_id=c8aa24b96126066e58ce&redirect_uri=http://domain.taken.over.oad.earth/path

The client_id identifies the test application. The redirect_uri points at a subdomain host; the screenshot shows the result. The screenshot shows the resulting behaviour.

From the original on medium.com

Root cause

The validation of redirect_uri compares the supplied host against the callback URL in a way that treats any subdomain as matching, rather than requiring the host and port to match exactly as documented. The design intent, per the documentation, is that the host and port are fixed and only the path may vary within the callback's directory tree. The implementation instead allows the host to vary within the same parent domain.

The main domain in the redirect still matches the configured callback, so the user will not suspect anything. The report does not describe the server-side code, so the exact comparison logic is not shown; the behaviour is inferred from the accepted and rejected examples above.

Impact

The author identifies two problems.

  1. Unexpected paths and hosts for the developer. Developers configure a specific callback path for specific reasons and expect that only that path (and its subdirectories) will be used. Allowing other paths and, more importantly, other subdomains means the application's OAuth flow can run through a destination the developer did not intend.
  2. Subdomain takeover. Subdomains are frequently taken over by attackers. If the callback domain has a subdomain that another user can register publicly, or one that is prone to takeover, the OAuth application's traffic can be redirected to a location controlled by an unauthorised person. The attacker can then obtain authorisation tokens through simple manipulations, and the user will not suspect anything because the main domain still matches. This threatens the whole infrastructure and all users of the application.

The report does not assign a severity or CVSS score, and the impact depends on the existence of a take-overable or registerable subdomain under the callback domain.

Fix

No fix was made. GitHub's first response was:

Hi,

Thanks for the submission! We have reviewed your report and validated your findings. After internally assessing the finding we have determined it is a known low risk issue. We may make this functionality more strict in the future, but don't have anything to announce right now. As a result, this is not eligible for reward under the Bug Bounty program.

A follow-up reply said:

The ability to reference a subdomain of the callback URL in the oauth redirect_uri and the related risks is a known issue for GitHub. It is currently being tracked and prioritized. While we are unable to reward the bounty due to the known-issue status, we do sincerely appreciate your submission.

And a further reply:

We definitely appreciate this feedback you have provided us with and will add your comments to the existing issue we have open for this bug. Again, thank you for participating in our bug bounty program!

So the issue was acknowledged as known and tracked, but not changed at the time of writing.

Variants to test

  1. Subdomain acceptance on other OAuth providers. Register an application with a callback on a domain you control, then send an authorisation request with redirect_uri set to a subdomain of that domain. A positive result is the provider accepting the subdomain and redirecting there instead of rejecting the request.
  2. Registerable or take-overable subdomains. Check whether the callback domain has subdomains that can be registered by anyone or are vulnerable to takeover (for example, dangling DNS records pointing at deprovisioned services). A positive result is a subdomain you can control that the provider accepts as a redirect_uri host.
  3. Port and scheme variations. Test whether the provider accepts a different port or scheme from the callback configuration, since the documentation says host and port must match exactly. A positive result is a redirect to a host or port that differs from the configured callback.
  4. Path traversal in the redirect path. Try redirect_uri paths that escape the callback's directory (for example, using .. segments or encoded variants). A positive result is a redirect to a path outside the callback's directory tree.
  5. Case and trailing-dot host variants. Try hostnames that differ only in case or a trailing dot from the callback host. A positive result is acceptance of a host that is not byte-for-byte identical to the configured callback.

Closing note

The author found a HackerOne report at https://hackerone.com/reports/292825 where the reporter received the same answer, i.e. automatic classification and the problem ignored.

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. 12 min read.

What happened, in plain words

GitHub lets other websites and apps ask a user for permission to access their GitHub account. This is done through a system called OAuth. When you click a button like "Sign in with GitHub" on some other site, OAuth is what makes that work.

When a developer sets up such an app, they tell GitHub where to send the user back after they approve access. That return address is called a callback URL. GitHub's own documentation says that when the app asks for a slightly different return address at the moment of the request (a parameter called redirect_uri), the address must match the callback URL exactly, apart from the path.

The author of this write-up found that GitHub does not actually behave that way. It accepts any subdomain of the callback domain, not just the exact host. So if a developer registered example.com as the callback, GitHub would also happily send users to hack.example.com or any other subdomain, including one an attacker could register or take over.

The author reported this to GitHub. GitHub replied that it was a known, low-risk issue, that it was being tracked, and that it was not eligible for a bug bounty reward. The author then found an older public report of the same behaviour, suggesting the issue had existed for at least three years.

This write-up is the first in a series the author calls "Bug or Feature", about findings that can threaten users and app owners but are treated as known issues rather than fixed.

Background: what OAuth is, and why the return address matters

Before the details make sense, a few ideas need to be clear.

An API is a way for one piece of software to talk to another. Think of it as a service counter: you hand over a request in a fixed format, and you get back an answer in a fixed format. GitHub has an API that lets other programs read and act on a user's account, with the user's permission.

OAuth is the permission system that makes that safe. Instead of giving another website your GitHub password, you are sent to GitHub, you log in there, and GitHub asks whether you want to let that website access your account. If you say yes, GitHub hands the website a token: a long string of characters that works like a temporary key. The website can use that key to talk to GitHub on your behalf, and you never had to share your password.

A callback URL is the address GitHub sends you back to after you approve. The developer registers it in the app's settings. It is where the token gets delivered, so it has to be a place the developer controls.

The redirect_uri parameter is an optional extra address an app can include in the authorisation request. It lets the app ask GitHub to send the user somewhere slightly different from the registered callback, for example a specific page under the callback. Because the token is delivered to wherever the user lands, this parameter is security-sensitive: if an attacker can make it point at a place they control, they can receive the token.

A subdomain is a name that sits under a main domain. In admin.example.com, the main domain is example.com and admin is the subdomain. Anyone who controls a subdomain controls what is served there.

A subdomain takeover happens when a subdomain points at a service that is no longer in use, and someone else can claim that service and start serving content on the subdomain. From the outside, the address still looks like it belongs to the real domain.

With those pieces in place, the rest of the write-up is about one question: when GitHub checks the redirect_uri, how strict is that check really?

Setup

The only thing needed to test this is the ability to create your own OAuth application on GitHub. The author does exactly that, with a callback URL on a domain they control, and then changes the redirect_uri sent to the authorisation endpoint to see what GitHub accepts. No special account roles, tool versions or third-party tools are mentioned.

Finding it

The starting point is GitHub's own documentation on authorising OAuth apps, in the section on redirect URLs at https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/#redirect-urls. The documentation says:

The redirect_uri parameter is optional. If left out, GitHub will redirect users to the callback URL configured in the OAuth Application settings. If provided, the redirect URL's host and port must exactly match the callback URL. The redirect URL's path must reference a subdirectory of the callback URL.

The documented examples are:

Text
CALLBACK: http://example.com/path

GOOD: http://example.com/path
GOOD: http://example.com/path/subdir/other
BAD: http://example.com/bar
BAD: http://example.com/
BAD: http://example.com:8080/path
BAD: http://oauth.example.com:8080/path
BAD: http://example.org

Line by line, this block says:

  • CALLBACK: http://example.com/path is the address the developer registered in the app settings. Everything else is compared against it.
  • GOOD: http://example.com/path is accepted because it is identical to the callback.
  • GOOD: http://example.com/path/subdir/other is accepted because it is a page further down inside the callback's folder. The documentation allows the path to point at a subdirectory.
  • BAD: http://example.com/bar is rejected because /bar is not inside /path.
  • BAD: http://example.com/ is rejected because the root of the site is not inside /path either.
  • BAD: http://example.com:8080/path is rejected because the port (8080) differs from the callback's port.
  • BAD: http://oauth.example.com:8080/path is rejected because both the host (oauth.example.com) and the port differ.
  • BAD: http://example.org is rejected because it is a completely different domain.

The key sentence is that the redirect URL's host and port must exactly match the callback URL. Read literally, that means only the exact host in the callback configuration is acceptable.

The author found the real behaviour is different. The check is not limited to the domain set in the settings; it accepts any subdomain of it. In practice the accepted and rejected cases look like this:

Text
CALLBACK: http://example.com

GOOD: http://example.com/path
GOOD: http://example.com/path/subdir/other
GOOD: http://hack.example.com
GOOD: http://admin.example.com
GOOD: http://user.example.com
GOOD: http://domain.taken.over.example.com
GOOD: http://custom.subdomain.registered.by.user.example.com

Line by line:

  • CALLBACK: http://example.com is the registered callback, this time with no path.
  • GOOD: http://example.com/path is accepted, as expected, because it is the callback host with a path.
  • GOOD: http://example.com/path/subdir/other is accepted, as expected, because it is a deeper page under the same host.
  • GOOD: http://hack.example.com is accepted even though hack is a different subdomain. This is the surprise.
  • GOOD: http://admin.example.com is accepted for the same reason.
  • GOOD: http://user.example.com is accepted for the same reason.
  • GOOD: http://domain.taken.over.example.com is accepted, and this is the dangerous case: the subdomain name suggests it could be taken over by someone else.
  • GOOD: http://custom.subdomain.registered.by.user.example.com is accepted, and this one suggests a subdomain that a user can register themselves.

So a callback registered as example.com also authorises hack.example.com, admin.example.com, and any other subdomain, including ones an unrelated party can register or take over. This contradicts the documentation's "exactly match" wording.

Exploitation

Step 1: Register a test OAuth application

The author creates an OAuth application on GitHub and tests the redirect_uri against its configured callback. The screenshot shows the application settings used for the test.

From the original on medium.com

This step is needed because the whole question is about how GitHub compares the redirect_uri against a registered callback. Without an app of your own, there is nothing to compare against. The screenshot shows the test application's settings.

Step 2: Send an authorisation request with a subdomain redirect_uri

With the application in place, the author visits the authorisation endpoint with a redirect_uri pointing at a subdomain of the configured callback domain:

HTTP
https://github.com/login/oauth/authorize?client_id=c8aa24b96126066e58ce&redirect_uri=http://domain.taken.over.oad.earth/path

Line by line:

  • https://github.com/login/oauth/authorize is GitHub's authorisation endpoint. This is the page a user is sent to when an app wants permission.
  • client_id=c8aa24b96126066e58ce identifies the test application. Every OAuth app has an ID like this so GitHub knows which app is asking.
  • redirect_uri=http://domain.taken.over.oad.earth/path is the return address the app is asking for. The host here is a subdomain of the callback domain rather than the exact host.
  • The & separates the two parameters in the URL.

The client_id identifies the test application. The redirect_uri points at a subdomain host; the screenshot shows the result. The screenshot shows the resulting behaviour.

From the original on medium.com

This step is the actual test. If GitHub followed its documentation, the request would be rejected because the host does not exactly match the callback. If GitHub accepts it, the documentation and the implementation disagree, which is the finding.

Root cause

The validation of redirect_uri compares the supplied host against the callback URL in a way that treats any subdomain as matching, rather than requiring the host and port to match exactly as documented. The design intent, per the documentation, is that the host and port are fixed and only the path may vary within the callback's directory tree. The implementation instead allows the host to vary within the same parent domain.

The main domain in the redirect still matches the configured callback, so the user will not suspect anything. The report does not describe the server-side code, so the exact comparison logic is not shown; the behaviour is inferred from the accepted and rejected examples above.

Impact

The author identifies two problems.

  1. Unexpected paths and hosts for the developer. Developers configure a specific callback path for specific reasons and expect that only that path (and its subdirectories) will be used. Allowing other paths and, more importantly, other subdomains means the application's OAuth flow can run through a destination the developer did not intend.
  2. Subdomain takeover. Subdomains are frequently taken over by attackers. If the callback domain has a subdomain that another user can register publicly, or one that is prone to takeover, the OAuth application's traffic can be redirected to a location controlled by an unauthorised person. The attacker can then obtain authorisation tokens through simple manipulations, and the user will not suspect anything because the main domain still matches. This threatens the whole infrastructure and all users of the application.

The report does not assign a severity or CVSS score, and the impact depends on the existence of a take-overable or registerable subdomain under the callback domain.

Fix

No fix was made. GitHub's first response was:

Hi,

Thanks for the submission! We have reviewed your report and validated your findings. After internally assessing the finding we have determined it is a known low risk issue. We may make this functionality more strict in the future, but don't have anything to announce right now. As a result, this is not eligible for reward under the Bug Bounty program.

A follow-up reply said:

The ability to reference a subdomain of the callback URL in the oauth redirect_uri and the related risks is a known issue for GitHub. It is currently being tracked and prioritized. While we are unable to reward the bounty due to the known-issue status, we do sincerely appreciate your submission.

And a further reply:

We definitely appreciate this feedback you have provided us with and will add your comments to the existing issue we have open for this bug. Again, thank you for participating in our bug bounty program!

So the issue was acknowledged as known and tracked, but not changed at the time of writing.

Variants to test

  1. Subdomain acceptance on other OAuth providers. Register an application with a callback on a domain you control, then send an authorisation request with redirect_uri set to a subdomain of that domain. A positive result is the provider accepting the subdomain and redirecting there instead of rejecting the request.
  2. Registerable or take-overable subdomains. Check whether the callback domain has subdomains that can be registered by anyone or are vulnerable to takeover (for example, dangling DNS records pointing at deprovisioned services). A positive result is a subdomain you can control that the provider accepts as a redirect_uri host.
  3. Port and scheme variations. Test whether the provider accepts a different port or scheme from the callback configuration, since the documentation says host and port must match exactly. A positive result is a redirect to a host or port that differs from the configured callback.
  4. Path traversal in the redirect path. Try redirect_uri paths that escape the callback's directory (for example, using .. segments or encoded variants). A positive result is a redirect to a path outside the callback's directory tree.
  5. Case and trailing-dot host variants. Try hostnames that differ only in case or a trailing dot from the callback host. A positive result is acceptance of a host that is not byte-for-byte identical to the configured callback.

Closing note

The author found a HackerOne report at https://hackerone.com/reports/292825 where the reporter received the same answer, i.e. automatic classification and the problem ignored.

Glossary

  • API: a fixed way for one program to send requests to another and receive answers.
  • OAuth: a permission system where a user approves an app on the provider's site, and the app receives a token instead of the user's password.
  • Token: a long string that works like a temporary key, letting an app act on a user's behalf.
  • Callback URL: the address a developer registers so the provider knows where to send the user back after approval.
  • redirect_uri: an optional parameter in the authorisation request that asks the provider to send the user to a slightly different address than the registered callback.
  • Authorisation endpoint: the provider's page where the user approves or denies an app's request.
  • client_id: a public identifier for an OAuth application, used so the provider knows which app is asking.
  • Host: the part of a URL that names the server, such as example.com in http://example.com/path.
  • Port: a number in a URL that selects a service on the server; 8080 in http://example.com:8080/path.
  • Scheme: the first part of a URL, such as http or https, that says how to connect.
  • Path: the part of a URL after the host, such as /path/subdir/other.
  • Subdomain: a name under a main domain, such as admin in admin.example.com.
  • Subdomain takeover: when a subdomain points at an unused service and someone else claims that service, gaining control of the subdomain.
  • DNS record: an entry that tells the internet where a domain or subdomain points.
  • Dangling DNS record: a DNS record that points at a service that no longer exists, which can be claimed by someone else.
  • Path traversal: using .. or encoded variants in a path to escape the intended folder.
  • Bug bounty: a programme where companies pay researchers for reporting security issues.
  • CVSS: a scoring system for rating the severity of a security issue.
  • Severity: a rough measure of how serious an issue is.
  • Known issue: a problem the vendor already knows about and tracks, often without fixing it immediately.
  • Host-suffix check: comparing only the end of a hostname, so any subdomain of the expected domain passes.
  • HackerOne: a platform where security researchers report issues to companies.

Similar reports

View all

Same bug class and techniques, clearest first.

OAuth and single sign-on flaws

The lesson behind this report.

Mistakes in OAuth, OpenID Connect, SAML or token handling that leak codes and tokens or link an attacker's identity to a victim's account.