Skip to content
CSRF Write-up Intermediate

How I exploited the json csrf with method override technique

The application accepted requests without the X-Auth-Token header and allowed a method override to bypass the PUT method restriction, enabling a JSON CSRF attack. An attacker could forge a request from another origin to perform actions on behalf of a logged-in user.

Simgamsetti Manikanta Follow

Published on medium.com

#### secureITmania

secureITmania, 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. 5 min read.

Context

This write-up describes a JSON CSRF vulnerability found during a bug bounty engagement on a web application that used cookie-based authentication. The researcher, Simgamsetti Manikanta (@zaheckmania), published it on 7 March 2020. The report does not name the target application or the bounty programme, and it does not give a payout figure.

The feature involved is an endpoint that accepts a JSON body over the PUT method. The request is authenticated with a cookie, and the application also sends a custom anti-CSRF token in an X-Auth-Token header and validates the Origin header. The goal of the exercise was to forge a cross-origin request that carries the victim's cookie and a JSON body, which is the classic JSON CSRF scenario.

Setup

The report does not describe any accounts, roles, tools or versions. The only precondition stated is that the authentication mechanism is cookie-based, which the researcher treats as the first requirement for CSRF. The proof of concept is described as a "csrfjson html script".

Finding it

The researcher starts from three conditions that a request must satisfy for a straightforward JSON CSRF:

  1. The authentication mechanism should be cookie-based. Cookie-based authentication is, by default, vulnerable to CSRF.
  2. The HTTP request should not be protected by a custom random token, either in a header or in the body.
  3. The HTTP request should not be protected by the Same Origin Policy.

If all three hold, a JSON request can be forged directly with an Ajax request from another origin. The researcher notes that JSON CSRF is still possible even when the second and third conditions are not met, and that is the case this report explores.

On the target, the first condition was satisfied: authentication was cookie-based. The second and third were not. The request was protected by a custom token in the X-Auth-Token header, and the server also validated the Origin header. The three screenshots below show the request and those protections.

Image for post
Image for post From the original on medium.com
Observation 2
Observation 2
Observation 3
Observation 3

Because the request was protected, the researcher turned to a set of bug bounty tips commonly shared on Twitter and tested each one against the protection mechanism:

  • Change the request method to GET and append the body as query parameters.
  • Test the request without the custom token and without the header.
  • Test the request with a token of exactly the same length but a different value.

The second tip worked: the application accepted the request without the X-Auth-Token header at all.

Image for post
Auth token validation From the original on medium.com

That is a token validation flaw, but on its own it was not enough to exploit. The request used the PUT method, and the server still validated the Origin header. A cross-origin Ajax request with a JSON body and the PUT method would only work if the server accepted a different Origin, which it did not.

Exploitation

Step 1: Remove the token header

The first step was to replay the original request with the X-Auth-Token header removed. The application accepted it, which showed that the anti-CSRF token was not actually enforced. The report does not include the raw request or response for this step; the result is shown only in the screenshot above.

Step 2: Try POST without Origin

With the token check bypassed, the remaining obstacle was the Origin validation combined with the PUT method. The researcher asked what would happen if the request were sent as a POST without the Origin header.

Image for post
POST method check From the original on medium.com

The server did not allow the POST method.

Image for post
WTF From the original on medium.com

Step 3: Use a method override

Since POST was rejected, the researcher used a method override technique to change how the server interpreted the request method. The server accepted the method override.

Image for post
Image for post From the original on medium.com

It also does not show the response that confirmed the override was accepted.

Step 4: Build the proof of concept

The final step was an exploit script for the proof of concept, described in the report as a "csrfjson html script". The report does not include the script itself, so the exact markup and the endpoint it targets are not available here.

Root cause

The researcher attributes the issue to poor validation of the anti-CSRF token and poor validation of the Content-Type header. The token check could be skipped entirely by omitting the X-Auth-Token header, so the presence of the header was apparently treated as optional rather than required. The Origin check and the PUT method were the remaining obstacles, and the server accepted a method override.

