CSP
Content Security Policy
An HTTP header that helps prevent XSS attacks by specifying which resources a page can load.
Technical Detail
CSP is delivered via the Content-Security-Policy HTTP header. Directives control resource sources: script-src (JavaScript), style-src (CSS), img-src (images), connect-src (XHR/fetch). The 'nonce-' source allows specific inline scripts with a cryptographic nonce. 'strict-dynamic' propagates trust to scripts loaded by trusted scripts. Report-only mode (Content-Security-Policy-Report-Only) logs violations without blocking, useful for gradual deployment. CSP is the strongest defense against XSS when configured to block all inline scripts.
Example
```javascript
// CSP: web API example
const response = await fetch('/api/resource');
const data = await response.json();
console.log(data);
```