Skip to content
CSRF Write-up Intermediate

XSRF and Cookie manipulation on google.com

The prefsval parameter on a Google finance preferences endpoint was placed into a Set-Cookie response header without sanitisation, so commas and semicolons in the value could break out and define extra cookies. An attacker could make a logged-in victim's browser set arbitrary cookies and overwrite existing Google cookies such as PREF, without any anti-XSRF token being checked.

Michele Spagnuolo Follow

Published on blog.miki.it

Bounty$3,134 View original

Here I present a (reported and fixed) XSRF and Cookie manipulation vulnerability I discovered in google.com, requiring no user interaction. It was possible to set arbitrary cookies and tamper with existing ones.

Michele Spagnuolo, on blog.miki.it

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

Google's finance property exposes a preferences endpoint that writes user preferences into cookies. The endpoint used in this report is on the Canadian domain:

HTTP
http://www.google.ca/finance/prefs?action=set&prefsgroup=global&prefskey=RV&prefsval=<PAYLOAD>

The prefsval parameter carries the value that ends up inside a Set-Cookie response header. The report describes a cross-site request forgery issue combined with cookie manipulation: an attacker page can make a logged-in victim's browser call this endpoint and have the response set arbitrary cookies and tamper with existing ones, requiring no user interaction.

Setup

The attack requires no account on the attacker side and no special tooling. The preconditions are:

  1. The victim is logged in to a Google account.
  2. The victim uses a browser that supports setting multiple cookies within a single Set-Cookie header. The report names Safari explicitly and says the technique works on browsers that support this behaviour; Chrome does not.
  3. The victim visits an attacker-controlled HTML page.

No anti-XSRF token was required by the endpoint at the time, which is what makes the cross-site request possible.

Finding it

The bug is a lack of sanitisation of the prefsval parameter, which is reflected into a Set-Cookie header in the response. The parameter accepts commas and semicolons, and those characters are exactly what is needed to inject additional cookies into the same header.

The underlying mechanism is Set-Cookie folding: setting multiple cookies within the same Set-Cookie header. The report points to section 4.2.2 of RFC 2109, which specifies that the Set-Cookie response header comprises the token Set-Cookie: followed by a comma separated list of one or more cookies. RFC 2109 was obsoleted by RFC 2965, which was in turn obsoleted by RFC 6265. The most recent specification does not formally forbid Set-Cookie folding, but some browsers, Chrome included, do not support it. The exploit therefore works on the rest of them.

Exploitation

Step 1: craft the payload

A proof-of-concept payload is:

Text
X;,%20USER_CONTROLLED_COOKIE_NAME=<script>alert('XSS')</script>;,DUMMY=

Placed in prefsval, this payload does the following, according to the report:

  1. It sets the first cookie, called SC, to X.
  2. It terminates that cookie and sets a cookie named USER_CONTROLLED_COOKIE_NAME whose content is <script>alert('XSS')</script>, totally unescaped.
  3. It terminates that cookie and sets another cookie, DUMMY, with the rest of the original, legitimate SC cookie.

The report also notes that it is possible to set an arbitrary expiration date and path, which makes the injected cookie valid for google.com/ and not only google.com/finance.

Step 2: deliver the request from the victim's browser

Because no anti-XSRF token was used, the request can be issued cross-site. The victim, logged in to her Google account, visits this crafted HTML page:

HTML
<html>
  <body onload="document.forms[0].submit()">
    <form
      action="http://www.google.ca/finance/prefs?action=set&prefsgroup=global
    &prefskey=RV&prefsval=X;,%20USER_CONTROLLED_COOKIE_NAME=<script>alert('XSS')</script>;%20path=/;
    %20Max-Age=999999999;%20domain=.google.ca;,%20PREF=GOOGLE_COOKIE_CONTENT_CHANGED;%20path=/;
    %20Max-Age=999999999;%20domain=.google.ca;,DUMMY="
      method="post"
    >
      <input type="submit" value="Submit" />
    </form>
  </body>
</html>

