Skip to content
CORS Write-up Intermediate

CORS bug on google's 404 page (rewarded)

The 404 page on Kaggle reflected any Origin in its CORS headers and allowed credentials, so a third-party site could read the page's contents. That page embedded the user's anti-forgery token, letting an attacker steal it and create an API key on the victim's behalf.

Jayateertha Guruprasad Follow

Published on medium.com

{{media:0}}

jayateertha guruprasad, 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. 4 min read.

Context

Kaggle is one of Google's acquisitions and is widely used by the machine learning community. The researcher, Jayateertha Guruprasad, was testing the site for CSRF and CORS issues. The interesting behaviour turned up not on a normal application page but on the site's 404 error page, which was found by accident.

The 404 page's source contained a script tag whose body held an AntiForgery token. That token is the same value the site sends as the X-XSRF-TOKEN header on all requests, and it is the CSRF token used as a header on all sensitive endpoints. In other words, the error page was leaking a per-user CSRF token, and the same page was also returning permissive CORS headers.

Setup

No special accounts, roles, tools or versions are described. The work was done by browsing the site, viewing the source of the 404 page, and replaying requests with a modified Origin header.

Finding it

The researcher first looked for CSRF bugs across the site without success, then searched for CORS misconfigurations and also found nothing useful. While visiting a 404 page accidentally, the page source showed a script tag whose body contained the AntiForgery token. That token is the same one sent as X-XSRF-TOKEN in all requests, and it is the CSRF token sent as a header to all sensitive endpoints.

Image for post
antiForgeryToken leaked via CORS misconfig in 404 page From the original on medium.com

The screenshot shows the antiForgeryToken leaked via the CORS misconfiguration in the 404 page.

Next, the Origin header of the 404 page request was changed to mydomain.tld and the request was replayed. The response came back with Access-Control-Allow-Origin set to mydomain.tld and Access-Control-Allow-Credentials set to True. That combination means any third-party domain can read the response from kaggle.com. The behaviour appeared only on the 404 page, so the misconfiguration was specific to that page.

Exploitation

The proof of concept had two parts:

  1. Get the user-specific Kaggle CSRF token from the 404 page.
  2. Use that CSRF token to generate an API key on behalf of the user.
Image for post
Generate API KEY on begalf of user using CORS and CSRF bugs combined. From the original on medium.com

The screenshot shows the API key being generated on behalf of the user by combining the CORS and CSRF bugs.

Step 1: read the CSRF token cross-origin

Because the response carries Access-Control-Allow-Origin: mydomain.tld together with Access-Control-Allow-Credentials: True, the browser lets the attacker's JavaScript read the body. That body contains the script tag with the AntiForgery token, which is the victim's CSRF token.

Step 2: use the token against a sensitive endpoint

The stolen token is then sent as the X-XSRF-TOKEN header to a sensitive Kaggle endpoint, in this case the one that generates an API key.

The report does not include the raw HTTP requests, the exact endpoint paths, or the response bodies for either step; it describes the two steps and shows the result in the screenshot above.

Root cause

The 404 page returned Access-Control-Allow-Origin set to the supplied mydomain.tld and paired it with Access-Control-Allow-Credentials: True. Reflecting an arbitrary origin while allowing credentials means any site can make credentialed reads of that response. The page also embedded the user's AntiForgery token in a script tag in its body, so the permissive CORS policy exposed a secret that the rest of the application relies on for CSRF protection. The error page embedded the user's AntiForgery token in a script tag, so the permissive CORS policy exposed a secret the application relies on for CSRF protection. The report does not describe the server-side code, so the exact reason the header was set only on the 404 page is not stated.

Impact

An attacker who can lure a logged-in Kaggle user to a malicious page can read that user's CSRF token and then perform sensitive actions as the user, here generating an API key. The report frames this as a combination of a CORS bug and a CSRF bug. The impact depends on the victim being authenticated and visiting the attacker's page while the misconfigured 404 page is live. The researcher reported the issue to the Google VRP team with the proof of concept and was rewarded, with a lower amount than a bug on Google itself would typically receive; a bug on a Google acquisition is rewarded relatively lower compared to a bug on Google.

