Skip to content
OAuth / SSO Write-up Advanced

Five Low Bugs, One GitHub Private Repo Takeover

Five low-severity OAuth weaknesses in GitHub's OAuth handling, when combined, could have exposed users' private repositories. The researcher reported that the combination could have granted read/write access to private repositories.

masimshahzad Follow

Published on masimshahzad.medium.com

Bug Bounty

Muhammad Asim Shahzad, on masimshahzad.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. 5 min read.

Context

This is an analytical case study of a public disclosure, not a first-hand discovery. The research was carried out by Egor Homakov and published in February 2014 under the title How I hacked Github again. The target is GitHub's OAuth handling: the flow by which a third-party or first-party client obtains a token that can act on a user's repositories. In normal operation that flow should bind an authorisation code to the client and redirect it was issued for, keep the resulting provider token away from browser-readable storage, and ask the user before granting scopes beyond what the client is registered for.

AI-generated illustration From the original on masimshahzad.medium.com

AI-generated illustration

According to the disclosure, five individually low-severity issues in that handling, taken together, could have exposed users' private repositories. GitHub fixed them and, per the researcher, paid $4,000. The article deliberately omits reproduction details, so what follows describes the weakness classes and the reasoning rather than a runnable attack chain.

Setup

The disclosure does not describe accounts, roles, tools or versions. What it does establish is the precondition for the whole class of issue: an OAuth authorisation server that issues codes and tokens to clients, at least one of which is a trusted first-party client, and a redirect endpoint that the browser visits during the flow. No request, response, header or payload is reproduced in the source, so none appears here.

Finding it

The disclosure describes redirect URI validation that was looser than an exact match. That alone is a familiar low-severity observation. The surrounding behaviour compounded it: authorisation codes were not strictly bound to the redirect they were issued for, a provider token was stored somewhere the browser could read it, and a trusted first-party client received broad scopes without explicit consent.

Each of those is minor in isolation. The finding is that they compound: a loose redirect check lets a code or token reach an unintended destination, weak code binding means an intercepted code is still usable, browser-readable token storage exposes the token itself, and silent broad scopes mean the token carries more authority than the user agreed to. The researcher characterised the combined issue as high severity; no CVSS score is reported, and no CVE is stated in the disclosure.

Exploitation

The disclosure intentionally omits reproduction details, so there is no step-by-step chain to reproduce here. The compounding logic is what matters:

  1. Loose redirect matching allows the flow to be steered to a destination that is not the exact registered URI.
  2. Because codes are not strictly bound to their issuing redirect, a code obtained at the wrong destination can still be exchanged.
  3. Because the provider token is stored where the browser can read it, exposure of that storage yields the token itself rather than an opaque handle.
  4. Because the first-party client holds broad scopes without explicit consent, the resulting token reaches further than the user authorised.

The researcher reported that the combination could have granted read/write access to private repositories.

Root cause

The disclosure groups the weaknesses into four areas:

  • Redirect URI validation that was looser than an exact match.
  • Authorisation codes not strictly bound to the redirect they were issued for.
  • A provider token stored where the browser could read it.
  • A trusted first-party client receiving broad scopes without explicit consent.

The design mistake is treating these as independent controls. Exact redirect matching is undermined if the code can be redeemed against a different redirect; server-side token storage is undermined if the token is also reachable from the browser; and consent is undermined if first-party trust silently widens scope. Why the existing checks did not stop the combination is not described in the disclosure.

Impact

Under the conditions above, the researcher reported that the combination could have granted read/write access to private repositories. Private code often holds secrets and build configuration, so write access extends to supply-chain risk. The claim is hedged: this is what the combination could have done, as reported by the researcher, not a demonstrated compromise of specific users.

Fix

GitHub fixed the issues; the disclosure does not describe the changes made. The defensive measures below are the case study author's own analysis, not a record of GitHub's patch.

  1. Exact registered redirect matching. Compare the full URI against registered values. No prefix, path or wildcard matching, and no normalisation that changes meaning.
  2. Bind each code to client and redirect. Store both when issuing; require both to match at exchange (RFC 6749 §4.1.3).
