CSRF Token Bypasss — A Tale of my $2k bug
The site's CSRF protection only compared the token in a request header with the token in a cookie, so any matching pair of values was accepted even if both were invalid. Combined with a permissive CORS policy, an attacker could forge requests that changed a victim's password or account details, leading to account takeover.
Published on web.archive.org
{{media:0}}
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
This is the story of my first critical bug: a CSRF token bypass that could lead to account takeover. The target was a private program on HackerOne, which I had just been invited to and which had only resolved 3 bugs at the time. Because the program is private and the bug had not yet been resolved, I cannot name the site; I refer to it as redacted.com throughout.
The site sends a CSRF token in two places in the request: in a header and in a cookie. The application failed to check the validity of the token properly.

Setup
There were no special tools or accounts involved. I had an invite to the private HackerOne program and started testing the site directly. The bug was found in my first 15 minutes of testing the site.

Finding it
The first thing I tested for was CSRF token bypass. I tried several common tricks:
- Deleting the token.
- Changing the request method.
- Changing just a letter in the token.
- Using another user's token.
None of these worked. I then remembered a trick I had read in an article some time before. I tried to find that article again so I could link to it, but I could not.
The trick relies on how the token is transmitted. In this case the CSRF token is sent in two parameters in the request: in a header and in the cookie. It only checked whether the token in the header matched the token in the cookie. If the two matched, the request succeeded. That means a wrong or invalid CSRF token can be used, as long as the value in the header matches the value in the cookie.
Exploitation
Step 1: Test with random token values
I tested with random values as the CSRF token and the request was successful. The application only checked whether the token in the header matched the token in the cookie.
Step 2: Confirm the scope
The vulnerability was site-wide. It affected critical functionality, including changing a user's password from the dashboard and changing email and account details.
Step 3: Exploit using the CORS misconfiguration
The site also had a CORS misconfiguration that allowed requests from all origins. I was able to use this to successfully exploit the vulnerability. The report does not include the specific request or payload used for this step.
Step 4: Report and reward
I did some further testing to confirm the vulnerability and submitted it. I got a reply from the team and was awarded $2k. This is my highest bounty in my 2 months of bug bounty.
Root cause
The application's CSRF validation was flawed: it only checked that the token in the header matched the token in the cookie. Because both values are supplied by the client, an attacker can set both to the same arbitrary value and the check passes. The token is never validated against a value stored server-side for the user's session, so the protection provides no assurance that the request originated from the legitimate user.
The site also had a CORS misconfiguration that allowed requests from all origins, which I used to successfully exploit the bypass.
Impact
The bypass was site-wide and affected critical functionality such as changing a user's password from the dashboard and changing email or account details. This CSRF token bypass could lead to account takeover. The report does not describe the exact attack chain or the conditions under which a victim would be affected beyond the CORS misconfiguration allowing requests from all origins.
Fix
The report does not state what fix was applied. The necessary fix is for the server to validate the CSRF token against a value it stores for the user's session, rather than only comparing the header value to the cookie value. The CORS misconfiguration that allowed requests from all origins should also be corrected.
Variants to test
- Duplicate token parameters: Send the CSRF token in two places (for example a header and a cookie, or two body parameters) with the same random value. A positive result is a successful state-changing request.
- Token in header only: Remove the cookie copy and see whether the request is still accepted. A positive result is a successful request without a valid server-side token.
- Token in cookie only: Remove the header copy and repeat. A positive result is the same.
- Mismatched values: Send different values in the header and cookie. A positive result is rejection, which confirms the comparison is the only check; if both are accepted, the validation is even weaker.
- CORS reflection: Check whether the application reflects arbitrary origins in
Access-Control-Allow-Origin. A positive result is a response allowing requests from an origin you control, which can be combined with a token bypass.
Lesson learnt: read a lot of articles and disclosed reports, keep testing and keep hunting. A big thanks to the infosec and bug bounty community; I learn a lot from your articles and disclosed reports. Hopefully someone somewhere will learn something from my article. This is my first article on bug bounty and infosec, and I look forward to writing more articles on new bugs I find. Merry Christmas and happy bug hunting.
What happened, in plain words
I found a bug that could lead to account takeover on a website. The bug was in the way the site protected its forms against a type of attack called CSRF, which I will explain below. The site tried to check a secret value called a token, but it checked it in the wrong way, so any value would pass as long as it appeared in two places at once. I found this in my first 15 minutes of testing a new private program on HackerOne, a platform where companies invite selected researchers to test their sites. The program had only resolved 3 bugs at that point. I was paid $2,000, my highest bounty in two months of doing this.
Because the program is private and the bug had not yet been resolved, I cannot name the site. I call it redacted.com throughout.