Fix

The report does not state what was changed. The fix implied by the finding is to stop reflecting arbitrary origins on the 404 page: return a fixed, trusted Access-Control-Allow-Origin (or none at all) and do not combine a reflected origin with Access-Control-Allow-Credentials: True. The AntiForgery token should also not be embedded in the body of an error page that any origin can read.

Variants to test

  • Send a request to error pages (404, 500, maintenance pages) with Origin: https://example.com and check whether the response reflects it in Access-Control-Allow-Origin alongside Access-Control-Allow-Credentials: True. A positive result is the exact origin echoed back with credentials allowed.
  • View the source of error pages while logged in and look for tokens, session identifiers or other per-user secrets embedded in script tags. A positive result is a value that also appears in a request header such as X-XSRF-TOKEN.
  • Replay the same Origin test against normal application pages to confirm the behaviour is limited to the error page, which tells you where the misconfiguration lives.
  • If a token is leaked, try it as the CSRF header against sensitive endpoints such as API key creation. A positive result is the action succeeding with the victim's session.

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

A security researcher found a bug on Kaggle, a website owned by Google where people share data and machine learning projects. The bug was not on a normal page of the site. It was on the page the site shows when you ask for something that does not exist, the so-called 404 error page.

That error page had two problems at once. First, it contained a secret value belonging to whoever was logged in, a token the site normally uses to prove that a request really came from the user and not from an attacker. Second, the page was willing to hand its contents to any other website that asked, because of a misconfiguration in a browser rule called CORS. Put together, any website could read the secret token of a logged-in Kaggle user, and then use that token to create an API key in that user's name.

The researcher reported it to Google's bug bounty programme, the Google VRP, and was paid a reward. The amount was smaller than a bug found directly on a Google site would usually earn, because Kaggle is an acquisition rather than a core Google product.

Some background first

Before walking through the finding, here are the ideas you need. None of them require any security knowledge, just a rough picture of how websites work.

What Kaggle is. Kaggle is a website used by the machine learning community. People upload datasets, run competitions and share notebooks of code. It is one of Google's acquisitions, meaning Google bought the company and the site became part of Google's family of products.

What a 404 page is. When you type a web address that does not exist on a server, the server answers with a standard error code, 404, which means "not found". Most sites show a friendly page in that case, something like "sorry, this page does not exist". These pages are easy to forget about, which is exactly why bugs hide there.

What a cookie and a session are. When you log in to a website, the server gives your browser a small piece of data called a cookie. Your browser sends that cookie back with every request you make to the site, so the server knows who you are without asking for your password again. The period during which the server remembers you is called your session. Think of it like a wristband at an event: you show it once at the entrance, and after that staff recognise you by the band.

What a token is. A token is a value, usually a long random-looking string, that stands in for something else. Here the token is a CSRF token, sometimes called an AntiForgery token. It is a secret value tied to your session that the site expects to see attached to sensitive requests. It works like a stamped form: the site gives you the stamp when you log in, and it checks the stamp before doing anything important.

What CSRF is. CSRF stands for Cross-Site Request Forgery. The idea is that an attacker's website tricks your browser into sending a request to another site where you are logged in. Because your browser automatically attaches your cookies, the other site might believe the request came from you. The defence is the CSRF token: the attacker's page does not know your token, so the request it forges is rejected. This is why the token is a secret worth stealing.

What CORS is. CORS stands for Cross-Origin Resource Sharing. Browsers have a rule that a page from one website (one origin) cannot read the response of a request to a different website, unless that other website explicitly says it is allowed. The other website says so with response headers, small labels attached to its answer. Access-Control-Allow-Origin names which website is allowed to read the response, and Access-Control-Allow-Credentials: True says that the request may include the visitor's cookies. If a site echoes back whatever origin asked, and also allows credentials, then any website at all can read the response as the logged-in user. That is the misconfiguration here.

What an API key is. An API is a way for programs to talk to a website without a browser, for example to upload a dataset automatically. An API key is a long secret string that identifies the program and authorises it, a bit like a password for software. If someone creates an API key in your account, they can act as you through the API.

