Skip to content
CSRF Write-up Beginner

What was the bug?

A CSRF token was not validated when a POST request was changed to a GET, allowing an attacker to modify a victim's email and username via a crafted link. The attacker could then use the changed email to reset the password and take over the account.

Arnold Anthony Follow

Published on infosecflash.com

Bounty$2,400 View original

Pinterest runs a public bug bounty program on Bugcrowd. The Pinterest security team has fixed the vulnerability and has allowed me to publish this blog.

Arnold Anthony (@armold9anthony), on infosecflash.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

Pinterest runs a public bug bounty programme on Bugcrowd. The target here is the main web application at https://www.pinterest.com, and the feature involved is the user settings page, which lets a signed-in user change profile details such as their username and email address. The application exposes an internal endpoint, /_ngjs/resource/UserSettingsResource/update/, that performs those settings changes. At the time of the report Pinterest had 250 million monthly active users, which is why a flaw that lets an attacker rewrite the email address on an account matters so much.

The researcher reports that the Pinterest security team fixed the vulnerability and allowed the write-up to be published. All accounts used in the demonstration were test accounts.

Setup

The report does not describe a special setup. The work was done against the live site while browsing https://www.pinterest.com, using Burp Suite to capture and modify requests (the crafted link was produced with Burp's "change request method" option). The only precondition for the attack is that a victim is signed in to Pinterest and follows an attacker-supplied link.

Finding it

While browsing the site, the researcher noticed that CSRF tokens are passed in an HTTP header, X-CSRFToken, rather than in the request body. To check how strictly that token is enforced, the researcher took the request that modifies user settings:

HTTP
POST /_ngjs/resource/UserSettingsResource/update/ HTTP/1.1
Host: www.pinterest.com
Content-Type: application/x-www-form-urlencoded
X-CSRFToken: <CSRF Token>
……..
……..
<POST Parameters>

Two experiments followed.

  1. The X-CSRFToken header was removed from the POST request and the request was forwarded. The response was an error saying /resource/UserSettingsResource/update/ didn't finish after 8 seconds, which indicated that the CSRF token was in fact being validated on POST.
  2. The POST request was then changed to a GET and forwarded, again without the X-CSRFToken header. This time the response was 200 ok.

The conclusion was that the CSRF token was not validated when the POST request was converted to a GET. The researcher notes that this was an application-wide CSRF issue, as most of the endpoints in the application were vulnerable to it.

Exploitation

Because the flaw is a GET-based CSRF, the whole attack is a link. The researcher crafted it from the settings request using Burp's "change request method" option, which turns the POST parameters into a query string.

Step 1: craft the settings-change link

The link carries a source_url parameter and a data parameter holding a JSON object of user settings, URL-encoded. The fields that matter are email and username:

Decoded, the data parameter is a JSON object with an options object and an empty context object. Inside options, the attacker-controlled values are "email":"[redacted]" and "username":"dummyuser". The email address belongs to the attacker. The remaining fields carry other profile and notification settings (first_name, last_name, locale, gender, country, and so on).

Step 2: get the victim to follow the link

When a signed-in user clicks the link, their username and email address change to dummyuser and [redacted] respectively. The email address is under the attacker's control and was the one placed in the crafted link. No CSRF token is needed because the request is a GET and the token is not checked for GET requests.

Step 3: reset the password

With the victim's account now pointing at the attacker's email address, the researcher browsed to the password reset page:

Text
https://www.pinterest.com/password/reset/

The email address entered was [redacted]. Pinterest then sent a password reset link to that address. Since the address is now the email address of the user who clicked the crafted link, the attacker receives the reset link, uses it to set a new password, and logs in to the victim's account.

Root cause

The settings endpoint validates the X-CSRFToken header on POST requests but does not validate it when the same operation is reached with a GET. Because the endpoint accepts all of the settings as a single URL-encoded data parameter, the entire state change can be expressed as a query string, which makes a plain link a working exploit. The researcher describes this as application-wide: most endpoints in the application were vulnerable to the same method-switch bypass.

Impact

An attacker who gets a signed-in Pinterest user to click a crafted link can change that user's username and email address. Changing the email address to one the attacker controls turns the CSRF into a full account takeover, because the attacker can then request a password reset and receive it. The attack requires the victim to follow the link while signed in to Pinterest. Given 250 million monthly active users, the researcher describes the vulnerability as severe.

Fix

