Skip to content
OAuth / SSO Write-up Advanced

How I hacked Github again.

Several flaws in GitHub's OAuth flow and Gist feature allowed an attacker to bypass redirect_uri validation and obtain a user's GitHub token, and a Gist could leak that token through cookies. Together these issues could let an attacker take over a victim's account.

Egor Homakov Follow

Published on homakov.blogspot.com

Bounty$4,000 View original

The original lives on homakov.blogspot.com

We do not hold its text, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 4 min read.

What the report shows

Egor Homakov's write-up covers five separate issues found in GitHub's OAuth and Gist functionality, published in February 2014. The report is short: each bug gets a heading and, in most cases, a screenshot, with very little prose. The bounty was 4,000 USD.

From the original on homakov.blogspot.com

Bug 1: bypass of redirect_uri validation with /../

The report quotes GitHub's documented rule for OAuth redirect URLs:

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 heading names the technique: a bypass of the redirect_uri validation using /../. The report gives no request or response for this bug, only the quoted rule and the technique in the heading.

Bug 2: lack of redirect_uri validation on get-token endpoint

The report quotes the API documentation for the redirect_uri parameter:

redirect_uri | string | The URL in your app where users will be sent after authorization. See details below about redirect urls. |

From the original on homakov.blogspot.com

The heading states a lack of redirect_uri validation on the get-token endpoint. The report does not include the request it sent.

Bug 3: injecting cross domain image in a gist

From the original on homakov.blogspot.com

The heading refers to injecting a cross domain image in a gist. The report shows the result in a screenshot and gives no payload text.

Bug 4: Gist reveals github_token in cookies

From the original on homakov.blogspot.com

The report states that a Gist reveals the github_token in cookies. The screenshots are the only detail provided; no cookie header, request or response is reproduced.

Bug 5: auto approval of 'scope' for Gist client

The heading states auto approval of 'scope' for the Gist client. No further detail is given.

Bounty

From the original on homakov.blogspot.com

The report records a bounty of 4,000 USD. It gives no severity rating, no CVSS score and no description of the fixes applied.

Root cause

The common thread is OAuth redirect handling.

Impact

The report does not quantify any of this beyond the headings and screenshots.

How this kind of bug works

OAuth ties an authorisation code to a client and a redirect URI. The authorisation server should compare the supplied redirect_uri against the registered one exactly, and the token endpoint should require the same value again. Bugs appear when the comparison is loose: prefix matching instead of exact matching, no normalisation of .., . or encoded characters before comparing, or validation on one endpoint but not the other. When the comparison can be defeated, the code lands on an attacker-controlled origin, and the attacker redeems it. Consent and scope handling are a related surface: if scopes are auto-approved, a client can obtain more access than the user believed they granted.

How to test for it

  1. Map the OAuth flow: the authorise endpoint, the token endpoint, the registered redirect URI, and which parameters each endpoint validates.
  2. At the authorise endpoint, send redirect_uri values that differ from the registered one only in path form: a subdirectory, then traversal segments such as /../, then encoded variants, then trailing slashes and case changes. Watch whether the server redirects to your value or rejects it.
  3. At the token endpoint, take a valid code and exchange it with a redirect_uri different from the one used at authorisation. A successful exchange is the positive result for Bug 2.
  4. For consent issues, request a scope the client does not normally use and check whether a consent screen appears.
  5. For content injection, create a document that loads a resource from another origin and inspect what the browser requests and what cookies accompany it.

False positives: a redirect that is rejected at the browser but accepted by the server, or vice versa; traversal that normalises back to the registered path; and codes that are single-use and already consumed, which make a second exchange fail for reasons unrelated to validation.

How it is fixed

Compare redirect_uri by exact string match after normalisation, on both the authorisation and token endpoints. Reject paths containing traversal segments or encoded equivalents. Bind the code to the redirect URI at issue time and verify it at exchange. Require explicit user consent for every scope, and keep tokens out of cookie values that pages can read.

Hunting notes

OAuth implementations are a reliable place to look: authorise and token endpoints, implicit and code flows, mobile and CLI clients with custom schemes, and any client that registers multiple redirect URIs. Recon signals include documentation that describes prefix or subdirectory matching, error messages that echo the supplied redirect_uri, and clients whose consent screen lists fewer scopes than the token actually carries.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 5 min read.

What happened, in plain words

In February 2014, Egor Homakov published a short write-up about five separate problems he found in GitHub. GitHub is a website where people store and share code. Two of its features matter here: OAuth, which lets other apps ask GitHub for permission to act on your account, and Gists, which are small snippets of code or text you can share.

From the original on homakov.blogspot.com

The report is brief. Each bug gets a heading and, in most cases, a screenshot, with very little explanation. GitHub paid a bounty of 4,000 USD. A bounty is a reward a company pays someone who reports a security flaw responsibly instead of abusing it.