The page submits the form automatically on load. The prefsval value in the form action is the folding payload extended with cookie attributes:

  1. X; sets the original SC cookie to X and terminates it.
  2. %20USER_CONTROLLED_COOKIE_NAME=<script>alert('XSS')</script>;%20path=/;%20Max-Age=999999999;%20domain=.google.ca; sets an attacker-named cookie with an unescaped script value, a path of /, a very long Max-Age and the domain .google.ca, so it applies to the whole domain rather than just the finance path.
  3. %20PREF=GOOGLE_COOKIE_CONTENT_CHANGED;%20path=/;%20Max-Age=999999999;%20domain=.google.ca; overwrites the existing Google PREF cookie with attacker-chosen content, again scoped to the whole domain and with a long lifetime.
  4. ,DUMMY= closes the header with a final cookie so that the remainder of the legitimate SC cookie is absorbed.

Step 3: result

After the victim's browser processes the response, the victim has an arbitrary cookie set for google.com (USER_CONTROLLED_COOKIE_NAME) and a Google cookie (PREF) modified. The report presents two screenshots of the result:

Root cause

The endpoint takes the prefsval parameter and writes it into a Set-Cookie response header without sanitising it. Because the parameter allows commas and semicolons, an attacker can break out of the intended cookie value and inject additional cookie definitions into the same header. The browser's support for Set-Cookie folding is what turns the injected text into separate cookies.

The request also lacked an anti-XSRF token, so a third-party page could trigger it on behalf of a logged-in victim. The two weaknesses combine: the CSRF lets the attacker reach the endpoint from any origin, and the unsanitised parameter lets the attacker control the cookies that come back.

Impact

An attacker who can get a logged-in victim to load a crafted page can set arbitrary cookies for google.com and modify existing Google cookies such as PREF, with attacker-chosen values, paths, domains and expiration dates. The report demonstrates the injected cookie value containing an unescaped <script>alert('XSS')</script>, and describes the outcome as arbitrary cookie setting and cookie tampering. The attack requires no user interaction, but it depends on the victim using a browser that supports Set-Cookie folding; Chrome does not, so the exploit does not work there.

Fix

The vulnerability was fixed in a week. The request now requires an anti-XSRF token and returns HTTP 400/Bad Request if the token is missing. The researcher received a $3133.7 reward and was listed in the Google Security Hall of Fame for the fourth time.

Variants to test

  1. Preference and settings endpoints that reflect input into Set-Cookie. Send a value containing a comma and a semicolon, such as a;,%20testcookie=1;,b=, and look at the raw response headers. A positive result is a single Set-Cookie header containing more than one cookie definition, or a second cookie appearing in the browser's cookie store.
  2. Cross-site reachability of the same endpoint. Build a page that auto-submits a form to the endpoint with no token, as in the report, and load it while authenticated. A positive result is the cookie being set even though the request originated from another site.
  3. Cookie attribute injection. Append path=/, domain= and Max-Age values to the injected cookie and check whether the resulting cookie is scoped to the parent domain and persists. A positive result is a cookie visible on paths and subdomains beyond the original endpoint.
  4. Overwriting security-relevant cookies. Target an existing cookie such as a preferences or session-related cookie and check whether its value can be replaced through the same parameter. A positive result is the original cookie value changing to the attacker-supplied one.
  5. Browser coverage. Repeat the test in browsers that support Set-Cookie folding and in one that does not, to confirm which clients are affected. A positive result is the injected cookies appearing only in the folding-capable browsers, matching the report's observation about Chrome.

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 found a way to make Google's servers hand a visitor's browser new cookies, or change existing ones, just by getting that visitor to open a web page. The visitor did not have to click anything, type anything or install anything; the page submitted the request automatically.

The page was not on Google. It was on a site the attacker controlled. But when the visitor's browser loaded it, the page quietly sent a request to a Google address. Because the visitor was already logged in to Google, the browser treated that request as coming from the visitor, and Google answered it. The answer contained instructions to store cookies, and those instructions had been shaped by the attacker.

The two problems combined here are:

  1. Cross-site request forgery (XSRF or CSRF): another website can make your browser send a request to a site where you are logged in, and that site cannot tell the difference between your own request and the forged one.
  2. Cookie manipulation: the Google endpoint that handled the request took a value from the URL and wrote it into a response header that tells the browser what cookies to store, without cleaning it up first. The attacker could therefore smuggle extra cookie definitions into that header.