The report states that the Pinterest security team fixed the vulnerability, and the timeline records the fix on 7th December 2018, the same day the report was triaged and the bounty paid. The report does not describe the code change itself. The general remedy for this class of bug is to enforce the CSRF token on every state-changing request regardless of HTTP method, and to reject state-changing GET requests entirely.

Variants to test

  1. Method switching on state-changing endpoints: take a POST that carries a CSRF token in a header or body, remove the token, and resend the same parameters as a GET. A positive result is a 200 response and the change actually taking effect.
  2. Token in a header only: check whether the application validates the token in X-CSRFToken but ignores a missing token on other verbs (PUT, PATCH, DELETE). A positive result is a successful state change without the header.
  3. JSON-in-a-parameter endpoints: look for endpoints that accept a whole settings object as one URL-encoded parameter, as here. A positive result is that the full object can be moved into a query string and still be applied.
  4. Email change followed by password reset: after any CSRF that changes an email address, request a reset at the password reset page and confirm the mail arrives at the new address. A positive result is a reset link delivered to an address the attacker controls.
  5. Application-wide sweep: replay the method switch against other endpoints that modify account state. A positive result is any endpoint that accepts the GET form without a token.

Timeline

Date Event
1st December 2018 Vulnerability reported
7th December 2018 Triaged
7th December 2018 Pinterest rewarded a bounty of $2400
7th December 2018 Vulnerability fixed

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

Pinterest is a website where people collect pictures and links onto boards. It runs a public bug bounty programme on Bugcrowd: a programme where companies pay independent researchers to find security problems and report them privately instead of exploiting them. This write-up describes a flaw the researcher found in Pinterest's user settings feature, the page where a signed-in person changes details such as their username and email address. The flaw let an attacker change those details on someone else's account by getting that person to click a single link. Because the email address could be changed to one the attacker owns, the attacker could then ask Pinterest for a password reset and receive it, which means taking over the account completely. Pinterest had 250 million monthly active users at the time, so the researcher calls the issue severe. The Pinterest security team fixed it and allowed the write-up to be published. All accounts used in the demonstration were test accounts.

The pieces you need to know first