Impact

The researcher's goal was to forge a cross-origin JSON request carrying the victim's cookie. The attack depends on the victim being authenticated and on the browser sending the cookie with the forged request.

Fix

Based on the findings, the token check should reject any request that omits the X-Auth-Token header rather than treating it as optional, and the Content-Type should be validated strictly so that only the expected type is accepted. The Origin validation and the method restriction should also be enforced consistently, including for requests that use a method override.

Variants to test

  • Remove the anti-CSRF token header entirely and replay the request. A positive result is a normal response instead of a rejection.
  • Send a token of the same length but a different value. A positive result is that the request is still accepted.
  • Change the method to GET and move the body into query parameters. A positive result is that the endpoint processes the parameters as it would the JSON body.
  • Send the request as POST without the Origin header. A positive result is that the server accepts the method.
  • Use a method override on a POST request to reach a handler that normally requires another method. A positive result is that the server processes the request as the overridden method.
  • Check whether the Content-Type is enforced. A positive result is that a request with an unexpected content type is still processed.

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

What happened, in plain words

A security researcher was testing a website as part of a bug bounty programme. A bug bounty programme is a scheme where a company invites outside people to look for security problems in its systems and report them, sometimes for a reward. The researcher found a way to make a logged-in user's browser send a request to the site that the user never intended to send. This class of problem is called Cross-Site Request Forgery, or CSRF for short.

The site had several protections in place that are supposed to stop this kind of attack. The researcher found that the token header could be skipped, and then used a trick called a method override. The report does not name the website or the programme, and it does not say whether a reward was paid.

The write-up was published on 7 March 2020 by Simgamsetti Manikanta, who uses the handle @zaheckmania.

The ideas you need first

Before the steps make sense, here are the basic pieces. Each one is explained from scratch.

What a web request is

When you use a website, your browser is constantly sending messages to a server. A server is the computer somewhere else that holds the website and answers those messages. Each message is called an HTTP request. The server sends back a reply, called a response. Think of it like ordering at a counter: you say what you want (the request), and the person behind the counter hands you something back (the response).

Every request has a few parts:

  • A method, which is a verb saying what kind of action you want. GET means "give me something". POST means "here is some data, do something with it". PUT means "here is some data, store or replace it".
  • A URL, the address of the thing you are asking for.
  • Headers, which are small labelled notes attached to the request, like "here is my identity" or "this is the format of my data".
  • A body, which is the actual data being sent, if there is any.

What an API is

An API (Application Programming Interface) is a way for one piece of software to talk to another. On the web, it usually means a set of URLs that accept and return data rather than web pages meant for a human to look at. When a website's own pages need to save something, they often call the site's API behind the scenes. The endpoint in this report is one of those API addresses: it accepts data in a format called JSON.

What JSON is

JSON (JavaScript Object Notation) is a simple way of writing data as text, using curly braces, names and values. A JSON body might look like {"name": "example"}. It is just a structured way to package information so both sides understand it.

What a cookie is

A cookie is a small piece of text that a website asks your browser to store and to send back with every later request to that site. It is how a site remembers that you are logged in. Think of it like a wristband you get at an event: you show it once at the entrance, and after that the staff recognise you by it without asking for your ID again. Because the browser attaches the cookie automatically, any request that reaches the site carries your identity with it, whether you meant to send that request or not. That automatic behaviour is the heart of CSRF.

What a token is

A token is a second, separate piece of proof, usually a long random string. Unlike a cookie, the browser does not attach it automatically. The website's own code has to read the token and put it into the request on purpose, usually in a header. The idea is that a malicious page on another site cannot know or read the token, so it cannot produce a valid request. A token used this way is often called an anti-CSRF token.

What the Origin header is

An origin is the combination of scheme, host and port, roughly "which site this is". The Origin header is a note the browser adds to some requests saying which site the request came from. A server can look at it and refuse requests that come from somewhere unexpected. This is related to the Same Origin Policy, a browser rule that stops a page on one site from freely reading data from another site.