The report calls the result "XSRF and Cookie manipulation" and says it required no user interaction. It was reported, fixed within a week, and paid a reward of $3133.70.

Background: the pieces you need to know

Before walking through the attack, here are the everyday ideas it relies on.

Cookies

A cookie is a small piece of text that a website asks your browser to keep and to send back on later requests to that site. Think of it like a cloakroom ticket: the site gives you a ticket, you show it again next time, and the site knows it is still you. Cookies are how most sites remember that you are logged in.

A server tells the browser to store a cookie using a response header called Set-Cookie. A header is a line of metadata that travels with an HTTP response, separate from the page content. When the browser sees Set-Cookie, it saves the cookie and attaches it to future requests for the matching site.

Cookies have attributes

A cookie is not just a name and a value. It can carry extra settings, called attributes, that control where and how long it applies:

  • path=/ means the cookie applies to the whole site, not just one folder.
  • domain=.google.ca means it applies to the whole google.ca domain, including subdomains.
  • Max-Age=999999999 means it should be kept for a long time (the number is in seconds).

These attributes matter in this story because the attacker was able to choose them, not just the cookie value.

What an endpoint is

An endpoint is a specific address on a server that does a specific job. The Google finance pages had an endpoint for saving user preferences, and that endpoint is the one the attack targets. You can think of it as a service counter: you walk up to it with a request, and it does one particular thing for you.

What a parameter is

A parameter is a named value attached to a URL, usually after a ? and separated by &. In ?action=set&prefskey=RV, the parameter action has the value set and the parameter prefskey has the value RV. Parameters are how you tell an endpoint what you want it to do.

What an anti-XSRF token is

An anti-XSRF token (also called a CSRF token) is a secret, unpredictable value that a site puts into its own pages and expects to see again when a form is submitted. Because another website cannot know or guess that value, a request forged from elsewhere will be missing it and can be rejected. It is like a cloakroom that only accepts your ticket if it also carries a stamp that only the cloakroom itself applied.

At the time of this report, the preferences endpoint did not require such a token. That is what made the cross-site request possible.

What Set-Cookie folding is

Normally one Set-Cookie header carries one cookie. Set-Cookie folding is the practice of putting several cookie definitions into a single Set-Cookie header, separated by commas. The report points to section 4.2.2 of an old web standard, RFC 2109, which describes the header as the token Set-Cookie: followed by a comma separated list of one or more cookies.

That standard was later replaced by RFC 2965, which was in turn replaced by RFC 6265. The newest standard does not formally forbid folding, but some browsers, Chrome included, do not support it. So the exploit works on the browsers that do.

The bug

The bug is a lack of sanitisation of the prefsval parameter. Sanitisation means cleaning up input so that characters with special meaning cannot do anything unexpected. Here, the value of prefsval was placed into a Set-Cookie header in the response, and the parameter allowed commas and semicolons. Those two characters are exactly what you need to end one cookie definition and start another inside the same header.

The endpoint used in the report is on the Canadian domain:

HTTP
http://www.google.ca/finance/prefs?action=set&prefsgroup=global&prefskey=RV&prefsval=<PAYLOAD>

Line by line:

  • http://www.google.ca/finance/prefs is the address of the preferences endpoint on Google's Canadian finance site.
  • ? starts the list of parameters.
  • action=set tells the endpoint that the action is to set a preference.
  • prefsgroup=global and prefskey=RV identify which preference is being set.
  • prefsval=<PAYLOAD> is the value for that preference. This is the part the attacker controls, and the part that ends up inside the Set-Cookie header.

Step 1: craft the payload

A proof-of-concept payload is:

Text
X;,%20USER_CONTROLLED_COOKIE_NAME=<script>alert('XSS')</script>;,DUMMY=

Placed in prefsval, this payload does the following, according to the report:

  1. It sets the first cookie, called SC, to X.
  2. It terminates that cookie and sets a cookie named USER_CONTROLLED_COOKIE_NAME whose content is <script>alert('XSS')</script>, totally unescaped.
  3. It terminates that cookie and sets another cookie, DUMMY, with the rest of the original, legitimate SC cookie.

