Skip to content
XSS Write-up Advanced

Ambushed by AngularJS: a hidden CSP bypass in Piwik PRO

The Piwik PRO analytics debugger was built with AngularJS and loaded its scripts from a whole allow-listed domain, so AngularJS script gadgets could be used to run JavaScript despite the site's Content Security Policy. An attacker who already had an HTML injection on a site using Piwik PRO could escalate it to full cross-site scripting.

Gareth Heyes Follow

Published on portswigger.net

Any individual website component can undermine the security of the entire site, and analytics platforms are no exception. With this in mind, we decided to do a quick audit of Piwik PRO to make sure it was safe to deploy on portswigger.net.

Gareth Heyes (@garethheyes), on portswigger.net

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

Impact

An attacker who already had an HTML injection vulnerability on a site using Piwik PRO could use the AngularJS gadget to bypass CSP and escalate to cross-site scripting.

What the attacker needed

An HTML injection on the target site; site uses Piwik PRO with the old CSP

The fix

It was fixed by tightening the CSP to allow-list a specific JavaScript file instead of the whole domain and by using nonces for certain scripts.

How it was found

  1. Browse the site with DOM Invader and set the canary to a blank value to reveal all sinks, including a document.write call.
  2. Inspect the document.write call, find a debug flag, and add it to the URL to load the analytics debugger.
  3. Inspect the debugger in devtools and notice an ng-app attribute, showing AngularJS is in use.
  4. Consult the XSS cheat sheet for AngularJS CSP bypasses and enter one into the console.
  5. Observe that the injected iframe with AngularJS directives and an ng-focus event bypassed CSP completely.

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 Content Security Policy is a browser rule that only lets scripts from approved sources run, which limits damage from injected HTML. AngularJS is an old JavaScript library that reads special attributes in HTML and runs code from them, so those attributes act like a back door around the rule. Here the approved source was a whole domain, so the attacker could load AngularJS itself and use its attributes to run their own code.

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 Gareth Heyes

View all

15 more disclosed reports, best first.

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.