Python
def authorize(client, redirect_uri, scopes, user):    if redirect_uri not in client.registered_redirects:          raise InvalidRedirect()    granted = scopes & client.allowed_scopes                  if granted - user.consented_scopes(client):        return show_consent(client, granted)    return issue_code(client.id, redirect_uri, granted, ttl_short=True)
Python
def exchange(code, client_id, redirect_uri, verifier):    c = codes.consume(code)                    # single use    if (c is None or c.client_id != client_id            or c.redirect_uri != redirect_uri            or not pkce_ok(c.challenge, verifier)):        raise InvalidGrant()    return mint_token(c)
  1. Keep tokens server-side. The browser should hold only an opaque session ID, never a provider token, even encoded.
  2. Explicit scopes, even for first-party clients. Pre-approval should cover only registered scopes; anything broader needs consent.
  3. Understand PKCE's limits. PKCE reduces the value of an intercepted code, but it does not fix loose redirect matching, leaked tokens or excessive scopes.
  4. Separate origins and limit referrers. Host user content away from callback origins, set Referrer-Policy: no-referrer on callbacks, and strip codes from URLs after use.

Variants to test

  • Redirect matching. Register a client and try redirect values that share a prefix, path or wildcard with the registered URI. A positive result is the server accepting a URI that is not an exact registered match.
  • Code binding. Obtain a code for one redirect and attempt exchange with a different redirect or client. A positive result is a successful exchange where either value differs from the issuing request.
  • Token storage. Inspect what the browser holds after the flow. A positive result is a provider token readable from browser storage or script rather than an opaque session identifier.
  • First-party scope widening. Authenticate through a trusted first-party client and compare granted scopes with what was consented to. A positive result is broader scopes granted without an explicit consent step.
  • Referrer leakage. Trigger navigation away from a callback page and observe the Referer header. A positive result is a code or token appearing in a referrer sent to another origin.
  • PKCE assumptions. Where PKCE is present, test whether it is the only control. A positive result is a flow that still leaks or over-scopes despite PKCE being enforced.

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

What happened, in plain words

In February 2014 a security researcher named Egor Homakov published a post called How I hacked Github again. He had looked at the way GitHub lets other applications ask for permission to act on your account, a system called OAuth, and found five separate weaknesses. Each one, on its own, was minor. Together, he reported, they could have let an attacker reach users' private repositories: the code you keep private on GitHub.

GitHub fixed the problems, and according to the researcher the company paid a $4,000 bounty, which is a reward paid for reporting a security flaw responsibly.

AI-generated illustration From the original on masimshahzad.medium.com

AI-generated illustration

This article is an analytical case study of that public disclosure. It was drafted with AI assistance and is not the author's own discovery. The point is to show, for someone new to security, why small weaknesses matter when they stack up, and how the fixes fit together. The original disclosure deliberately leaves out the exact steps needed to repeat the attack, so nothing here is a recipe you could run.

The background you need first

Before the details make sense, a few everyday ideas.

What GitHub is. GitHub is a website where people store and share code. A repository (repo) is a project folder held on GitHub. A public repo can be read by anyone; a private repo can only be read by the people it is shared with. Private repos often contain passwords, keys and build settings, which is why they matter.

What an API is. An API is a way for one piece of software to talk to another, like a waiter taking your order to the kitchen. Your browser does not reach into GitHub's database directly; it asks GitHub's API, and the API decides what to do.

What a token is. A token is a short string of characters that acts like a temporary key or a wristband at an event. Whoever holds it can do what it allows, without typing a password again. If someone else copies the token, they can often use it too. That is why tokens must be kept secret.

What a cookie is. A cookie is a small piece of data a website asks your browser to store and send back on later visits, so the site can remember who you are. Cookies live inside the browser, which means scripts running in the browser may be able to read them if they are not protected properly.

What OAuth is. OAuth is the system behind buttons like "Sign in with Google" or "Connect to GitHub". Instead of giving a third-party app your password, you are sent to the provider (here, GitHub) to approve the app. GitHub then hands the app a token. The app uses that token to act on your behalf, for example to read your repos.

The OAuth flow has a few moving parts:

  1. The app sends your browser to GitHub with a request to authorise it, including a redirect URI: the web address GitHub should send you back to afterwards.
  2. GitHub shows you a consent screen and, if you agree, creates an authorisation code, a one-time voucher.
  3. Your browser carries that code back to the app at the redirect URI.
  4. The app swaps the code for a token by talking to GitHub directly, server to server.

What a redirect URI is. It is the return address. If the return address can be tampered with, the voucher can be delivered to the wrong place, like a parcel sent to a stranger because the address label was easy to alter.

What a scope is. A scope is a permission label, such as "read your repos" or "write to your repos". Broad scopes mean more power. Consent means you were asked and agreed.