What CSRF means

CSRF is when an attacker makes your browser send a request to a site where you are logged in, without you knowing. The attacker does not steal your cookie. They simply rely on your browser attaching it for them. Imagine someone quietly posting a signed form in your name because your signature stamp was sitting on the desk: the recipient sees a valid signature and has no reason to doubt it.

What JSON CSRF means

JSON CSRF is the same idea applied to an API endpoint that expects a JSON body. It is not always possible, because it depends on how the site checks who you are and where the request came from.

The three conditions for a straightforward JSON CSRF

The researcher starts by listing three things that must be true for the simple version of this attack to work:

  1. The authentication mechanism should be cookie-based. Cookie-based authentication is, by default, vulnerable to CSRF.
  2. The HTTP request should not be protected by a custom random token, either in a header or in the body.
  3. The HTTP request should not be protected by the Same Origin Policy.

In plain words: if the site only relies on the automatic cookie, has no separate token, and does not check where the request came from, then an attacker can simply build a page that fires the request from another site and the site will accept it.

The researcher adds an important note: JSON CSRF is still possible even when the second and third conditions are not met. That is exactly the situation this report explores.

What the researcher found on the target

The first condition was satisfied: the site used cookie-based authentication. The second and third were not. The request was protected by a custom token sent in a header called X-Auth-Token, and the server also checked the Origin header. The three screenshots below show the request and those protections.

Image for post
Image for post From the original on medium.com
Observation 2
Observation 2
Observation 3
Observation 3

So the obvious route was closed. The researcher could not just fire a request from another site, because the token would be missing and the origin would look wrong.

Trying known tricks against the protections

Because the request was protected, the researcher turned to a set of bug bounty tips commonly shared on Twitter and tested each one against the protection mechanism:

  • Change the request method to GET and append the body as query parameters.
  • Test the request without the custom token and without the header.
  • Test the request with a token of exactly the same length but a different value.

The reasoning behind each tip is worth spelling out:

  • The first tip tries a different method, because sometimes a server checks protections on one method but forgets them on another. Moving the data into the URL as query parameters is a way of sending the same information without a body.
  • The second tip simply removes the token and its header. If the server treats the token as optional rather than required, the request goes through.
  • The third tip sends a wrong token of the same length. If the server only checks the length and not the value, a fake token passes.

The second tip worked: the application accepted the request without the X-Auth-Token header at all.

Image for post
Auth token validation From the original on medium.com

That is a token validation flaw, but on its own it was not enough to exploit. The request used the PUT method, and the server still validated the Origin header. A cross-origin Ajax request with a JSON body and the PUT method would only work if the server accepted a different Origin, which it did not. In other words, one lock was open but another was still shut.

Exploitation, step by step

Step 1: Remove the token header

The first step was to replay the original request with the X-Auth-Token header removed. The application accepted it, which showed that the anti-CSRF token was not actually enforced. The report does not include the raw request or response for this step; the result is shown only in the screenshot above.

Why this matters: the token was supposed to be the thing a malicious page could never produce. If the server is happy without it, that defence is gone.

Step 2: Try POST without Origin

With the token check bypassed, the remaining obstacle was the Origin validation combined with the PUT method. The researcher asked what would happen if the request were sent as a POST without the Origin header.

Image for post
POST method check From the original on medium.com

The server did not allow the POST method.

Image for post
WTF From the original on medium.com

Why this step was tried: the researcher was probing whether the method itself was the barrier. If POST were allowed, a malicious page might be able to send the request in a way the browser permits more easily.

Step 3: Use a method override

Since POST was rejected, the researcher used a method override technique to change how the server interpreted the request method. A method override is a convention where a request is sent using one method, but a header or parameter tells the server to treat it as a different method. It exists because some clients or browsers can only send certain methods, so the server is told "pretend this is really a PUT". The server accepted the method override.

Image for post
Image for post From the original on medium.com

The report does not state which override mechanism or header name was used, and it does not show the request that was sent. It also does not show the response that confirmed the override was accepted.

