GitHub OAuth Bypass: The $25K HEAD Request
GitHub's OAuth authorization endpoint treated HEAD requests as non-GET, causing them to grant app access without a consent click, while CSRF protection was bypassed because HEAD is considered safe. An attacker could make a signed-in user's browser approve a malicious OAuth app, gaining access to private repositories.
Published on masimshahzad.medium.com
Bug Bounty
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.
Context
GitHub's OAuth authorisation flow is the gate between a GitHub account and any third-party application that wants to act on that account's behalf. When a user installs an OAuth app, GitHub serves a consent page and the user clicks "Authorize". That click is the whole security boundary: after it, the app can read and modify whatever the granted scopes allow.
The endpoint that implements this, the OAuth authorize URL, does two jobs on one path. A GET renders the consent page. A POST, sent by the "Authorize" button and carrying a CSRF token, grants the app access. Teddy Katz found that a third HTTP method, HEAD, could reach the grant branch without a consent click and without a CSRF token. GitHub patched it in about three hours and paid $25,000, at the time the largest bounty in its program.

AI-generated illustration
Setup
Katz spent part of summer 2019 reading the Rails source of a GitHub Enterprise trial. No special account, role or tooling is described beyond access to that code. The attack needs a signed-in victim and an attacker's OAuth app, as the report's impact section implies.
The bug was fixed on github.com in June 2019 and in GitHub Enterprise Server 2.17.3 and related releases. The report does not reproduce a proof of concept.
Finding it
Reading the OAuth authorize handler, Katz saw that the router accepted both GET and POST for the path. Inside the handler the code asked a single question: is this a GET? If yes, render the consent page. Otherwise, grant access.
That structure is the smell. The safe case is the one being tested explicitly, and every other method falls through to the state change. HEAD is the method that makes the fall-through reachable. It is defined as "GET, but headers only", and Rails routes HEAD requests to GET handlers, so the router let HEAD through to the same code. But the handler's own check still saw a request that was not a GET, so it took the grant branch. And because HEAD is supposed to be side-effect free, the CSRF protection did not require a token for it.
Exploitation
Step 1: Identify the dual-purpose endpoint
The OAuth authorize URL serves the consent page on GET and performs the grant on POST. Both methods are routed to the same handler.
Step 2: Note the branch condition
The handler distinguishes the two cases with a single test: if the request is a GET, show the page; otherwise, grant. There is no explicit allow-list of methods that may grant.
Step 3: Reach the grant branch with HEAD
Rails maps HEAD to the GET handler, so the router admits HEAD on the same path. The handler's check does not treat HEAD as a GET, so the request lands in the grant branch. Because HEAD is treated as side-effect free, the CSRF token check is skipped.
Step 4: Trigger it from a malicious site
A malicious site could make the signed-in visitor's browser approve the attacker's OAuth app. The app is approved without a consent screen and without a click. The report gives no request or response for this step.
Root cause
The mistake is HTTP method confusion in the authorisation handler: the code branches on the safe case ("is this a GET?") and lets everything else fall through to the state change. HEAD is routed like GET by the framework but is not GET as far as the handler's check is concerned, so it takes the write path.
The second failure is in the CSRF defence. It exempts methods considered safe, and HEAD is one of them, on the assumption that the application honours those semantics. Here the application did not: the same request that the CSRF layer considered harmless was the one that granted access. The two layers disagreed about what HEAD means, and the gap between them was the bypass.
Impact
OAuth consent is the main barrier between a GitHub account and every third-party app. Bypassing it with one page visit would expose private source code, secrets stored in repositories, and write access to projects that sit in other companies' supply chains. The attacker needs the victim to visit a malicious page while signed in to GitHub, and needs an OAuth app of their own to receive the grant.
GitHub's Enterprise Server 2.17.3 release notes list the "OAuth app authorization bypass" as CRITICAL. No CVE or CVSS score is cited in the sources. The bounty was $25,000 through GitHub's HackerOne program.
The response is worth noting: GitHub confirmed the report eight minutes after submission, patched production about three hours later, then shipped Enterprise Server fixes and paid the bounty a week later.
Fix
GitHub fixed the handler on github.com and shipped the fix in GitHub Enterprise Server 2.17.3 and related releases. The report does not describe the patch itself. The author's own analysis of how this class of bug should be fixed:
- Branch on the safe case, not the unsafe one. Grant only on an explicit POST; never fall through to a state change from an "else".
- Treat HEAD as read-only everywhere. Framework conveniences that map HEAD to GET must never reach write paths.
- Separate routes for reads and writes. One URL doing both jobs invites exactly this ambiguity.
The pseudocode given for the corrected shape:
# Pseudocode: state changes only on an explicit, CSRF-checked POSTdef oauth_authorize(request, user): method = request.method.upper() if method in ("GET", "HEAD"): return render_consent_page(request, user) # read-only, always safe if method == "POST": if not csrf_token_valid(request, user): return forbidden("csrf") if request.form.get("decision") != "approve": return deny_and_redirect(request) return grant_and_redirect(request, user) return method_not_allowed() # unknown methods never grant# Test: HEAD, OPTIONS, or POST without a valid token -> no grant is ever written
Variants to test
- Other methods on dual-purpose endpoints. Send OPTIONS, PUT or PATCH to any URL that renders on GET and writes on POST. A positive result is a state change or a grant without the expected token.
- HEAD against every state-changing route. Try HEAD on endpoints that normally require POST plus a CSRF token. A positive result is the side effect occurring with no token and no body.
- Framework method mapping. Where the framework routes HEAD to GET handlers, check whether the handler's own method test still distinguishes them. A positive result is a handler that treats HEAD as "not GET" and takes the write branch.
- CSRF exemptions for safe methods. Look for defences that skip token checks on GET and HEAD. A positive result is a request the CSRF layer ignores that nevertheless changes state.
- "If not GET, then write" patterns. Grep for branch conditions that test only for the safe method and default to the action. A positive result is any third method that reaches the action.
What happened, in plain words
Imagine you have a GitHub account. GitHub is a website where people store computer code, often private code that nobody outside should see. Many other websites and apps want to connect to your GitHub account: for example, a tool that reads your repositories or posts on your behalf. To let one of those apps in, GitHub shows you a page with an "Authorize" button. You read what the app wants, you click the button, and the app gets access. That click is the whole safety barrier.
In June 2019, a security researcher named Teddy Katz found a way to skip that click. A malicious website could make your browser approve an attacker's app without showing you any consent page at all. The cause was a rarely used HTTP method called HEAD. GitHub fixed it in about three hours and paid $25,000, which at the time was the largest bounty in its program.
This is an analytical case study of a public disclosure. The bug was fixed on github.com in June 2019 and in GitHub Enterprise Server 2.17.3 and related releases. No proof of concept is reproduced here.

