100% Clientseitige Berechnung • Keine Server-Logs • Sofortige Ausführung
Curious TechieEntwickler-Toolbox
Security & AuthenticationW3C Content Security Policy Level 3✓ Schnellübersichtstabelle (8 Einträge) • DE

Content-Security-Policy (CSP) Direktiven Referenz

W3C CSP Level 3: XSS-Schutz, Nonces, Hashes und Quellregeln

CT
Curious-Techie Engineering TeamVerifizierter Autor

Web Protocols & Security Architecture Research

Veröffentlicht:
•
Aktualisiert:
•8 min read
Maßgebliche Spezifikation:RFC 9110(IETF)
Geprüft von Curious-Techie Architecture Peer Review Group

Übersicht & Anwendungsbereich

Der W3C CSP Level 3-Standard dient als primäre Verteidigungslinie gegen Cross-Site Scripting (XSS) und Data-Injection-Angriffe.

Spezifikationstabelle & Matrix

Echtzeit-Filter nach Stichwort, Statuscode oder Direktive

Schlüssel / CodeDefinition & DetailsSemantische GEO-HierarchieSpezifikation & Hinweise
default-src
default-src

Serves as a fallback for all standard fetch directives if they are not explicitly declared.

default-src 'self'
●default-src
↳CSP directive
↳fetch directive
↳universal fallback policy
W3C CSP3 §6.6.1

Does NOT cover frame-ancestors, base-uri, or form-action; those must be set individually.

script-src
script-src

Restricts valid sources for JavaScript execution, web workers, and script elements.

script-src 'self' 'nonce-rAnd0m' https://trusted.cdn.com
●script-src
↳CSP directive
↳fetch directive
↳JavaScript execution boundary
W3C CSP3 §6.6.2

By default, disallows inline <script> tags and eval() unless unsafe-inline or nonces are present.

style-src
style-src

Restricts valid sources for stylesheets, <style> blocks, and link rel="stylesheet".

style-src 'self' https://fonts.googleapis.com
●style-src
↳CSP directive
↳fetch directive
↳CSS stylesheet restrictions
W3C CSP3 §6.6.3

Inline style attributes require 'unsafe-inline' or style-src-attr in CSP3.

connect-src
connect-src

Restricts URLs that can be loaded using script interfaces (fetch, XMLHttpRequest, WebSocket, EventSource).

connect-src 'self' https://api.example.com wss://ws.example.com
●connect-src
↳CSP directive
↳fetch directive
↳network API fetch restriction
W3C CSP3 §6.6.5

Prevents compromised scripts from exfiltrating stolen session data to arbitrary attacker servers.

frame-ancestors
frame-ancestors

Specifies valid parents that may embed a page using <frame>, <iframe>, <object>, or <embed>.

frame-ancestors 'none' (or 'self')
●frame-ancestors
↳CSP directive
↳document directive
↳clickjacking defense
W3C CSP3 §6.7.1

Modern replacement for X-Frame-Options; does NOT fallback to default-src.

object-src
object-src

Restricts valid sources for the <object>, <embed>, and <applet> elements.

object-src 'none'
●object-src
↳CSP directive
↳fetch directive
↳legacy plugin blocking
W3C CSP3 §6.6.7

Should ALWAYS be set to 'none' in modern web development to prevent Flash and Java applet exploits.

base-uri
base-uri

Restricts the URLs that can be used in a document’s <base> element.

base-uri 'self'
●base-uri
↳CSP directive
↳document directive
↳base tag hijack prevention
W3C CSP3 §6.7.2

Prevents attackers from injecting <base href='https://evil.com'> to redirect relative script imports.

upgrade-insecure-requests
upgrade-insecure-requests

Instructs user agents to rewrite all insecure HTTP URLs to secure HTTPS URLs before requesting them.

upgrade-insecure-requests;
●upgrade-insecure-requests
↳CSP directive
↳transport policy
↳automatic HTTPS rewriting
W3C CSP3 §6.8.2

Instantly eliminates mixed content warnings on newly migrated HTTPS domains.

Technisches Beispiel & Code

Strict Nonce-Based CSP Policy Template

textCode kopieren
Content-Security-Policy:
  default-src 'self';
  script-src 'self' 'nonce-EDNnf03nceEc1hgq' 'strict-dynamic';
  style-src 'self' 'nonce-EDNnf03nceEc1hgq';
  img-src 'self' data: https:;
  font-src 'self' https://fonts.gstatic.com;
  connect-src 'self' https://api.example.com;
  object-src 'none';
  base-uri 'self';
  frame-ancestors 'none';
  upgrade-insecure-requests;

A modern strict policy using nonces and strict-dynamic provides maximum XSS defense while allowing legitimate dynamic script loading.

Häufig gestellte Fragen (FAQ)

Standard-Spezifikation Q&A

Why does my inline script fail even with default-src "self"?↓
"self" only permits external scripts loaded from the same origin (e.g. <script src="/app.js">). Inline scripts (<script>alert(1)</script>) are blocked unless an explicit cryptographic nonce or hash is provided.
Authoritative Sourcing & Verification

References & Primary Sources

Every source below directly substantiates technical statements and protocol behaviors explained in Content-Security-Policy (CSP) Direktiven Referenz. Curious-Techie prioritizes official Internet standards (IETF RFCs, W3C Recommendations, WHATWG specifications) and established security bodies (OWASP, NIST). Zero sponsored or secondary links.

  1. [1]W3CPrimary SpecificationW3C CSP Level 3 • Section 2 & 3
    Verified Primary Source
    Technical Claim Supported:

    Normative specification for Content-Security-Policy HTTP headers, directive fallback inheritance from default-src, and cryptographic nonce/hash-based script execution.

    “A server can specify a policy for a resource that the user agent will enforce, restricting the execution of scripts, stylesheets, and embedded frames.”
  2. [2]OWASPAuthoritative Security StandardOWASP Cheat Sheet Series • Strict CSP & XSS Mitigation
    Verified Primary Source
    Technical Claim Supported:

    Authoritative security guide for strict CSP deployment using per-request cryptographic nonces and strict-dynamic to neutralize Reflected and Stored XSS.

  3. [3]MDNDeveloper Authority (MDN)MDN Web Docs • CSP Directives Reference
    Verified Primary Source
    Technical Claim Supported:

    Reference documentation for browser implementation of CSP directives including script-src, frame-ancestors, object-src, and report-to.