Skip to content
XSS Write-up Intermediate

Google Tag Manager Csp Vulnerable To Xss

A reflected cross-site scripting flaw in a query parameter can be combined with a weak Content Security Policy that trusts Google Tag Manager and allows inline scripts, letting an attacker load a malicious script from the trusted tag manager domain. This bypasses both the policy and a web application firewall, allowing theft of session cookies and account takeover.

Mark Puckett Follow

Published on infosecwriteups.com

Most teams I talk to assume that if they “have a CSP” and “Cloudflare is on,” then XSS is largely a solved problem for their web app. Unfortunately, Raxis’ Ryan Chaplin’s recent research on Google Tag Manager (GTM) — and the honorable mention from Google that came with it — shows how easy it is to turn that comfort…

Mark Puckett, on infosecwriteups.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

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

How it worked

Root cause

Likely the CSP relies on unsafe-inline or unsafe-eval and a broad host exemption for the tag manager, so any injection point can load attacker-controlled JavaScript from a domain the policy already trusts.

Impact

An attacker could steal session cookies to take over accounts, skim data on high-value pages, and update payloads from the tag manager interface, while the firewall and CSP stay quiet.

What the attacker needed

A reflected XSS injection point; CSP allows unsafe-inline or unsafe-eval; CSP trusts the tag manager domain; attacker controls a tag manager container

The fix

The policy should be changed to use a per-request nonce on first-party scripts together with strict-dynamic, so unsafe-inline and unsafe-eval are no longer needed while the tag manager still works.

How it was found

  1. Find a reflected XSS injection point in a query parameter on the target application.
  2. Confirm the CSP allows inline scripts and trusts the tag manager domain, and that the WAF blocks obvious payloads.
  3. Inject a small loader that creates a script element pointing at a tag manager container the attacker controls.
  4. The browser loads the attacker's script from the trusted domain, which then reads cookies and performs post-exploitation actions.

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 write-up has not been written yet. The Original tab links to the source.

A website can tell the browser which sources of JavaScript it is allowed to run; this rule set is called a Content Security Policy. If the site also has a spot where an attacker can slip their own code into a page, and the policy trusts a third-party script host plus inline code, the attacker can use that trusted host to deliver harmful code. The browser and the firewall see only a normal script from a well-known domain, so they do not stop it.

What is XSS?

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

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.