What a proof of concept is. A proof of concept, or POC, is a small demonstration that shows a bug is real and can be exploited, without doing any actual harm. It is what researchers attach to a report so the company can reproduce the problem.

The setup

The report does not describe any special accounts, roles, tools or software versions. The work was done with an ordinary browser: browsing the site, viewing the source code of the 404 page, and replaying requests with a modified Origin header. The Origin header is a label the browser attaches to a request saying which website the request is coming from.

Finding it

The researcher started by hunting for CSRF bugs across the site, and found nothing. Then he looked for CORS misconfigurations, and again found nothing useful. Both searches came up empty.

Then, by accident, he visited a 404 page and looked at its source code. Viewing source is what your browser can show you when you press the option that displays the raw HTML the server sent, rather than the rendered page. In that source there was a script tag, an HTML element normally used to include code, whose body contained the AntiForgery token. That token is the same value the site sends as the X-XSRF-TOKEN header on all requests, and it is the CSRF token used as a header on all sensitive endpoints. In other words, the error page was leaking a per-user CSRF token.

Image for post
antiForgeryToken leaked via CORS misconfig in 404 page From the original on medium.com

The screenshot shows the antiForgeryToken leaked via the CORS misconfiguration in the 404 page.

Next, the researcher changed the Origin header of the 404 page request to mydomain.tld and replayed the request. Replaying means sending the same request again, with one detail changed, to see how the server reacts. The response came back with Access-Control-Allow-Origin set to mydomain.tld and Access-Control-Allow-Credentials set to True. That combination means any third-party domain can read the response from kaggle.com. The behaviour appeared only on the 404 page, so the misconfiguration was specific to that page.

Exploitation

The proof of concept had two parts:

  1. Get the user-specific Kaggle CSRF token from the 404 page.
  2. Use that CSRF token to generate an API key on behalf of the user.
Image for post
Generate API KEY on begalf of user using CORS and CSRF bugs combined. From the original on medium.com

The screenshot shows the API key being generated on behalf of the user by combining the CORS and CSRF bugs.

Step 1: read the CSRF token cross-origin

"Credentialed" means the request carries the victim's cookies, so the server treats it as coming from the logged-in victim. "Cross-origin" means the request goes from one website to a different one. Because the response carries Access-Control-Allow-Origin: mydomain.tld together with Access-Control-Allow-Credentials: True, the browser lets the attacker's JavaScript read the body. That body contains the script tag with the AntiForgery token, which is the victim's CSRF token.

Why this step matters: without the CORS misconfiguration, the browser would block the attacker's page from reading the answer, even though the request itself would still be sent. The misconfiguration is what turns a harmless error page into a way to read a secret.

Step 2: use the token against a sensitive endpoint

The stolen token is then sent as the X-XSRF-TOKEN header to a sensitive Kaggle endpoint, in this case the one that generates an API key. An endpoint is a specific address on the server that performs a particular action.

Why this step matters: the token alone is not enough to do damage. It becomes dangerous because the site trusts it as proof that the request came from the real user. With the token in hand, the attacker's forged request looks legitimate.

The report does not include the raw HTTP requests, the exact endpoint paths, or the response bodies for either step; it describes the two steps and shows the result in the screenshot above.

Root cause

The 404 page returned Access-Control-Allow-Origin set to the supplied mydomain.tld and paired it with Access-Control-Allow-Credentials: True. Reflecting means copying back whatever value was sent, instead of checking it against a list of trusted sites. Reflecting an arbitrary origin while allowing credentials means any site can make credentialed reads of that response. The page also embedded the user's AntiForgery token in a script tag in its body, so the permissive CORS policy exposed a secret that the rest of the application relies on for CSRF protection. The error page embedded the user's AntiForgery token in a script tag, so the permissive CORS policy exposed a secret the application relies on for CSRF protection. The report does not describe the server-side code, so the exact reason the header was set only on the 404 page is not stated.

Impact