Bug 1: bypass of redirect_uri validation with /../

When an app wants to act on your GitHub account, it sends you to GitHub to approve. GitHub then sends you back to the app at a web address the app registered in advance. That return address is called the redirect_uri. GitHub's documentation states the rule:

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

In everyday terms: the app says "send users back to my shop, and only to a room inside my shop". GitHub checks that the return address points inside the registered folder. The heading names a bypass of that check using /../. The report gives no request or response for this bug, only the quoted rule and the technique in the heading.

Bug 2: lack of redirect_uri validation on get-token endpoint

The report quotes the API documentation for the redirect_uri parameter:

redirect_uri | string | The URL in your app where users will be sent after authorization. See details below about redirect urls. |

From the original on homakov.blogspot.com

OAuth happens in two steps. First, GitHub sends the app a short-lived code. Second, the app swaps that code for a token, which is like a temporary key that lets the app act on your behalf. The second step is the "get-token" endpoint. The heading states a lack of redirect_uri validation on the get-token endpoint. The report does not include the request it sent.

Bug 3: injecting cross domain image in a gist

From the original on homakov.blogspot.com

The heading refers to injecting a cross domain image in a gist. A web page loading a picture from a different site is called a cross-domain request. The report shows the result in a screenshot and gives no payload text.

Bug 4: Gist reveals github_token in cookies

From the original on homakov.blogspot.com

A cookie is a small piece of data a website stores in your browser and sends back with each request, often used to remember who you are. A token is a secret string that proves your identity or grants access. The report states that a Gist revealed the github_token in cookies. The screenshots are the only detail provided; no cookie header, request or response is reproduced.

Bug 5: auto approval of 'scope' for Gist client

A scope is the list of permissions an app asks for, such as reading your profile or writing to your repositories. Normally GitHub shows you that list and asks you to confirm. The heading states auto approval of 'scope' for the Gist client. No further detail is given.

Bounty

From the original on homakov.blogspot.com

The report records a bounty of 4,000 USD. It gives no severity rating, no CVSS score and no description of the fixes applied.

In general, how this kind of bug works

OAuth ties an authorisation code to an app and a return address. The server should compare the supplied redirect_uri against the registered one exactly, and the token step should require the same value again. Problems appear when the comparison is loose: matching only the start of the address instead of the whole thing, not tidying up .., . or encoded characters before comparing, or checking on one step but not the other. Consent and scope handling are a related area: if scopes are approved automatically, an app can obtain more access than the user believed they granted.

In general, how to test for it

  1. Map the OAuth flow: the authorise endpoint, the token endpoint, the registered return address, and which parameters each endpoint checks.
  2. At the authorise endpoint, send redirect_uri values that differ from the registered one only in path form: a subfolder, then traversal segments such as /../, then encoded variants, then trailing slashes and case changes. Watch whether the server redirects to your value or rejects it.
  3. At the token endpoint, take a valid code and exchange it with a redirect_uri different from the one used at authorisation. A successful exchange is the positive result for Bug 2.
  4. For consent issues, request a scope the app does not normally use and check whether a consent screen appears.
  5. For content injection, create a document that loads a resource from another site and inspect what the browser requests and what cookies accompany it.

False positives: a redirect rejected by the browser but accepted by the server, or the reverse; traversal that tidies back to the registered path; and codes that are single-use and already used, which make a second exchange fail for reasons unrelated to validation.

In general, how it is fixed

Compare redirect_uri by exact string match after tidying the path, on both the authorise and token endpoints. Reject paths containing traversal segments or encoded equivalents. Tie the code to the return address when it is issued and verify it at exchange. Require explicit user consent for every scope, and keep tokens out of cookie values that pages can read.

Glossary

  • OAuth: a standard that lets one website or app get limited access to your account on another, with your approval.
  • redirect_uri: the web address an app asks the service to send you back to after you approve access.
  • Path traversal: using .. in a path to move up a folder level, so a path can resolve somewhere other than where it appears to point.
  • Endpoint: a specific web address on a server that performs one function, such as exchanging a code for a token.
  • Token: a secret string that proves identity or grants access, like a temporary key.
  • Cookie: a small piece of data a site stores in your browser and sends back with each request.
  • Scope: the list of permissions an app requests, such as reading your profile or writing to your repositories.
  • Gist: a small shareable snippet of code or text hosted by GitHub.
  • Cross-domain request: a web page loading a resource, such as an image, from a different website.
  • Bounty: a reward a company pays for a responsibly reported security flaw.
  • CVSS: a scoring system for measuring how severe a security flaw is.
  • False positive: a test result that looks like a flaw but is not one.

More from GitHub

View all

The newest disclosed reports for this program.

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.