Why this matters: the server refused POST, but accepted a method override.

Step 4: Build the proof of concept

The final step was an exploit script for the proof of concept, described in the report as a "csrfjson html script". A proof of concept is a small demonstration that shows the problem is real, usually a page an attacker could host. The report does not include the script itself, so the exact markup and the endpoint it targets are not available here.

Why it happened

The researcher attributes the issue to poor validation of the anti-CSRF token and poor validation of the Content-Type header. The token check could be skipped entirely by omitting the X-Auth-Token header, so the presence of the header was apparently treated as optional rather than required. The Origin check and the restriction of the method to PUT were the remaining defences, and the method override technique allowed a request to be delivered in a way the server accepted while still reaching the handler.

What the impact would be

The researcher's goal was to forge a cross-origin JSON request carrying the victim's cookie. The attack depends on the victim being authenticated and on the browser sending the cookie with the forged request.

How to fix it

Based on the findings, the token check should reject any request that omits the X-Auth-Token header rather than treating it as optional, and the Content-Type should be validated strictly so that only the expected type is accepted. The Origin validation and the method restriction should also be enforced consistently, including for requests that use a method override.

Things worth trying on your own tests

  • Remove the anti-CSRF token header entirely and replay the request. A positive result is a normal response instead of a rejection.
  • Send a token of the same length but a different value. A positive result is that the request is still accepted.
  • Change the method to GET and move the body into query parameters. A positive result is that the endpoint processes the parameters as it would the JSON body.
  • Send the request as POST without the Origin header. A positive result is that the server accepts the method.
  • Use a method override on a POST request to reach a handler that normally requires another method. A positive result is that the server processes the request as the overridden method.
  • Check whether the Content-Type is enforced. A positive result is that a request with an unexpected content type is still processed.

Glossary

  • API: a set of addresses and rules that let one piece of software talk to another, usually exchanging data rather than web pages.
  • Ajax: a way for a web page to send requests to a server in the background, without reloading the page.
  • Anti-CSRF token: a random value the site expects in a request to prove it was built by the site's own code, not by another site.
  • Body: the part of a request that carries the actual data.
  • Bug bounty: a programme where a company invites outside researchers to find and report security problems, sometimes for a reward.
  • Cookie: a small piece of text a site stores in your browser and that your browser sends back automatically with later requests, often used to remember that you are logged in.
  • CORS: a set of rules that lets a server say which other sites are allowed to read its responses.
  • 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, without your knowledge.
  • Content-Type: a header that says what format the body is in, such as JSON.
  • Endpoint: a specific URL on a server that accepts requests and does something with them.
  • GET: an HTTP method meaning "give me something".
  • Header: a small labelled note attached to a request or response, such as an identity or a format.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • JSON: a text format for writing structured data using names and values.
  • JSON CSRF: CSRF applied to an endpoint that expects a JSON body.
  • Method: the verb in a request saying what kind of action is wanted, such as GET, POST or PUT.
  • Method override: a convention where a request is sent with one method but a header or parameter tells the server to treat it as another.
  • Origin: the combination of scheme, host and port that identifies which site a request comes from.
  • Origin header: a header the browser adds saying which site the request came from.
  • POST: an HTTP method meaning "here is some data, do something with it".
  • Proof of concept: a small demonstration showing that a problem is real and can be triggered.
  • PUT: an HTTP method meaning "here is some data, store or replace it".
  • Query parameter: a name and value appended to a URL after a question mark.
  • Same Origin Policy: a browser rule that stops a page on one site from freely reading data from another site.
  • Server: the computer that holds a website and answers requests to it.
  • Token: a piece of proof, usually a long random string, that the site's own code has to include on purpose.
  • URL: the address of something on the web.
  • X-Auth-Token: the name of the custom header the target used to carry its anti-CSRF token.

More by Simgamsetti Manikanta

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site request forgery (CSRF)

The lesson behind this report.

Another site makes a signed-in user's browser perform an action they did not intend.