The picture above is my profile on the publishing platform where this story first appeared.
The ideas you need first
Before the steps, a few everyday comparisons for the words that come up.
- A cookie is a small note that a website asks your browser to keep and to show back to the site on every visit. Think of a cloakroom ticket: the site gives it to you, you hand it back, and the site knows it is you.
- A header is a line of extra information that your browser attaches to a request, separate from the main content. Think of the label on a parcel: the parcel is the request, the label carries instructions about it.
- A token is a long random string that a site generates to prove that a request really came from its own pages and not from somewhere else. Think of a numbered wristband given at the door of an event: only people who were inside get one.
- CSRF stands for Cross-Site Request Forgery. It is an attack where a malicious page makes your browser send a request to another site where you are already logged in, without you meaning to. Because your browser automatically attaches your cookie, the other site may believe the request came from you. The token is the defence: the malicious page cannot know the token, so its forged request should be rejected.
- An API is the part of a website that accepts requests and returns data, rather than showing you pages. Think of it as the service counter behind the shop floor: your browser talks to it directly when a page needs to save or fetch something.
- CORS stands for Cross-Origin Resource Sharing. It is a set of rules, enforced by your browser, about which other websites are allowed to read responses from a given site. A site can say, in a response header, which origins it trusts. If it says it trusts everyone, any website can read its responses.
- Account takeover means an attacker gains control of someone else's account, for example by changing the password or the email address on it.
The target and the feature
The site sends a CSRF token in two places in the request: in a header and in a cookie. The application failed to check the validity of the token properly. Those are exactly the actions an attacker would want, because they lead to account takeover.
Setup
There were no special tools or accounts involved. I had an invite to the private HackerOne program and started testing the site directly. The bug was found in my first 15 minutes of testing the site.

