Releases: aubes/csp-bundle
Releases · aubes/csp-bundle
v2.0.0
Breaking changes
- PHP >= 8.2 required (was PHP 7.4+)
- Symfony ^6.4 | ^7.4 | ^8.0 required (was Symfony 5.4+)
CSPDirectiveandCSPSourceare now PHP backed enums inAubes\CSPBundle\Enum\(was classes with constants inAubes\CSPBundle\)CSPPolicymoved toAubes\CSPBundle\Model\CSPPolicy(wasAubes\CSPBundle\CSPPolicy)- Directive names in YAML config use underscores:
script_src(wasscript-src) ReportTo::render()removed, userenderReportTo()orrenderReportingEndpoints()- Nonces now use base64 encoding (was hex). If you were reading nonce values directly, update your code to expect base64
CSP::addGroup()now throwsInvalidArgumentExceptionif the group already existsReportControllerno longer acceptsLoggerInterface: it dispatches aCSPViolationEventinstead. If you injected or extended the controller, update accordingly
Added
- Presets: built-in
strict,permissive, andapipresets for common CSP configurations - PHP attributes:
#[CSPGroup('name')]and#[CSPDisabled]on controllers/methods - Twig block tags:
{% csp_script %}...{% end_csp_script %}and{% csp_style %}...{% end_csp_style %}for automatic nonce wrapping - Hash support:
csp_hash()Twig function for sha256/384/512 hash-based CSP - Audit command:
csp:checkinspects your configuration for 15 security pitfalls (missing directives, unsafe sources, wildcards, etc.) - Web Debug Toolbar: CSP panel in the Symfony profiler (requires
symfony/web-profiler-bundle) - Debug mode:
debug: trueforces all groups into report-only mode - Reporting-Endpoints header: modern reporting standard, alongside legacy
Report-Toviabackward_compatibilityoption - Worker mode:
CSPservice implementsResetInterfacefor FrankenPHP/RoadRunner - Violation events:
CSPViolationEventdispatched on each report, handle violations your way (log, Sentry, database, etc.) - Optional built-in logger:
report_loggerconfig registers a log listener for violations via Monolog - Multi-group nonce resolution: nonces in Twig templates are automatically added to all active groups of the current request
- Multi-group constraint: each request supports at most one enforcing group and one report-only group. Applying two groups of the same mode throws a
LogicException - CSP Level 3 directives:
script-src-attr,script-src-elem,style-src-attr,style-src-elem,worker-src,manifest-src,webrtc,require-trusted-types-for,trusted-types - CSP Level 3 sources:
strict-dynamic,unsafe-hashes,wasm-unsafe-eval,report-sample,inline-speculation-rules,trusted-types-eval CSP::getGroups()public method to access all registered policy groups- Conditional service registration: Twig extension and data collector are only registered when their dependencies are available
Fixed
image-srcdirective renamed to correctimg-srcReportControllervalidates Content-Type, body size (10KB max), JSON format, and JSON depth (max 10 levels)Reporting-Endpointsheader now correctly uses a single URL per endpoint name (per spec)
Changed
symfony/twig-bundleis now optional: install it explicitly if you use nonce/hash Twig helpers