What a first-party client is. A first-party client is an app made by the same company as the provider, so it is trusted more than an outside app. The danger is when that trust quietly turns into extra permissions you never approved.

What severity and CVSS mean. Severity is how serious a flaw is judged to be. CVSS is a standard scoring system for it. The researcher called the combined issue high severity, but no CVSS score is reported, and no CVE identifier (a public catalogue number for a known flaw) is stated in the disclosure.

The five weaknesses

The disclosure describes problems in four areas, part of the five low-severity issues:

  • Loose redirect checking. GitHub checked the return address less strictly than an exact match.
  • Codes not tied to their redirect. An authorisation code was not strictly bound to the return address it was issued for, so a code obtained at the wrong place could still be redeemed.
  • A token the browser could read. A provider token was stored somewhere the browser could read it, rather than being kept only on the server.
  • Silent broad permissions. A trusted first-party client received broad scopes without an explicit consent step.

None of these is critical alone. The risk came from how they compounded, which is the heart of the case.

Why the combination mattered

Think of each weakness as one loose lock in a building. A loose lock on its own is a small problem. But if the front door is loose, the inner door is loose, and the safe is left open, a visitor can walk from one to the next.

  1. Loose redirect matching lets the flow be steered to a destination that is not the exact registered address.
  2. Because codes are not strictly bound to their issuing redirect, a code obtained at the wrong destination can still be exchanged for a token.
  3. Because the provider token is stored where the browser can read it, exposing that storage hands over the token itself, not just a useless handle.
  4. Because the first-party client holds broad scopes without explicit consent, the resulting token reaches further than the user ever agreed to.

The researcher reported that the combination could have granted read and write access to private repositories. Read access means seeing the code; write access means changing it. Private code often holds secrets and build configuration, so write access extends to supply-chain risk: the risk that tampered code flows onward into software other people use. The claim is hedged: this is what the combination could have done, as reported, not a demonstrated break-in of specific users.

What the disclosure does not say

The disclosure does not describe accounts, roles, tools or software versions, and it reproduces no request, response, header or payload. It also does not explain why the existing checks failed to stop the combination. The disclosure does not explain why the existing checks failed to stop the combination.

How to fix it

GitHub fixed the issues, but the disclosure does not describe the changes made. The measures below are the case study author's own suggestions, not a record of GitHub's patch. They are written as code, and each block is explained line by line afterwards.

1. Match the redirect address exactly

Compare the full return address against the registered values. No prefix matching, no path matching, no wildcards, and no normalisation that changes what the address means. A return address that is merely similar is not good enough.

2. Tie each code to its client and redirect

When a code is issued, store which client and which redirect it belongs to. When the code is exchanged, require both to match. This follows RFC 6749 section 4.1.3, the part of the OAuth standard that covers this exchange.

Python
def authorize(client, redirect_uri, scopes, user):    if redirect_uri not in client.registered_redirects:          raise InvalidRedirect()    granted = scopes & client.allowed_scopes                  if granted - user.consented_scopes(client):        return show_consent(client, granted)    return issue_code(client.id, redirect_uri, granted, ttl_short=True)

Line by line:

  • def authorize(...) defines the step that runs when an app asks for permission. It receives the client (the app), the return address, the scopes requested, and the user.
  • if redirect_uri not in client.registered_redirects: checks the return address against the exact list registered for that app. If it is not on the list, the next line raises InvalidRedirect(), which stops the request. This is the exact-match rule from point 1.
  • granted = scopes & client.allowed_scopes narrows the requested permissions to those the app is actually allowed to have. The & keeps only what appears in both lists.
  • if granted - user.consented_scopes(client): checks whether anything in that narrowed set has not yet been consented to by the user. If so, return show_consent(client, granted) sends the user to a consent screen instead of issuing a code. This is the explicit-consent rule.
  • return issue_code(client.id, redirect_uri, granted, ttl_short=True) creates the one-time code, recording the client and the return address with it, and gives it a short lifetime.
Python
def exchange(code, client_id, redirect_uri, verifier):    c = codes.consume(code)                    # single use    if (c is None or c.client_id != client_id            or c.redirect_uri != redirect_uri            or not pkce_ok(c.challenge, verifier)):        raise InvalidGrant()    return mint_token(c)