AI-generated illustration
The words you need first
Before the story makes sense, a few everyday ideas.
- HTTP method. When your browser asks a website for something, it sends a short word describing what it wants to do. The most common is GET, which means "give me this page". POST means "here is some information, please act on it", like submitting a form. HEAD means "give me the same information as GET, but only the headers, not the body". Headers are the small labels that travel with every request and response, such as the content type. A HEAD request is meant to be a cheap way to check that a page exists without downloading it.
- OAuth. A system that lets one website act on your account at another website without giving it your password. You log in to GitHub, GitHub asks whether you want to let the other app in, and if you agree GitHub hands the app a kind of key. OAuth is what powers all those "Sign in with GitHub" buttons.
- Consent page. The screen that lists what an app wants to do and offers an "Authorize" button. It is the moment where you, the human, decide.
- CSRF token. A short random value that a website puts into a form. When the form is submitted, the site checks that the value matches what it expected. Its purpose is to stop another website from silently submitting forms on your behalf, because the other site cannot know the random value. Think of it as a numbered ticket handed out at the door: the form is only accepted if it comes back with the right ticket.
- CSRF (Cross-Site Request Forgery). An attack where a malicious page makes your browser send a request to another site where you are already logged in. Your browser automatically attaches your login, so the other site thinks the request came from you.
- Rails. A popular toolkit for building websites in the Ruby programming language. Katz read the Rails code of a GitHub Enterprise trial. Rails has built-in habits, and one of them matters here: it quietly treats a HEAD request as if it were a GET.
- Router. The part of a website that looks at the address and the method of an incoming request and decides which piece of code should handle it. Like a receptionist who sends visitors to the right desk.
- Handler. The piece of code at that desk. It does the actual work for a request.
- Branch. A decision point in code: if this, do that; otherwise, do something else.
- Scope. The list of permissions an app asks for, such as reading private repositories or writing to them.
- Bounty. A reward a company pays a researcher who reports a security bug responsibly instead of abusing it.
The setup
Katz spent part of summer 2019 reading the Rails source code of a GitHub Enterprise trial. GitHub Enterprise is the version of GitHub that companies run on their own servers. Reading source code is a normal research technique: you look for places where the code's assumptions do not hold.
No special account, role or tooling is described beyond access to that code. The attack needs a signed-in victim and an attacker's OAuth app, as the report's impact section implies.
Finding it
The endpoint that does two jobs
The OAuth authorize URL is the address GitHub sends you to when an app asks for access. Katz saw that this one address handled two different jobs depending on the method used:
- A GET shows the consent page, the screen with the "Authorize" button.
- A POST, sent when you click that button and carrying a CSRF token, actually grants the app access.
The router accepted both GET and POST for that path. Inside the handler, the code asked a single question: is this a GET? If yes, show the page. Otherwise, grant access.
That structure is the smell. The safe case is the one being tested explicitly, and every other method falls through to the state change. In plain words: the code says "if it is a harmless page view, show the page; for anything else, hand over the keys". It never lists which methods are allowed to hand over the keys.
Why HEAD slipped through
HEAD is the method that makes the fall-through reachable. It is defined as "GET, but headers only". Rails routes HEAD requests to GET handlers, so the router let HEAD through to the same code. But the handler's own check still saw a request that was not a GET, so it took the grant branch. And because HEAD is supposed to be side-effect free, the CSRF protection did not require a token for it.
Two layers of the site disagreed about what HEAD means. The router treated it like a harmless page view. The handler treated it like "not a page view, so grant". The gap between those two views was the bypass.
Exploitation, step by step
Step 1: Identify the dual-purpose endpoint
The OAuth authorize URL serves the consent page on GET and performs the grant on POST. Both methods are routed to the same handler. Why this matters: one address with two jobs means the code has to tell the jobs apart, and any mistake in that separation is a potential opening.
Step 2: Note the branch condition
The handler distinguishes the two cases with a single test: if the request is a GET, show the page; otherwise, grant. There is no explicit allow-list of methods that may grant. Why this matters: an allow-list says "only these methods may do the dangerous thing". A single "is it the safe one?" test says "everything that is not the safe one may do the dangerous thing", and there are more methods than GET and POST.
Step 3: Reach the grant branch with HEAD
Rails maps HEAD to the GET handler, so the router admits HEAD on the same path. The handler's check does not treat HEAD as a GET, so the request lands in the grant branch. Because HEAD is treated as side-effect free, the CSRF token check is skipped. Why this matters: the request looks harmless to the router and to the CSRF layer, but the handler reads it as a command to grant access.
Step 4: Trigger it from a malicious site
A malicious site could make the signed-in visitor's browser approve the attacker's OAuth app. The app is approved without a consent screen and without a click. The report gives no request or response for this step.
Why a malicious page can do this at all: your browser automatically sends your GitHub login with any request to GitHub, no matter which site told it to make the request. That is exactly the situation CSRF tokens exist to prevent, and here the token check was skipped.
The root cause
The mistake is HTTP method confusion in the authorisation handler: the code branches on the safe case ("is this a GET?") and lets everything else fall through to the state change. HEAD is routed like GET by the framework but is not GET as far as the handler's check is concerned, so it takes the write path.
The second failure is in the CSRF defence. It exempts methods considered safe, and HEAD is one of them, on the assumption that the application honours those semantics. Here the application did not: the same request that the CSRF layer considered harmless was the one that granted access. The two layers disagreed about what HEAD means, and the gap between them was the bypass.
A comparison: a building where the front desk waves through anyone carrying a "delivery" label, and the back door opens for anyone who is not carrying a "visitor" label. A person with a "delivery" label gets waved in at the front and then opens the back door, because the two guards use different rules.
Impact
OAuth consent is the main barrier between a GitHub account and every third-party app. Bypassing it with one page visit would expose private source code, secrets stored in repositories, and write access to projects that sit in other companies' supply chains. The attacker needs the victim to visit a malicious page while signed in to GitHub, and needs an OAuth app of their own to receive the grant.
GitHub's Enterprise Server 2.17.3 release notes list the "OAuth app authorization bypass" as CRITICAL. No CVE or CVSS score is cited in the sources. The bounty was $25,000 through GitHub's HackerOne program.
The response is worth noting: GitHub confirmed the report eight minutes after submission, patched production about three hours later, then shipped Enterprise Server fixes and paid the bounty a week later.
The fix
GitHub fixed the handler on github.com and shipped the fix in GitHub Enterprise Server 2.17.3 and related releases. The report does not describe the patch itself. The author's own analysis of how this class of bug should be fixed:
- Branch on the safe case, not the unsafe one. Grant only on an explicit POST; never fall through to a state change from an "else".
- Treat HEAD as read-only everywhere. Framework conveniences that map HEAD to GET must never reach write paths.
- Separate routes for reads and writes. One URL doing both jobs invites exactly this ambiguity.
The pseudocode given for the corrected shape:
# Pseudocode: state changes only on an explicit, CSRF-checked POSTdef oauth_authorize(request, user): method = request.method.upper() if method in ("GET", "HEAD"): return render_consent_page(request, user) # read-only, always safe if method == "POST": if not csrf_token_valid(request, user): return forbidden("csrf") if request.form.get("decision") != "approve": return deny_and_redirect(request) return grant_and_redirect(request, user) return method_not_allowed() # unknown methods never grant# Test: HEAD, OPTIONS, or POST without a valid token -> no grant is ever written
Line by line, in plain words:
- The first line is a comment saying what the code is meant to guarantee: access is only ever granted by an explicit POST that passed the CSRF check.
def oauth_authorize(request, user):starts the function that handles the authorize address. It receives the incoming request and the current user.method = request.method.upper()reads the method word from the request and converts it to capitals, soget,GetandGETall becomeGET.if method in ("GET", "HEAD"):checks whether the method is one of the two read-only ones. This is the safe case being tested first.return render_consent_page(request, user)shows the consent page and stops. The comment notes this is read-only and always safe.if method == "POST":is the only path that can lead to a grant. Everything else is handled by the lines after it.if not csrf_token_valid(request, user):checks the numbered ticket. If it is missing or wrong, the next line runs.return forbidden("csrf")refuses the request with a CSRF error and stops.if request.form.get("decision") != "approve":checks what the user actually chose in the form. If it is anything other than approve, the next line runs.return deny_and_redirect(request)denies access and sends the user back.return grant_and_redirect(request, user)is the only line that grants access, and it is reachable only by a POST with a valid token and an approve decision.return method_not_allowed()catches every other method, such as OPTIONS, PUT or PATCH, and refuses it. Unknown methods never grant.- The final comment states the test to run: HEAD, OPTIONS, or POST without a valid token must never write a grant.
Variants to test
These are the general lessons a defender or researcher can apply to other sites.
- Other methods on dual-purpose endpoints. Send OPTIONS, PUT or PATCH to any URL that renders on GET and writes on POST. A positive result is a state change or a grant without the expected token.
- HEAD against every state-changing route. Try HEAD on endpoints that normally require POST plus a CSRF token. A positive result is the side effect occurring with no token and no body.
- Framework method mapping. Where the framework routes HEAD to GET handlers, check whether the handler's own method test still distinguishes them. A positive result is a handler that treats HEAD as "not GET" and takes the write branch.
- CSRF exemptions for safe methods. Look for defences that skip token checks on GET and HEAD. A positive result is a request the CSRF layer ignores that nevertheless changes state.
- "If not GET, then write" patterns. Grep for branch conditions that test only for the safe method and default to the action. A positive result is any third method that reaches the action.
Key takeaways
- "If not GET, then write" is a bug waiting for a third method.
- CSRF defences that exempt safe methods assume your code honours those semantics; verify that it does.
- Fast triage and same-day payout turn a critical bug into a trust story.
Glossary
- API: a defined way for one piece of software to talk to another, like a service counter with set questions and answers.
- Authorize URL: the address on GitHub that handles an app's request for access.
- Bounty: a reward paid by a company to a researcher who reports a security bug.
- Branch: a decision point in code, where the program chooses between two or more paths.
- Consent page: the screen that lists an app's requested permissions and offers an "Authorize" button.
- CRITICAL: the highest severity label in GitHub's release notes for this issue.
- CSRF (Cross-Site Request Forgery): an attack where a malicious page makes your browser send a request to a site where you are already logged in.
- CSRF token: a random value placed in a form and checked on submission, so another site cannot submit the form on your behalf.
- CVE: a public identifier assigned to a known security vulnerability.
- CVSS: a scoring system that rates the severity of a vulnerability.
- Endpoint: a specific address on a website that performs a specific job.
- GET: an HTTP method meaning "give me this page or resource".
- Handler: the code that processes a request for a particular address.
- HEAD: an HTTP method meaning "give me the same information as GET, but only the headers, not the body".
- Headers: small labels sent with every request and response, such as the content type.
- HTTP method: the short word at the start of a request describing what the browser wants to do, such as GET, POST or HEAD.
- OPTIONS: an HTTP method used to ask a server which methods it supports for an address.
- PATCH: an HTTP method used to partially update a resource.
- POST: an HTTP method meaning "here is some information, please act on it".
- PUT: an HTTP method used to create or replace a resource.
- Rails: a toolkit for building websites in the Ruby programming language, used by GitHub.
- Router: the part of a website that decides which handler should process an incoming request.
- Scope: the list of permissions an app asks for, such as reading private repositories.
- Source code: the human-written instructions that make up a program.
- Supply chain: the chain of companies and projects whose code ends up inside other products.
- Triage: the process of reviewing and prioritising an incoming bug report.