Finding it
The first thing I tested for was CSRF token bypass. A bypass means getting past the protection without knowing the real token. I tried several common tricks, one after another:
- Deleting the token.
- Changing the request method.
- Changing just a letter in the token.
- Using another user's token.
None of these worked. Each one is a guess about a different weakness: maybe the site forgets to check when the token is missing, maybe it only checks on one kind of request, maybe it compares loosely, maybe it accepts any token that belongs to some user. The site resisted all four.
I then remembered a trick I had read in an article some time before. I tried to find that article again so I could link to it, but I could not.
The trick relies on how the token is transmitted. In this case the CSRF token is sent in two parameters in the request: in a header and in the cookie. It only checked whether the token in the header matched the token in the cookie. If the two matched, the request succeeded. That means a wrong or invalid CSRF token can be used, as long as the value in the header matches the value in the cookie.
Put simply: the site compares the two copies of the token with each other, but never compares either copy with the value it stored for your session on its own server. Both copies come from the client, so an attacker controls both and can make them agree on any value.
Exploitation
Step 1: Test with random token values
I tested with random values as the CSRF token and the request was successful. The application only checked whether the token in the header matched the token in the cookie.
Why this step: if the site really checked the token against its own record, a random string would be rejected. A successful request with a made-up value proves the check is only a comparison between the two copies.
Step 2: Confirm the scope
The vulnerability was site-wide. It affected critical functionality, including changing a user's password from the dashboard and changing email and account details.
Why this step: a bypass on one minor form is interesting; a bypass on the password and email forms is serious, because those are the actions that let someone take over an account.
Step 3: Exploit using the CORS misconfiguration
The site also had a CORS misconfiguration that allowed requests from all origins. I was able to use this to successfully exploit the vulnerability. The report does not include the specific request or payload used for this step.
Because the site allowed requests from all origins, a page on any other site could do so, which turned the bypass into a working attack.
Step 4: Report and reward
I did some further testing to confirm the vulnerability and submitted it. I got a reply from the team and was awarded $2k. This is my highest bounty in my 2 months of bug bounty.
Root cause
The application's CSRF validation was flawed: it only checked that the token in the header matched the token in the cookie. Because both values are supplied by the client, an attacker can set both to the same arbitrary value and the check passes. The token is never validated against a value stored server-side for the user's session, so the protection provides no assurance that the request originated from the legitimate user.
The site also had a CORS misconfiguration that allowed requests from all origins, which I used to successfully exploit the bypass.
Impact
The bypass was site-wide and affected critical functionality such as changing a user's password from the dashboard and changing email or account details. This CSRF token bypass could lead to account takeover. The report does not describe the exact attack chain or the conditions under which a victim would be affected beyond the CORS misconfiguration allowing requests from all origins.
Fix
The report does not state what fix was applied. The necessary fix is for the server to validate the CSRF token against a value it stores for the user's session, rather than only comparing the header value to the cookie value. The CORS misconfiguration that allowed requests from all origins should also be corrected.
Variants to test
If you want to look for the same weakness on a site you are allowed to test, these are the variations worth trying. Each one is a small change to the same idea, and each has a clear sign of success.
- Duplicate token parameters: Send the CSRF token in two places (for example a header and a cookie, or two body parameters) with the same random value. A positive result is a successful state-changing request.
- Token in header only: Remove the cookie copy and see whether the request is still accepted. A positive result is a successful request without a valid server-side token.
- Token in cookie only: Remove the header copy and repeat. A positive result is the same.
- Mismatched values: Send different values in the header and cookie. A positive result is rejection, which confirms the comparison is the only check; if both are accepted, the validation is even weaker.
- CORS reflection: Check whether the application reflects arbitrary origins in
Access-Control-Allow-Origin. A positive result is a response allowing requests from an origin you control, which can be combined with a token bypass.
Lesson learnt
Read a lot of articles and disclosed reports, keep testing and keep hunting. A big thanks to the infosec and bug bounty community; I learn a lot from your articles and disclosed reports. Hopefully someone somewhere will learn something from my article. This is my first article on bug bounty and infosec, and I look forward to writing more articles on new bugs I find. Merry Christmas and happy bug hunting.
Glossary
- Account takeover: an attacker gains control of someone else's account, for example by changing its password or email address.
- API: the part of a website that accepts requests and returns data, rather than showing pages.
- Bounty: a reward, usually money, paid by a company for a valid security report.
- Cookie: a small piece of data a website asks your browser to store and send back with later requests.
- CORS: Cross-Origin Resource Sharing, the browser rules that decide which other websites may read a site's responses.
- CORS misconfiguration: a CORS setting that trusts more origins than it should, for example all of them.
- CSRF: Cross-Site Request Forgery, an attack where a malicious page makes your browser send a request to a site where you are logged in.
- CSRF token: a random value a site includes in its forms and checks before accepting a request that changes something.
- Header: a line of extra information attached to a request or response, separate from its main content.
- HackerOne: a platform where companies run bug bounty programs and researchers submit reports.
- Origin: the combination of scheme, host and port that identifies where a web page came from.
- Parameter: a named value sent with a request.
- Payload: the content an attacker sends to carry out an attack.
- Private program: a bug bounty program that only invited researchers can see and test.
- Request method: the verb of a request, such as GET or POST, that says what kind of action is intended.
- Root cause: the underlying reason a vulnerability exists.
- Server-side: happening on the website's own computers, as opposed to in your browser.
- Session: the period during which a site recognises you as logged in, usually tracked with a cookie.
- State-changing request: a request that alters data, such as changing a password or an email address.
- Token bypass: getting past a token check without knowing the real token.
- Vulnerability: a weakness in a system that an attacker can use to do something harmful.