Before the steps make sense, here are the ideas the report relies on, explained from zero.

  • HTTP request: every time your browser loads a page or sends a form, it sends a message to a server. That message is an HTTP request. It has a method (a verb saying what kind of action it is), a path (which part of the site), headers (extra labels with information) and sometimes a body (the data being sent).
  • GET and POST: two of the HTTP methods. GET is what your browser uses when you type an address or click an ordinary link; it is meant to fetch something. POST is what a form usually uses when it sends data that changes something, such as saving settings. A useful comparison: GET is like asking a librarian to show you a book, POST is like handing over a form to change your address in their records.
  • Endpoint: a specific address on a server that performs a specific job. /_ngjs/resource/UserSettingsResource/update/ is the endpoint that saves user settings. Think of it as one particular counter in a large office building.
  • API: the set of endpoints and rules a website uses internally so its own pages can talk to its servers. The settings page in your browser calls the settings endpoint behind the scenes; that call is an API call.
  • Cookie: a small piece of data your browser stores for a website and sends back with every request to that site. After you log in, Pinterest gives your browser a cookie that identifies your session, so the server knows the request comes from you. This is why an attacker does not need your password: if your browser automatically attaches your cookie to a request, the server treats the request as yours.
  • CSRF (Cross-Site Request Forgery): an attack where a malicious page or link causes your browser to send a request to a site you are logged in to, using your cookie, without you intending it. The everyday comparison: a stranger cannot sign your name at the bank, but if they hand you a form and you sign it without reading, the signature is real. CSRF is the web version of that trick.
  • CSRF token: a random value the site puts into its pages and expects back with any request that changes something. Because an attacker on another site cannot know the random value, a request without the correct token is rejected. It is like a numbered ticket the clerk gives you and checks before accepting your form.
  • Header: a labelled line in an HTTP request or response carrying extra information, such as the content type or a token. X-CSRFToken is a custom header Pinterest uses to carry the CSRF token.
  • JSON: a text format for structured data, made of names and values in curly braces. Settings can be sent as one JSON object.
  • URL encoding: since a URL cannot contain spaces or many special characters, they are written as codes such as %22 for a double quote, %7B for {, %40 for @ and + for a space. A URL-encoded value is the same data, just written in a form a URL can carry.
  • Query string: the part of a URL after the ?, made of name=value pairs joined by &. It is how a GET request carries data.
  • Burp Suite: a tool researchers use to sit between their browser and the site, capture requests, edit them and resend them. Its "change request method" option turns a POST request into a GET request, moving the body data into the query string.
  • Account takeover: when an attacker gains control of someone else's account, here by changing the email address and then resetting the password.

Finding the bug

While browsing https://www.pinterest.com, the researcher noticed that the CSRF token is sent in an HTTP header called X-CSRFToken rather than in the body of the request. That raised a question worth testing: how strictly does the server check this token? To find out, the researcher started from the request that saves user settings:

HTTP
POST /_ngjs/resource/UserSettingsResource/update/ HTTP/1.1
Host: www.pinterest.com
Content-Type: application/x-www-form-urlencoded
X-CSRFToken: <CSRF Token>
……..
……..
<POST Parameters>

Line by line:

  1. POST /_ngjs/resource/UserSettingsResource/update/ HTTP/1.1 says this is a POST request to the settings update endpoint, using version 1.1 of the HTTP protocol. POST is the method a form uses to save changes.
  2. Host: www.pinterest.com tells the server which site the request is for. One server can host many sites, so it needs to know which one you mean.
  3. Content-Type: application/x-www-form-urlencoded says the body is in the classic form format, the same name=value&name=value style you see in a URL.
  4. X-CSRFToken: <CSRF Token> carries the random anti-CSRF value. The angle brackets are a placeholder: in a real request there would be an actual random string there.
  5. The dotted lines and <POST Parameters> stand for the rest of the request, which the report does not show: the headers and the form fields being saved.

With that request in hand, the researcher ran two experiments.

  1. The X-CSRFToken header was removed from the POST request and the request was forwarded. The response was an error saying /resource/UserSettingsResource/update/ didn't finish after 8 seconds. In plain words: the server refused to complete the save, which shows the token really is checked on POST requests. The error message is the server's own wording; the point is that the request did not succeed.
  2. The POST request was then changed to a GET and forwarded, again without the X-CSRFToken header. This time the response was 200 ok. In plain words: the same settings save, sent as a GET with no token at all, was accepted.

The conclusion: the CSRF token was not validated when the POST request was converted to a GET. The researcher notes that this was an application-wide CSRF issue, as most of the endpoints in the application were vulnerable to it.

Why does this matter so much? Because a GET request can be triggered by an ordinary link. If the server accepts a settings change as a GET, then anyone who can make you click a link can make that change happen on your account, with your cookie attached automatically by your browser.

Turning it into an account takeover

Because the flaw is a GET-based CSRF, the whole attack is a link. The researcher crafted it from the settings request using Burp's "change request method" option, which turns the POST parameters into a query string.

Step 1: craft the settings-change link

The link carries a source_url parameter and a data parameter holding a JSON object of user settings, URL-encoded. The fields that matter are email and username:

Line by line, in plain words:

  1. https://www.pinterest.com/_ngjs/resource/UserSettingsResource/update/ is the settings endpoint, the same one as before, now reached with a GET because it is a link.
  2. ? starts the query string, the part of the URL that carries data.
  3. source_url=%2Fsettings%2F is a parameter named source_url whose value is %2Fsettings%2F. Decoded, %2F is a slash, so the value is /settings/, the settings page.
  4. & separates one parameter from the next.
  5. data= starts the second parameter, which holds the whole settings object as one URL-encoded JSON value.
  6. Inside that encoded value, %7B is { and %7D is }, so the value begins with {"options":{ and ends with },"context":{}}. Decoded, the data parameter is a JSON object with an options object and an empty context object.
  7. Inside options, the attacker-controlled values are "email":"[redacted]" (written in the URL as %22email%22%3A%22anytestemail%40user.com%22, where %22 is a double quote, %3A is a colon and %40 is @) and "username":"dummyuser". The email address belongs to the attacker.
  8. The remaining fields carry other profile and notification settings (first_name, last_name, locale, gender, country, and so on).

Why build the link this way? Because the endpoint accepts all of the settings as a single URL-encoded data parameter, the entire state change can be expressed as a query string. That is what makes a plain link a working exploit: no form, no script, just an address.

Step 2: get the victim to follow the link

When a signed-in user clicks the link, their username and email address change to dummyuser and [redacted] respectively. The email address is under the attacker's control and was the one placed in the crafted link. No CSRF token is needed because the request is a GET and the token is not checked for GET requests.

Why does the victim's login matter? Because of the cookie. When the victim's browser follows the link, it automatically attaches the victim's Pinterest cookie, so the server believes the request comes from the victim and applies the change to the victim's account. The victim does not type anything and does not see a form; the click is enough.

Step 3: reset the password

With the victim's account now pointing at the attacker's email address, the researcher browsed to the password reset page:

Text
https://www.pinterest.com/password/reset/

This is the ordinary page anyone uses when they have forgotten their password. The email address entered was [redacted]. Pinterest then sent a password reset link to that address. Since the address is now the email address of the user who clicked the crafted link, the attacker receives the reset link, uses it to set a new password, and logs in to the victim's account.

Why does this complete the takeover? A password reset link is normally the safest way back into your own account, because only the owner of the email address can receive it. Here the attacker has made themselves the owner of the address on the account, so the safety mechanism works in the attacker's favour.

Why it worked

The settings endpoint validates the X-CSRFToken header on POST requests but does not validate it when the same operation is reached with a GET. Because the endpoint accepts all of the settings as a single URL-encoded data parameter, the entire state change can be expressed as a query string, which makes a plain link a working exploit. The researcher describes this as application-wide: most endpoints in the application were vulnerable to the same method-switch bypass.

How bad it was

An attacker who gets a signed-in Pinterest user to click a crafted link can change that user's username and email address. Changing the email address to one the attacker controls turns the CSRF into a full account takeover, because the attacker can then request a password reset and receive it. The attack requires the victim to follow the link while signed in to Pinterest. Given 250 million monthly active users, the researcher describes the vulnerability as severe.

The fix

The report states that the Pinterest security team fixed the vulnerability, and the timeline records the fix on 7th December 2018, the same day the report was triaged and the bounty paid. The report does not describe the code change itself. The general remedy for this class of bug is to enforce the CSRF token on every state-changing request regardless of HTTP method, and to reject state-changing GET requests entirely.

Things worth testing on other sites

These are the same checks the researcher's findings suggest, written so you can follow them with a browser and a tool such as Burp Suite.

  1. Method switching on state-changing endpoints: take a POST that carries a CSRF token in a header or body, remove the token, and resend the same parameters as a GET. A positive result is a 200 response and the change actually taking effect.
  2. Token in a header only: check whether the application validates the token in X-CSRFToken but ignores a missing token on other verbs (PUT, PATCH, DELETE). A positive result is a successful state change without the header.
  3. JSON-in-a-parameter endpoints: look for endpoints that accept a whole settings object as one URL-encoded parameter, as here. A positive result is that the full object can be moved into a query string and still be applied.
  4. Email change followed by password reset: after any CSRF that changes an email address, request a reset at the password reset page and confirm the mail arrives at the new address. A positive result is a reset link delivered to an address the attacker controls.
  5. Application-wide sweep: replay the method switch against other endpoints that modify account state. A positive result is any endpoint that accepts the GET form without a token.

Timeline

Date Event
1st December 2018 Vulnerability reported
7th December 2018 Triaged
7th December 2018 Pinterest rewarded a bounty of $2400
7th December 2018 Vulnerability fixed

Glossary

  • Account takeover: gaining control of someone else's account, here by changing their email address and then resetting the password.
  • API: the set of endpoints and rules a website uses internally so its pages can talk to its servers.
  • Bug bounty programme: a scheme where a company pays researchers to report security problems privately.
  • Burp Suite: a tool that sits between your browser and a site so you can capture, edit and resend requests.
  • Change request method: a Burp Suite option that turns a POST request into a GET request, moving the body data into the query string.
  • Cookie: a small piece of data your browser stores for a site and sends back with every request, used here to identify your logged-in session.
  • CSRF (Cross-Site Request Forgery): an attack that makes your browser send a request to a site you are logged in to, using your cookie, without your intent.
  • CSRF token: a random value the site expects back with state-changing requests, so that requests forged elsewhere are rejected.
  • GET: an HTTP method used to fetch something, and the method an ordinary link uses.
  • Header: a labelled line in an HTTP request or response carrying extra information.
  • HTTP request: the message a browser sends to a server to load a page or submit data.
  • POST: an HTTP method used to send data that changes something, such as saving a form.
  • State change: any action that alters data on the server, such as saving settings or changing an email address.
  • Triaged: the point at which the programme has reviewed a report and confirmed it is valid.
  • URL encoding: writing special characters in a URL as codes such as %22 for a double quote or %40 for @.
  • X-CSRFToken: the custom HTTP header Pinterest used to carry the CSRF token.

More from Pinterest

View all

The newest disclosed reports for this program.

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.