Line by line:

  • def exchange(...) defines the step where the app swaps the code for a token. It receives the code, the client's identity, the return address and a PKCE verifier (explained below).
  • c = codes.consume(code) looks up the code and marks it used in one go, so it cannot be replayed. The comment # single use says exactly that.
  • The if checks four things at once: the code exists (c is None catches a missing or already-used code), the client matches the one the code was issued to, the return address matches the one the code was issued for, and the PKCE check passes. If any check fails, raise InvalidGrant() rejects the exchange.
  • return mint_token(c) creates the actual token only after every check has passed.

3. Keep tokens on the server

The browser should hold only an opaque session ID, a meaningless reference number, never the provider token itself, not even in encoded form. If a script or a leaked link exposes the browser's storage, it exposes a reference number, not the key.

4. Ask for explicit scopes, even for first-party clients

Pre-approval should cover only the scopes an app is registered for. Anything broader needs the user's consent. Being made by the same company should never mean silent extra privilege.

5. Know what PKCE can and cannot do

PKCE (Proof Key for Code Exchange) is an extra check in the OAuth flow that makes an intercepted code much less useful to an attacker. It does not fix loose redirect matching, tokens leaked to the browser, or excessive scopes. It is one lock, not the whole door.

6. Separate origins and limit referrers

Host user content on a different origin (a different site address) from the callback pages. Set Referrer-Policy: no-referrer on callbacks so the browser does not tell other sites where you came from, and strip codes out of the address bar after they are used.

What to test, if you are reviewing a similar system

These are the checks a reviewer would run, described at a high level. A positive result means the weakness is present.

  • Redirect matching. Register a client and try return addresses that share a prefix, path or wildcard with the registered one. A positive result is the server accepting an address that is not an exact registered match.
  • Code binding. Obtain a code for one return address and try to exchange it with a different address or client. A positive result is a successful exchange where either value differs from the issuing request.
  • Token storage. Look at what the browser holds after the flow. A positive result is a provider token readable from browser storage or by a script, rather than an opaque session identifier.
  • First-party scope widening. Sign in through a trusted first-party client and compare the permissions granted with what you agreed to. A positive result is broader permissions granted without an explicit consent step.
  • Referrer leakage. Navigate away from a callback page and watch the Referer header, the field the browser sends to say where you came from. A positive result is a code or token appearing in a referrer sent to another site.
  • PKCE assumptions. Where PKCE is present, test whether it is the only control. A positive result is a flow that still leaks or over-grants despite PKCE being enforced.

Key takeaways

  • When triaging low findings, ask how they combine, not just how each one looks alone.
  • Exact redirect matching and code binding reduce the risk of interception. Server-side tokens and explicit scopes are still required.
  • First-party trust should never mean silent privilege.

Glossary

  • API: a defined way for one piece of software to ask another to do something.
  • Authorisation code: a short-lived, one-time voucher in OAuth that an app swaps for a token.
  • Bounty: a reward paid for reporting a security flaw responsibly.
  • Browser storage: places inside your browser, such as cookies, where a website can keep data; scripts may be able to read it.
  • Callback: the page at the redirect URI that receives the browser after the provider sends it back.
  • Client: the application asking for permission to act on your account.
  • Consent: the step where you are shown what an app wants and agree to it.
  • Cookie: a small piece of data a site asks your browser to store and send back later.
  • CVE: a public catalogue number for a known security flaw.
  • CVSS: a standard scoring system for how serious a flaw is.
  • First-party client: an app made by the same company as the provider, and therefore trusted more.
  • OAuth: the system that lets an app act on your behalf at another site without your password.
  • Opaque session ID: a meaningless reference number that points to a session on the server without revealing the secret itself.
  • Origin: the combination of scheme, host and port that identifies a site address.
  • PKCE: an extra OAuth check that makes an intercepted code much less useful.
  • Private repository: a code project on GitHub visible only to the people it is shared with.
  • Provider: the site that holds your account and issues tokens, here GitHub.
  • Redirect URI: the return address the provider sends your browser to after you approve an app.
  • Referer header: the field a browser sends to say which page you came from.
  • Repository (repo): a project folder of code, held on a service such as GitHub.
  • RFC 6749: the OAuth 2.0 standard document; section 4.1.3 covers exchanging a code for a token.
  • Scope: a permission label, such as read or write access to repositories.
  • Severity: how serious a flaw is judged to be.
  • Supply-chain risk: the risk that tampered code flows onward into software other people use.
  • Token: a string that acts like a temporary key, letting whoever holds it act on your behalf.
  • Wildcard: a pattern character that matches many values, which makes matching looser than an exact comparison.

More by masimshahzad

View all

2 more disclosed reports, best first.

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.