Google Books X-Hacking
A cross-site search attack on Google Books exploited the Chromium XSS Auditor to detect whether a search query returned a specific book title, and a uid parameter flaw allowed searching a logged-in user's private book collections without knowing their uid. An attacker could exfiltrate the victim's private book collections and reading history.
Security
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Google Books at books.google.com is a search and library interface for books. A signed-in user has a private library: book collections, reading history, purchases and searches. The report describes a cross-site search (XS-Search) attack against that private library, carried out from a malicious page in another origin, without the attacker knowing the victim's Google user identifier (<uid>).
The technique is borrowed from the Filemanager task at 35c3ctf, which abused the Chromium XSS Auditor. The author frames this write-up as the first of several demonstrating a successful cross-site search, here against books.google.com.

Setup
The attack needs a victim who is a regular signed-in user of Google Books and who visits an attacker-controlled page. The attacker needs no account on the target and, after the second finding below, no knowledge of the victim's <uid>. The technique depends on the XSS Auditor blocking the crafted page, an abuse borrowed from the Filemanager task at 35c3ctf.
Finding it
While inspecting the page source, the author noticed that a search query returning at least one book causes a block of JavaScript to be inserted into the page, and that this block is absent when the query returns nothing. The inserted code begins with:
<script>if (window['_OC_registerHover']){_OC_registerHover({"title":"<title>"
Here <title> is the title of the first displayed result. The important property is that the reflected value is the title of the first result, not the query string: the page echoes data derived from the user's own library back into the HTML.
That gives a conditional primitive. For a chosen <title> and a known user <uid>, the author could build a URL of the form:
https://books.google.com/books?uid=<uid>&num=1&q=<title>&x=<script>if (window['_OC_registerHover']){_OC_registerHover({"title":"<title>"
When this URL is visited, the x parameter carries a script fragment that the XSS Auditor recognises as reflected XSS, so the Auditor blocks the page. The block only happens if the first result of the search for q=<title> actually has the title <title>, because only then does the page contain the matching reflected string. If the first result has a different title, the page loads normally.
The second observation is the side channel that makes the block observable cross-origin. When the XSS Auditor blocks the page, window.length stays 0, meaning no iframes are embedded. Google normally inserts many frames into its pages, so window.length is usually greater than 0. Reading window.length on a cross-origin window reference is permitted, so the attacker can distinguish the blocked state from the normal state. The author notes that other error-page detection channels exist and points to the xsleaks wiki's Browser-Side-Channels page, on which he is a collaborator.
The remaining limitation was that the attacker had to know the victim's <uid>, which narrowed the attack considerably. Looking at the uid= parameter produced the following behaviours:
https://books.google.com/books?uid=vulnerabilityinfinitely redirects to itself.https://books.google.com/books?uid=%2Bredirects tohttps://books.google.com/books?uid=<uid>&hl=en.https://books.google.com/books?uid=%2B1throws a 404 response.https://books.google.com/books?uid=1%2B1redirects tohttps://books.google.com/books?uid=<uid>&hl=en.https://books.google.com/books?uid='&q=hackredirects tohttps://www.google.com/search?tbo=p&tbm=bks&q=hack.https://books.google.com/books?uid=vulnerability&q=hackdisplays results for the logged-in user without changing the URL. This one was fixed.
The last entry is the key: a crafted uid combined with a q parameter makes the page render the logged-in user's results while the URL stays put. Combined with the XSS Auditor abuse, this lets the attacker run the cross-site search against the victim's account without knowing the <uid>.
Exploitation
Step 1: open a background window to the target
The victim visits a malicious page. On any interaction, the page opens a new window in the background pointing at books.google.com. The attacker keeps a reference to that window, manipulates its cross-origin location property and reads its window.length.
Step 2: drive the target through location
By manipulating the cross-origin location property of the opened window, the attacker navigates it to URLs built from the uid trick and the reflected x parameter. Each navigation is a fresh attempt at a conditional test.
Step 3: make the page conditional on a guess
The attacker supplies a candidate <title> in both q and the reflected x fragment, using the URL shape shown above. If the first result of the search has that title, the reflected script fragment is present in the page, the XSS Auditor blocks it, and window.length remains 0. Otherwise the page loads with its usual frames and window.length is greater than 0.
Step 4: read the result
After each navigation the attacker reads window.length on the window reference. A value of 0 means the guess was correct; a non-zero value means it was wrong. No response body is ever read.
Step 5: binary search
Multiple reflected parameters can be supplied in a single query, so the attacker can run a binary search algorithm to extract information efficiently rather than testing one candidate at a time. The author notes this is visible in the included video.
A proof of concept and a fuller description are in the original report submitted to Google, at https://terjanq.github.io/Bug-Bounty/Google/books-xs-search-enpgws9jw5mb/index.html.
Root cause
The page reflects the title of the first displayed search result into an inline script, so the rendered HTML depends on that result. That reflection is what the XSS Auditor reacts to when the attacker appends a matching fragment through a parameter, turning a private-data-dependent page into a block-or-not oracle. The uid handling then removes the need to know the victim's identifier: a crafted uid together with q renders the logged-in user's results without a URL change, so the attacker can aim the oracle at the victim's own account. The cross-origin readable window.length supplies the observable difference between the blocked and normal states, because Google's pages normally embed frames and the Auditor's block page does not.
Impact
The exfiltrated data could include searched books, private book collections, purchased books and read books. The attack applies to signed-in Google Books users who visit an attacker-controlled page. The author notes the information could be used to embarrass, blackmail or threaten the victim, or to draw legal consequences, since a specific set of books can be banned in some countries.
Fix
Google fixed the uid behaviour that displayed the logged-in user's results without changing the URL; the report marks that entry in the list as fixed. The timeline records the fix on Mar 5, 2019. More broadly, Google responded to the wave of cross-site search research by implementing a chain of defences against these attacks. As a consequence, new XS-Search reports are no longer rewarded and are treated as duplicates unless they significantly change Google's understanding of its defences and mitigations. Google said it would list web applications and endpoints it believes are properly protected against XS-Search, and would issue Vulnerability Research Grants to audit the effectiveness of those defences, while discouraging hunters from spending much time in the area to avoid duplication of effort.
Variants to test
- Reflected first-result metadata. Search a target that echoes the title, author or identifier of the first result into the page. A positive result is a page whose HTML differs depending on whether a guessed string is the first result, observable through a cross-origin side channel.
- Auditor-based block oracle. Append a script fragment as an extra parameter that matches the reflected value. A positive result is that the page is blocked only when the guess is correct, with
window.lengthstaying0on the block page while normal pages carry frames. - Identifier parameters that fall back to the session. Try crafted values of a user identifier parameter combined with a query parameter. A positive result is a page that renders the logged-in user's data while the URL stays unchanged.
- Other error-page channels. Where
window.lengthis not usable, test the other browser-side channels catalogued in the xsleaks wiki. A positive result is any cross-origin readable signal that reliably separates the blocked or error state from the normal state. - Multiple reflected parameters. Supply several reflected parameters in one query to test many candidates per navigation. A positive result is a correct binary-search extraction of a private string in far fewer navigations than a linear scan.
Timeline
- Jan 27, 2019 11:00PM: reported
- Jan 28, 2019 10:16AM: triaged
- Jan 30, 2019 02:18AM: accepted
- Feb 5, 2019 06:20PM: awarded $500
- Mar 5, 2019 10:47PM: fixed
- Mar 19, 2019 06:20PM: awarded an additional $837, totalling $1337
What happened, in plain words
Google Books is a website where you can search for books and keep a personal library: the books you have bought, the books you have read, the collections you have put them in, and the things you have searched for. All of that is private to your Google account.
This report describes a way for a malicious website to find out what is in that private library, without ever logging in as you and without reading any of your data directly. The trick is to make your own browser ask Google Books a series of yes/no questions about you, and to watch a tiny detail of the browser window to learn the answer. This kind of attack is called a cross-site search attack, or XS-Search: "cross-site" because the attacker's page lives on a different website from Google Books, and "search" because the attacker is effectively searching your private data one guess at a time.
The author borrowed the idea from a challenge called Filemanager that was part of a hacking competition, 35c3ctf. That challenge abused a feature built into the Chromium browser (the engine behind Chrome) called the XSS Auditor. The author says this write-up is the first of several showing a successful cross-site search, here against books.google.com.

The video shows the proof of concept in action.
The pieces you need to understand first
Before the details make sense, here are the basic ideas, from zero.
A website and its origin. Every page on the web has an address, and the browser groups addresses by "origin": the combination of protocol (http or https), host name (like books.google.com) and port. Pages from one origin are allowed to read each other's contents; pages from different origins are not. This rule is called the same-origin policy, and it is the main wall that protects your data from other websites.
A window reference. When one page opens another window (for example with window.open), it gets a handle to that window. The handle lets it do a few things to the other window even though it is a different origin, such as navigate it to a new address. It cannot read the other window's page content.
window.length. Every window object has a property called length. It counts how many frames (embedded sub-pages, called iframes) are inside that window. Crucially, this number can be read across origins: a page can open a window to another site and read window.length on it, even though it cannot read anything else. That small leak is the heart of this attack.
The XSS Auditor. Older Chromium browsers shipped with a defence called the XSS Auditor. Its job was to spot a particular kind of attack, cross-site scripting (XSS), where an attacker slips a script into a page through a URL parameter so the page runs it. When the Auditor thought it saw such a reflected script, it blocked the page instead of showing it. When the Auditor blocks the page, window.length stays 0, while Google's normal pages usually embed frames.
Reflected input. When a website takes something from the URL (a search term, for example) and writes it back into the page it sends you, that value is said to be reflected. If the site reflects a value the attacker controls, and the value looks like a script, the Auditor may step in.
A side channel. A side channel is any indirect signal that reveals something you are not supposed to know. You are not reading the secret itself; you are reading a side effect. Here the side effect is whether a page was blocked or not, observed through window.length.
A user identifier, <uid>. Google gives each account an identifier, written <uid> in this report. It is not your password; it is more like an account number. If an attacker knows it, they can aim requests at your account specifically.
Binary search. If you want to find a word among many possibilities, you can test them one by one, or you can split the possibilities in half and ask "is it in this half?", then split again, and so on. Each question halves the remaining options, so you find the answer in very few questions. That is binary search, and it is why this attack can be fast.
Finding it
While looking at the source code of the Google Books page, the author noticed a difference between two kinds of page. When a search returns at least one book, the page contains a particular block of JavaScript. When the search returns nothing, that block is missing. The inserted code starts like this:
<script>if (window['_OC_registerHover']){_OC_registerHover({"title":"<title>"
Line by line, in plain words:
<script>opens a script block, so the browser will treat what follows as code.if (window['_OC_registerHover'])checks whether a function called_OC_registerHoverexists on the page. If it does not, nothing inside the braces runs.{_OC_registerHover({"title":"<title>"calls that function and passes it an object with atitlefield. The value of that field is<title>, which in the report stands for the title of the first book in the search results.
The important part is what gets reflected. The page does not echo back the search term you typed. It echoes back the title of the first displayed result. That means the HTML of the page depends on private data.
That gives the attacker a yes/no test. For a chosen book title <title> and a known user identifier <uid>, the author could build a URL like this:
https://books.google.com/books?uid=<uid>&num=1&q=<title>&x=<script>if (window['_OC_registerHover']){_OC_registerHover({"title":"<title>"
What each part does:
https://books.google.com/booksis the Google Books page.uid=<uid>tells the site which user's library to look at.num=1asks for one result.q=<title>is the search query: search for this book title.x=is an extra parameter the page does not really need. The attacker fills it with a script fragment that matches the reflected title.
When this URL is opened, the x parameter carries a piece of script that the XSS Auditor recognises as reflected XSS, so the Auditor blocks the page. But the block only happens if the first result of the search for q=<title> really has the title <title>. Only then does the page contain the matching reflected string for the Auditor to notice. If the first result has a different title, the page loads normally.
So the attacker has turned a private fact ("is this the first book in your results?") into a public event ("was the page blocked?").
The second observation is how to see that event from another website. When the XSS Auditor blocks the page, window.length stays 0, because the block page has no iframes. Google's normal pages insert many frames, so on a normal page window.length is usually greater than 0. Since window.length can be read across origins, the attacker can tell the blocked state from the normal state. The author notes that other ways to detect an error page exist, and points to the Browser-Side-Channels page of the xsleaks wiki, where he is a collaborator.
There was still a big limitation: the attacker had to know the victim's <uid>, which made the attack much narrower. So the author looked more closely at the uid= parameter and found these behaviours:
https://books.google.com/books?uid=vulnerabilityinfinitely redirects to itself.https://books.google.com/books?uid=%2Bredirects tohttps://books.google.com/books?uid=<uid>&hl=en.https://books.google.com/books?uid=%2B1throws a 404 response.https://books.google.com/books?uid=1%2B1redirects tohttps://books.google.com/books?uid=<uid>&hl=en.https://books.google.com/books?uid='&q=hackredirects tohttps://www.google.com/search?tbo=p&tbm=bks&q=hack.https://books.google.com/books?uid=vulnerability&q=hackdisplays results for the logged-in user without changing the URL. This one was fixed.
A few words on the symbols: %2B is how a plus sign (+) is written inside a URL, and %27 is how a single quote (') is written. A redirect is when the server answers "not here, go to this other address instead". A 404 is the standard "not found" answer.
The last entry is the key. A crafted uid combined with a q parameter makes the page show the logged-in user's results while the address bar stays the same. Combined with the XSS Auditor trick, this lets the attacker run the cross-site search against the victim's account without knowing the <uid>.
Exploitation
Step 1: open a background window to the target
The victim visits a malicious page. On any interaction, that page opens a new window in the background pointing at books.google.com. The attacker keeps a reference to that window, which lets it manipulate the window's cross-origin location and read window.length.
Why this step: the attacker needs a live Google Books window that belongs to the victim's browser session, so that Google sees the victim's login. Opening it in the background means the victim may not notice.
Step 2: drive the target through location
By manipulating the cross-origin location property of the opened window, the attacker navigates it to URLs built from the uid trick and the reflected x parameter. Each navigation is a fresh attempt at a conditional test.
Why this step: the attacker cannot read the page, but it can tell the window where to go. Each new address is one question asked of Google Books.
Step 3: make the page conditional on a guess
The attacker supplies a candidate <title> in both q and the reflected x fragment, using the URL shape shown above. If the first result of the search has that title, the reflected script fragment is present in the page, the XSS Auditor blocks it, and window.length remains 0. Otherwise the page loads with its usual frames and window.length is greater than 0.
Why this step: this is the question itself. The page's behaviour now depends on whether the guess is right.
Step 4: read the result
After each navigation the attacker reads window.length on the window reference. A value of 0 means the guess was correct; a non-zero value means it was wrong. No response body is ever read.
Why this step: this is the answer. The attacker never sees your books; it only sees a number that happens to differ depending on whether the page was blocked.
Step 5: binary search
Multiple reflected parameters can be supplied in a single query, so the attacker can run a binary search algorithm to extract information efficiently rather than testing one candidate at a time. The author notes this is visible in the included video.
Why this step: testing one title at a time would be slow. Splitting the possibilities in half each time turns a long list of guesses into a short one.
A proof of concept and a fuller description are in the original report submitted to Google, at https://terjanq.github.io/Bug-Bounty/Google/books-xs-search-enpgws9jw5mb/index.html.
Root cause
The page reflects the title of the first search result into an inline script, so the rendered HTML depends on private library contents. That reflection is what the XSS Auditor reacts to when the attacker appends a matching fragment through a parameter, turning a private-data-dependent page into a block-or-not oracle. An oracle here just means something that answers yes/no questions.
The uid handling then removes the need to know the victim's identifier: a crafted uid together with q renders the logged-in user's results without a URL change, so the attacker can aim the oracle at the victim's own account.
The cross-origin readable window.length supplies the observable difference between the blocked and normal states, because Google's pages normally embed frames and the Auditor's block page does not.
Impact
The exfiltrated data could include searched books, private book collections, purchased books and read books. The attack applies to signed-in Google Books users who visit an attacker-controlled page. The author notes the information could be used to embarrass, blackmail or threaten the victim, or to draw legal consequences, since a specific set of books can be banned in some countries.
Fix
Google fixed the uid behaviour that displayed the logged-in user's results without changing the URL; the report marks that entry in the list as fixed. The timeline records the fix on Mar 5, 2019.
More broadly, Google responded to the wave of cross-site search research by implementing a chain of defences against these attacks. As a consequence, new XS-Search reports are no longer rewarded and are treated as duplicates unless they significantly change Google's understanding of its defences and mitigations. Google said it would list web applications and endpoints it believes are properly protected against XS-Search, and would issue Vulnerability Research Grants to audit the effectiveness of those defences, while discouraging hunters from spending much time in the area to avoid duplication of effort.
Variants to test
- Reflected first-result metadata. Search a target that echoes the title, author or identifier of the first result into the page. A positive result is a page whose HTML differs depending on whether a guessed string is the first result, observable through a cross-origin side channel.
- Auditor-based block oracle. Append a script fragment as an extra parameter that matches the reflected value. A positive result is that the page is blocked only when the guess is correct, with
window.lengthstaying0on the block page while normal pages carry frames. - Identifier parameters that fall back to the session. Try crafted values of a user identifier parameter combined with a query parameter. A positive result is a page that renders the logged-in user's data while the URL stays unchanged.
- Other error-page channels. Where
window.lengthis not usable, test the other browser-side channels catalogued in the xsleaks wiki. A positive result is any cross-origin readable signal that reliably separates the blocked or error state from the normal state. - Multiple reflected parameters. Supply several reflected parameters in one query to test many candidates per navigation. A positive result is a correct binary-search extraction of a private string in far fewer navigations than a linear scan.
Timeline
- Jan 27, 2019 11:00PM: reported
- Jan 28, 2019 10:16AM: triaged
- Jan 30, 2019 02:18AM: accepted
- Feb 5, 2019 06:20PM: awarded $500
- Mar 5, 2019 10:47PM: fixed
- Mar 19, 2019 06:20PM: awarded an additional $837, totalling $1337
Glossary
- API: a defined way for one piece of software to ask another for something, like a menu of requests a service accepts.
- Binary search: a way of finding an answer by repeatedly halving the set of possibilities, asking "is it in this half?" each time.
- Block page: the page a browser shows instead of the real page when a defence decides the page is dangerous.
- Chromium: the open-source browser engine that Chrome and several other browsers are built on.
- Cross-origin: belonging to a different origin (protocol, host and port) from the page you are on.
- Cross-site search (XS-Search): an attack that uses a victim's browser to ask a website yes/no questions about the victim's private data, one guess at a time.
- Cross-site scripting (XSS): an attack where a script is slipped into a page, often through a URL parameter, so the page runs it.
- Exfiltrate: to get data out of a protected place to somewhere the attacker can see it.
- Frame / iframe: a page embedded inside another page.
- HTML: the language that describes the structure and content of a web page.
- JavaScript: the programming language that runs in web pages and makes them interactive.
- Oracle: any behaviour that answers yes/no questions about a secret.
- Origin: the combination of protocol, host name and port that defines which pages may read each other.
- Parameter: a named value attached to a URL after a
?, such asq=hack. - Proof of concept (PoC): a working demonstration that an attack is possible.
- Redirect: a server answer telling the browser to go to a different address.
- Reflected input: a value from the request that the server writes back into the page it returns.
- Same-origin policy: the browser rule that pages from one origin may not read the contents of pages from another.
- Side channel: an indirect signal that leaks information without giving direct access to it.
- Triaged: the stage where a bug report is reviewed and confirmed as valid enough to investigate.
<uid>: a user identifier, an account number for a Google user, not a password.- URL: the address of a page or resource on the web.
- Vulnerability Research Grant: a payment Google offers to researchers to audit the effectiveness of its defences.
window.length: a property of a browser window that counts the frames inside it, readable across origins.- XSS Auditor: an older Chromium defence that blocked pages it believed contained reflected cross-site scripting.
- xsleaks: a community wiki cataloguing browser side channels, including ways to detect error pages.