In plain words: the endpoint was going to write a cookie called SC with whatever value it was given. The attacker's value starts with X;, which makes SC equal to X and then ends that cookie definition with the semicolon. The %20 is an encoded space. After the comma, a new cookie definition begins: USER_CONTROLLED_COOKIE_NAME with a value containing a script tag. The script tag is stored exactly as written, with no escaping, which is why the report calls it "totally unescaped". Another semicolon ends that cookie, and DUMMY= starts a final cookie that absorbs whatever legitimate text the server appends after the attacker's input.

The report also notes that it is possible to set an arbitrary expiration date and path, which makes the injected cookie valid for google.com/ and not only google.com/finance. In other words, the attacker is not limited to the finance section: the cookie can be made to apply to the whole site and to last a very long time.

Step 2: deliver the request from the victim's browser

Because no anti-XSRF token was used, the request can be issued from another site. The victim, logged in to her Google account, visits this crafted HTML page:

HTML
<html>
  <body onload="document.forms[0].submit()">
    <form
      action="http://www.google.ca/finance/prefs?action=set&prefsgroup=global
    &prefskey=RV&prefsval=X;,%20USER_CONTROLLED_COOKIE_NAME=<script>alert('XSS')</script>;%20path=/;
    %20Max-Age=999999999;%20domain=.google.ca;,%20PREF=GOOGLE_COOKIE_CONTENT_CHANGED;%20path=/;
    %20Max-Age=999999999;%20domain=.google.ca;,DUMMY="
      method="post"
    >
      <input type="submit" value="Submit" />
    </form>
  </body>
</html>

Line by line:

  • <html> and </html> wrap the whole page.
  • <body onload="document.forms[0].submit()"> means: as soon as the page finishes loading, automatically submit the first form on the page. This is why the victim does not have to click anything.
  • <form ... method="post"> starts a form that will be sent as an HTTP POST request to the address in action.
  • The action attribute holds the Google endpoint URL, with the folding payload placed in prefsval. The value is spread over several lines in the source, but it is one continuous URL.
  • <input type="submit" value="Submit" /> is a submit button. It exists so the form has something to submit; the automatic onload does the actual submitting.
  • </form>, </body> and </html> close the form, the body and the page.

The prefsval value in the form action is the folding payload extended with cookie attributes:

  1. X; sets the original SC cookie to X and terminates it.
  2. %20USER_CONTROLLED_COOKIE_NAME=<script>alert('XSS')</script>;%20path=/;%20Max-Age=999999999;%20domain=.google.ca; sets an attacker-named cookie with an unescaped script value, a path of /, a very long Max-Age and the domain .google.ca, so it applies to the whole domain rather than just the finance path.
  3. %20PREF=GOOGLE_COOKIE_CONTENT_CHANGED;%20path=/;%20Max-Age=999999999;%20domain=.google.ca; overwrites the existing Google PREF cookie with attacker-chosen content, again scoped to the whole domain and with a long lifetime.
  4. ,DUMMY= closes the header with a final cookie so that the remainder of the legitimate SC cookie is absorbed.

Why each step is taken:

  • The automatic submit is what turns a harmless-looking page into a request to Google. The victim only has to open the page.
  • The X; and the semicolons end the cookie the server intended to write, so the attacker's text becomes new cookie definitions.
  • The path=/ and domain=.google.ca attributes make the injected cookie apply to the whole domain rather than just the finance path.
  • The Max-Age=999999999 attribute is there to make the cookie last a long time.
  • The PREF=GOOGLE_COOKIE_CONTENT_CHANGED part sets the existing Google PREF cookie to a new value.
  • The final DUMMY= is there to absorb the rest of the original, legitimate SC cookie.

Step 3: result

After the victim's browser processes the response, the victim has an arbitrary cookie set for google.com (USER_CONTROLLED_COOKIE_NAME) and a Google cookie (PREF) modified. The report presents two screenshots of the result:

Root cause

The endpoint takes the prefsval parameter and writes it into a Set-Cookie response header without sanitising it. Because the parameter allows commas and semicolons, an attacker can break out of the intended cookie value and inject additional cookie definitions into the same header. The browser's support for Set-Cookie folding is what turns the injected text into separate cookies.

The request also lacked an anti-XSRF token, so a third-party page could trigger it on behalf of a logged-in victim. The two weaknesses combine: the CSRF lets the attacker reach the endpoint from any origin, and the unsanitised parameter lets the attacker control the cookies that come back.

