Dress Code - Analysis of the current status of the Content Security Policy
Felipe Molina (Security Researcher, SensePost · Orange Cyberdefense)
AppSec Village @ DEF CON 31 · Day 2 · AppSec Village
Overview
In his talk "Dress Code - Analysis of the current status of the Content Security Policy" at AppSec Village @ DEF CON 31, Felipe Molina of Orange Cyberdefense's SensePost team presented a comprehensive analysis of Content Security Policy (CSP) adoption and effectiveness across the internet's top 1 million websites. Molina's research highlights a critical disconnect: despite CSP being a powerful defense against cross-site scripting (XSS) and other injection attacks, its implementation is alarmingly low and often misconfigured, leaving many applications vulnerable.

Key moments
- 0:29 The 'Big Red Button' and CSP's overlooked importance
- 4:56 Alarming low adoption: Only 10% of sites use CSP
- 8:50 Architecture for scanning 1 million sites for CSP policies
- 12:38 Pervasive CSP misconfigurations: Unsafe directives and orphan domains
- 21:50 Live demo: Exfiltrating data via Hotjar CSP bypass
- 25:20 Exploiting AWS Lambda/API Gateway for CSP bypass
- 27:50 Best practices: Strengthening CSP with SRI, nonces, and reporting
Dress Code - Analysis of the current status of the Content Security Policy
Speakers: Felipe Molina (Security Researcher, SensePost, Orange Cyberdefense)
Conference: AppSec Village @ DEF CON 31
YouTube: https://www.youtube.com/watch?v=9xTw_SKed-Q
Overview
In his talk "Dress Code - Analysis of the current status of the Content Security Policy" at AppSec Village @ DEF CON 31, Felipe Molina of Orange Cyberdefense's SensePost team presented a comprehensive analysis of Content Security Policy (CSP) adoption and effectiveness across the internet's top 1 million websites. Molina's research highlights a critical disconnect: despite CSP being a powerful defense against cross-site scripting (XSS) and other injection attacks, its implementation is alarmingly low and often misconfigured, leaving many applications vulnerable.
Molina frames the problem with a compelling analogy: if there were a "big red button" that could eliminate all SQL injection vulnerabilities, everyone would push it. He argues that CSP is akin to this button for XSS, yet the industry is largely failing to leverage its potential. The talk not only exposes the widespread poor state of CSP but also unveils several novel and lesser-known bypass techniques, demonstrating how even "strict" policies can be circumvented by determined attackers. This research provides invaluable insights for both developers striving to secure their applications and security professionals seeking to bypass common defenses.
Background
▶ Watch: The 'Big Red Button' and CSP's overlooked importance (0:29)
The motivation for Molina's deep dive into CSP stemmed from a personal experience during a web application assessment. He encountered a client who, rather than fixing underlying XSS vulnerabilities in their codebase, opted to implement a "very strict" CSP. As an attacker, Molina's instinct was to bypass this new defense, which he successfully did, effectively "resurrecting" the old XSS flaws and even leveraging them for a UI redressing attack to exfiltrate data. This experience sparked his curiosity about CSP's true efficacy and prevalence.
Content Security Policy (CSP) was conceived as early as 2004 by RSnake, with Mozilla implementing an early version in 2009. It was officially issued as a standard in 2012, and a working draft for Policy Level 3 is currently in development. Despite its decade-plus existence as a standard, Molina's research reveals that CSP remains a largely underutilized and misunderstood security mechanism. Its primary aim is to mitigate and detect injection attacks, particularly XSS and clickjacking, which can lead to severe consequences such as data defacement, malware distribution, and unauthorized data exfiltration. However, the complexity of its configuration and the operational overhead associated with maintaining strict policies often deter widespread and correct adoption, leading to the prevalent issues Molina's research uncovered.
Key Findings
▶ Watch: Architecture for scanning 1 million sites for CSP policies (8:50)
Molina's extensive scan of the top 1 million websites (sourced from Majestic Million and Cisco Umbrella) yielded several concerning key findings regarding CSP adoption and configuration:
- Low Adoption Rate: A striking only 10% of the scanned websites were found to be implementing any form of CSP. This figure underscores the industry's collective failure to adopt a fundamental layer of defense against injection attacks, akin to the "opposite of 9 out of 10 dentists recommending brushing your teeth" analogy.
- Misconfigured Policies: Even among the 10% that implemented CSP, configurations were frequently weak or flawed:
- Directive Usage: The most frequently used directives were
upgrade-insecure-requestsandframe-ancestors, both used by approximately 46% of CSP-enabled sites. While useful, these are often the easiest to implement and do not directly address script execution. script-srcNeglect: Crucially, only 20% of sites defining a CSP explicitly defined ascript-srcdirective, which controls what JavaScript can execute. This leaves a vast majority of CSP-enabled sites exposed to script injection attacks.- Dangerous
script-srcValues: Alarmingly, among those sites that did definescript-src, 20% allowedunsafe-inlineand 21% allowedunsafe-eval. These keywords effectively negate much of CSP's protection against XSS by permitting inline scripts andeval()-like functions, which are common XSS vectors. - Underutilized Critical Directives: Directives like
base-uriandreport-towere found to be rarely used.base-uriis critical for preventing base tag injection, a type of XSS that can redirect all relative script paths to an attacker-controlled domain.report-to(andreport-sample) provides invaluable real-time feedback on CSP violations, yet no sites were found using it. - Widespread Weaknesses: The analysis identified several common weaknesses:
- Third-Party Abuse: 9% of CSP-enabled sites were found to be vulnerable to abuse via broadly allowed third-party domains (e.g.,
*.hotjar.com). Attackers can leverage legitimate services hosted on these domains for data exfiltration or code execution. - Insecure Protocol Handling: 7% of sites allowed HTTP handles (e.g.,
https:was allowed, but implicitly or explicitly,http:was also permitted), potentially allowing insecure script loading. - Orphaned Domains: A significant finding was the presence of orphan domains within CSP directives. These are domains explicitly allowed in a CSP (e.g.,
script-src bosstoolspage.com) but are currently unregistered. An attacker could register such a domain and host malicious scripts on it, which the victim's browser would then execute due to the CSP's explicit allowance.
These findings paint a grim picture of CSP's current status, highlighting a clear need for greater awareness, better implementation practices, and continuous monitoring of policies.
Technical Deep Dive
▶ Watch: Pervasive CSP misconfigurations: Unsafe directives and orphan domains (12:38)
Molina's research methodology involved a sophisticated Big Data approach to analyze CSP across a vast number of websites. To achieve scalability and speed, he developed a custom scanner leveraging asynchronous programming paradigms. Instead of sequential requests, the scanner utilized Python's asyncio and aiohttp libraries to concurrently fetch HTTP headers from 1 million sites.
The collected data was managed using Pongo for the backend database, and pandas for efficient data manipulation and analysis. To visualize the findings and provide interactive exploration, a custom dashboard was built using Dash and plotly express, enabling users to filter, sort, and identify trends in CSP implementation and vulnerabilities.
The data collection and analysis process followed these steps:
- Header Collection: HTTP headers were collected from URLs sourced from Majestic Million and Cisco Umbrella.
- CSP Parsing: CSP headers were extracted and parsed into their constituent directives and values.
- Geolocation: Each site was assigned a country and continent based on its Top-Level Domain (TLD), IP address geolocation, and WHOIS records.
- Weakness Identification: The parsed CSPs were then analyzed against a set of rules to identify common weaknesses and potential bypass vectors.
A Content Security Policy is defined in an HTTP response header, typically Content-Security-Policy. It consists of a series of directives, each separated by a semicolon (;). Each directive has a name (e.g., script-src, connect-src, default-src) followed by one or more values, separated by spaces.
script-src: This directive specifies valid sources for JavaScript. Values can include'self'(allowing scripts from the same origin), specific domains (e.g.,example.com),'nonce-<base64-value>'(allowing scripts with a matchingnonceattribute),'sha256-<hash-value>'(allowing scripts matching a specific hash),'unsafe-inline'(allowing inline<script>blocks),'unsafe-eval'(allowingeval()and similar functions), and'strict-dynamic'(allowing scripts loaded by trusted scripts to load more scripts). The research found a concerning prevalence ofunsafe-inlineandunsafe-eval.connect-src: This directive restricts the URLs which can be loaded using script interfaces (e.g.,fetch,XMLHttpRequest,WebSocket,EventSource). Broad allowances here, such as*.hotjar.com, can be abused for data exfiltration.default-src: This acts as a fallback for any fetch directive that is not explicitly defined. Ifscript-srcis not defined,default-srcwill apply to scripts.base-uri: This directive restricts the URLs that can be used in a document's<base>element. Its neglect is dangerous, as an attacker could inject a<base>tag pointing to their domain, causing all relative URLs for scripts, images, and other resources to be fetched from the attacker's server.report-to: Specifies a reporting endpoint group for CSP violations. This is crucial for real-time monitoring and feedback, but was found to be almost universally absent.
The scanner's output, accessible via the dashboard, classified weaknesses such as "no CSP defined," "unsafe-inline," "unsafe-eval," "third-party abuse," and "orphan domains." Orphan domains are particularly insidious: if a CSP allows script-src example-cdn.com but example-cdn.com is unregistered, an attacker can register it, host malicious code, and the victim's browser will trust and execute it. Similarly, third-party abuse occurs when widely used services like Hotjar or Facebook are allowed with broad wildcards (e.g., *.hotjar.com). An attacker can then leverage the legitimate API endpoints of these services to exfiltrate data from the victim's browser, as demonstrated in Molina's proof of concepts.
Demo / Proof of Concept
▶ Watch: Exploiting AWS Lambda/API Gateway for CSP bypass (25:20)
To concretely demonstrate CSP bypasses, Molina set up a vulnerable lab environment. The lab included sensitive information like a "secret ingredient" (akin to a private key or sensitive data), user profiles with security questions and answers, and password change functionality. The objectives for the bypasses were clear: exfiltrate the security question and answer, exfiltrate the secret ingredient, and change the user's password.
Two primary XSS vulnerabilities were intentionally introduced into the lab application to serve as initial attack vectors:
- A reflected XSS vulnerability where a
msgURL parameter was directly embedded into a JavaScript block (e.g.,<script>alert('MSG');</script>). - A script injection vulnerability where a
sourceURL parameter was used as thesrcattribute of a dynamically appended script tag (e.g.,<script src="SOURCE"></script>).
Molina then demonstrated six bypasses, four of which were detailed:
- **Hotjar Abuse (
hotjar.com,hotjar.io):**
- Prevalence: Found on 250 sites (2% of CSP-enabled sites).
- Mechanism: If a CSP broadly allows
hotjar.comorhotjar.ioinconnect-src(ordefault-src), an attacker can create an account on Hotjar, set up a poll, and then sniff the legitimate traffic generated when submitting poll responses. The attacker then crafts a malicious JavaScript payload that, when executed via XSS in the victim's browser, mimics a Hotjar poll submission. Sensitive data (e.g., security question/answer) is injected into the "comment" field of this simulated poll response and sent to Hotjar's API endpoint. This data then appears in the attacker's Hotjar account dashboard. This attack typically requiresunsafe-inlineto execute the initial JavaScript payload.
- **Facebook Tracking Pixel Abuse (
facebook.com,facebook.net):**
- Prevalence: Found on 2,750 sites (2.6% of CSP-enabled sites).
- Mechanism: When a CSP allows
facebook.comorfacebook.net, an attacker can leverage Facebook's tracking pixel. By initializing the pixel with their own Facebook developer account ID and then creating a "fake custom event," sensitive data (e.g., the "secret ingredient") can be included within the event data. This data is then exfiltrated to the attacker's Facebook developer account dashboard, appearing as a custom event payload.
- **JSDelivr Code Execution (
*jsdelivr.net):**
- Prevalence: Found on 1,550 sites.
- Mechanism: If
*jsdelivr.netis allowed inscript-src(ordefault-src), an attacker can host malicious JavaScript code on a public platform like GitHub or npm. JSDelivr, a popular CDN, can then be used to cache and serve this code via a specific URL format (e.g.,cdn.jsdelivr.net/gh/username/repo/path/exploit.js). The attacker then exploits the script injection vulnerability (the second lab vulnerability) to load this JSDelivr-hosted malicious script into the victim's browser. Once executed, the script can perform actions like changing the user's password or exfiltrating data.
- **Amazon AWS API Gateway Exfiltration (
*aws.amazon.com):**
- Prevalence: Found on 550 sites.
- Mechanism: A CSP allowing
*aws.amazon.comcan be abused for data exfiltration. An attacker sets up an AWS Lambda function and an API Gateway endpoint. The Lambda function is configured to log any received data (after base64 decoding) to AWS CloudWatch logs. A malicious script injected into the victim's browser then makes a POST request to the attacker's API Gateway endpoint (which is a subdomain ofaws.amazon.com), sending sensitive data, base64 encoded, in the request body. The Lambda function processes this, and the attacker can retrieve the exfiltrated data from their CloudWatch logs.
Molina also briefly mentioned other bypasses for:
- Amazon CloudFront (
*cloudfront.com) - Azure Web Applications (
azurewebsites.net,azurestaticapps.net) - Heroku (
*herokuapp.com) - Firebase (
*firebaseapp.com)
These platforms can be similarly abused for code execution or data exfiltration if broadly allowed in a CSP, typically by opening an attacker account and hosting malicious content or leveraging legitimate API endpoints.
Defensive Implications
▶ Watch: Best practices: Strengthening CSP with SRI, nonces, and reporting (27:50)
Felipe Molina's research provides critical insights for defenders aiming to secure their web applications with CSP. The primary message is clear: implement CSP, and do so correctly.
- Push the Big Red Button: The most fundamental step is to adopt CSP. Its absence on 90% of sites leaves them entirely exposed to XSS and other injection attacks that CSP is designed to mitigate.
- Integrate with Subresource Integrity (SRI): CSP should not be used in isolation. Pairing it with Subresource Integrity (SRI) is crucial. SRI ensures that any third-party scripts loaded (e.g., from CDNs) have not been tampered with. If a third-party script is compromised, SRI will prevent its execution on your site, even if your CSP allows the domain.
- Eliminate
unsafe-inlineandunsafe-eval: These directives are antithetical to CSP's purpose. They reintroduce the very vulnerabilities CSP is meant to prevent. Defenders must refactor their code to avoid inline scripts andeval()functions. - Prefer Nonces and Hashes: Instead of
unsafe-inline, use cryptographic nonces or hashes forscript-srcandstyle-src. Nonces are randomly generated values added to the CSP header and to specific script tags, allowing only those scripts to execute. Hashes allow only scripts with a specific content hash to execute. - Understand
strict-dynamic: Whilestrict-dynamiccan simplify CSP management by allowing scripts loaded by trusted scripts to also load new scripts, it requires absolute trust in the initial trusted scripts. Any XSS in a script allowed bystrict-dynamiccan bypass the entire policy. - Minimize Third-Party Allowances: Reduce the number of external domains allowed in your CSP directives to the absolute minimum required. Each allowed third-party domain, especially with wildcards, introduces a potential bypass vector.
- Self-Host Libraries: Where possible, self-host third-party JavaScript libraries on your own domain instead of relying on external CDNs. This eliminates the need to poke holes in your CSP for external script sources and gives you full control over the script's integrity.
- Avoid Wildcards: Never use broad wildcards like
.amazon.comor.google.comin your CSP directives. This opens up vast attack surfaces, allowing attackers to leverage any subdomain of these services for exfiltration or code execution. Be as specific as possible with allowed domains. - Utilize
report-toandreport-sample: Implement CSP violation reporting using thereport-todirective. While it can be "noisy," it provides invaluable real-time feedback on CSP violations occurring in users' browsers, allowing defenders to identify and address issues promptly. - Consider Commercial Monitoring Solutions: For enhanced client-side security, consider commercial solutions that monitor JavaScript execution in real-time. These tools can detect anomalous script behavior, alert on unauthorized code execution, and provide an additional layer of defense against client-side attacks.
Key Takeaways
- CSP Adoption is Critically Low: Only 10% of the top 1 million websites implement Content Security Policy, leaving a vast majority vulnerable to injection attacks.
- Poor Configuration Undermines Protection: Even when implemented, CSPs are often misconfigured with dangerous directives like
unsafe-inlineandunsafe-eval, or by broadly allowing third-party domains, effectively negating their security benefits. - Common Services Can Be Hijacked: Widely used third-party services (e.g., Hotjar, Facebook, JSDelivr, AWS) can be leveraged for data exfiltration or code execution if broadly allowed in a CSP, demonstrating that "trusted" domains can become attack vectors.
- Orphaned Domains Pose a Unique Threat: Unregistered domains explicitly allowed in a CSP are a significant and often overlooked bypass vector, allowing attackers to register them and host malicious content.
- Defenders Must Be Proactive and Precise: Effective CSP implementation requires avoiding unsafe directives, using nonces/hashes, minimizing third-party allowances, self-hosting libraries, and utilizing reporting mechanisms (
report-to) for continuous monitoring. - CSP + SRI is the Standard: For robust client-side security, CSP should always be deployed in conjunction with Subresource Integrity (SRI) to protect against compromised third-party scripts.
About the Speaker(s)
Felipe Molina is a security professional with over 10 years of experience in the information security industry. He has been working with the Orange Cyberdefense SensePost team for more than four years. Molina is a self-proclaimed proud "F" and "Simpson" fan and can be found on Twitter for further discussion on security topics. His work focuses on practical security research and demonstrating real-world vulnerabilities and bypass techniques.
Reviews
Dr. Zero (Offensive Security Researcher) — STRONG ACCEPT
Molina scanned a million sites to prove what we already suspected: the internet's CSP implementation is mostly theater. He backs it up with a massive async data pipeline and weaponizes the exact marketing tools developers wildcard by default. It's a brutal reminder that trusting .facebook.com completely negates your mitigation.
Heather Calloway (CISO) — STRONG ACCEPT
Molina proves that Content Security Policy is not only rarely used, but routinely misconfigured to the point of uselessness. He demonstrates that broadly allowing third-party marketing and cloud services in CSP headers creates trivial data exfiltration pipelines. This is required reading for any AppSec leader who thinks checking the CSP box on an audit actually means their front-end is secure.