An attacker who can lure a logged-in Kaggle user to a malicious page can read that user's CSRF token and then perform sensitive actions as the user, here generating an API key. The report frames this as a combination of a CORS bug and a CSRF bug. The impact depends on the victim being authenticated and visiting the attacker's page while the misconfigured 404 page is live. The researcher reported the issue to the Google VRP team with the proof of concept and was rewarded, with a lower amount than a bug on Google itself would typically receive; a bug on a Google acquisition is rewarded relatively lower compared to a bug on Google.

Fix

The fix implied by the finding is to stop reflecting arbitrary origins on the 404 page: return a fixed, trusted Access-Control-Allow-Origin (or none at all) and do not combine a reflected origin with Access-Control-Allow-Credentials: True. The AntiForgery token should also not be embedded in the body of an error page that any origin can read.

Variants to test

If you want to look for similar problems yourself, these are the checks the finding suggests. Each one is a small experiment you can run with a browser and a tool that lets you change request headers.

  • Send a request to error pages (404, 500, maintenance pages) with Origin: https://example.com and check whether the response reflects it in Access-Control-Allow-Origin alongside Access-Control-Allow-Credentials: True. A positive result is the exact origin echoed back with credentials allowed.
  • View the source of error pages while logged in and look for tokens, session identifiers or other per-user secrets embedded in script tags. A positive result is a value that also appears in a request header such as X-XSRF-TOKEN.
  • Replay the same Origin test against normal application pages to confirm the behaviour is limited to the error page, which tells you where the misconfiguration lives.
  • If a token is leaked, try it as the CSRF header against sensitive endpoints such as API key creation. A positive result is the action succeeding with the victim's session.

Glossary

  • 404 page: the page a website shows when the address you asked for does not exist; the server answers with the standard error code 404.
  • Acquisition: a company that has been bought by another company; Kaggle is one of Google's acquisitions.
  • AntiForgery token: another name for a CSRF token, a secret value tied to your session that the site checks before performing sensitive actions.
  • API: a way for programs to talk to a website without a browser, for example to upload data automatically.
  • API key: a long secret string that identifies a program to an API and authorises it, like a password for software.
  • Cookie: a small piece of data a website stores in your browser and that your browser sends back with every request, so the server knows who you are.
  • CORS: Cross-Origin Resource Sharing, the browser rule that decides whether a page from one website may read the response of a request to a different website, based on headers the other website sends.
  • Access-Control-Allow-Origin: the response header that names which website is allowed to read the response.
  • Access-Control-Allow-Credentials: the response header that says whether the request may include the visitor's cookies; True means yes.
  • Credentials: in this context, the cookies that identify your logged-in session.
  • Cross-origin: a request from one website to a different website.
  • CSRF: Cross-Site Request Forgery, an attack where a malicious website tricks your browser into sending a request to a site where you are logged in, hoping the site treats it as yours.
  • CSRF token: a secret value tied to your session that the site expects on sensitive requests, so forged requests without it are rejected.
  • Endpoint: a specific address on a server that performs a particular action.
  • Header: a small label attached to a request or response, carrying extra information such as where the request came from or what is allowed.
  • Origin: the request header that says which website the request is coming from.
  • X-XSRF-TOKEN: the request header Kaggle uses to carry the CSRF token on sensitive requests.
  • Proof of concept (POC): a small demonstration showing that a bug is real and can be exploited, without doing actual harm.
  • Reflect: to copy a value from the request straight back into the response, instead of checking it against a list of trusted values.
  • Replay: to send the same request again, usually with one detail changed, to see how the server reacts.
  • Session: the period during which a website remembers you after you log in, usually tracked with a cookie.
  • Source code (view source): the raw HTML a server sent, which your browser can display instead of the rendered page.
  • Token: a value, usually a long random-looking string, that stands in for something else, such as proof of your session.
  • Google VRP: Google's Vulnerability Reward Program, the bug bounty programme through which the researcher reported the issue and was paid.

More by Jayateertha Guruprasad

View all

10 more disclosed reports, best first.

More from Google

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

CORS misconfiguration

The lesson behind this report.

A permissive cross-origin policy lets another site read responses with the user's credentials.