Impact

An attacker who can get a logged-in victim to load a crafted page can set arbitrary cookies for google.com and modify existing Google cookies such as PREF, with attacker-chosen values, paths, domains and expiration dates. The report demonstrates the injected cookie value containing an unescaped <script>alert('XSS')</script>, and describes the outcome as arbitrary cookie setting and cookie tampering. The attack requires no user interaction, but it depends on the victim using a browser that supports Set-Cookie folding; Chrome does not, so the exploit does not work there.

Fix

The vulnerability was fixed in a week. The request now requires an anti-XSRF token and returns HTTP 400/Bad Request if the token is missing. The researcher received a $3133.7 reward and was listed in the Google Security Hall of Fame for the fourth time.

Variants to test

If you want to look for similar issues on other sites, here are the same ideas written as tests you can try. Each one describes what to send and what a positive result looks like.

  1. Preference and settings endpoints that reflect input into Set-Cookie. Send a value containing a comma and a semicolon, such as a;,%20testcookie=1;,b=, and look at the raw response headers. A positive result is a single Set-Cookie header containing more than one cookie definition, or a second cookie appearing in the browser's cookie store.
  2. Cross-site reachability of the same endpoint. Build a page that auto-submits a form to the endpoint with no token, as in the report, and load it while authenticated. A positive result is the cookie being set even though the request originated from another site.
  3. Cookie attribute injection. Append path=/, domain= and Max-Age values to the injected cookie and check whether the resulting cookie is scoped to the parent domain and persists. A positive result is a cookie visible on paths and subdomains beyond the original endpoint.
  4. Overwriting security-relevant cookies. Target an existing cookie such as a preferences or session-related cookie and check whether its value can be replaced through the same parameter. A positive result is the original cookie value changing to the attacker-supplied one.
  5. Browser coverage. Repeat the test in browsers that support Set-Cookie folding and in one that does not, to confirm which clients are affected. A positive result is the injected cookies appearing only in the folding-capable browsers, matching the report's observation about Chrome.

Glossary

  • Anti-XSRF token (CSRF token): a secret, unpredictable value that a site includes in its own pages and checks on submission, so that requests forged from other sites can be rejected.
  • Attribute (cookie attribute): an extra setting on a cookie, such as path, domain or Max-Age, that controls where and how long the cookie applies.
  • Cookie: a small piece of text a website asks the browser to store and send back on later requests, often used to remember that you are logged in.
  • Cross-site request forgery (XSRF or CSRF): an attack where another website makes your browser send a request to a site where you are logged in, and the site cannot tell it apart from your own request.
  • Endpoint: a specific address on a server that performs a specific job when it receives a request.
  • Header: a line of metadata sent with an HTTP request or response, separate from the page content.
  • HTTP 400/Bad Request: an HTTP status code meaning the server refused the request because it was malformed or missing something it required.
  • Max-Age: a cookie attribute that says how many seconds the browser should keep the cookie.
  • Parameter: a named value attached to a URL, usually after a ? and separated by &, used to tell an endpoint what to do.
  • Path (cookie attribute): a cookie attribute that limits which parts of a site the cookie applies to; path=/ means the whole site.
  • Payload: the attacker-controlled piece of input that is sent to a target, here the value placed in prefsval.
  • PREF: an existing Google cookie that the report shows being overwritten.
  • RFC 2109: an old web standard that describes Set-Cookie as a comma separated list of one or more cookies.
  • RFC 2965: the standard that replaced RFC 2109.
  • RFC 6265: the standard that replaced RFC 2965; it does not formally forbid Set-Cookie folding, but some browsers do not support folding.
  • Sanitisation: cleaning up input so that characters with special meaning cannot do anything unexpected.
  • SC: the cookie the endpoint originally intended to write, which the payload breaks out of.
  • Set-Cookie: the response header a server uses to tell the browser to store a cookie.
  • Set-Cookie folding: putting several cookie definitions into a single Set-Cookie header, separated by commas.
  • XSS (cross-site scripting): a class of issue where attacker-supplied script ends up in a page or a stored value; the report shows a script tag stored unescaped in a cookie value.

More by Michele Spagnuolo

View all

1 more disclosed report, 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.

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.