Conversation
Al2Klimov
reviewed
Mar 24, 2026
Al2Klimov
previously approved these changes
Mar 31, 2026
Al2Klimov
left a comment
Member
There was a problem hiding this comment.
Tested together with Icinga/icingaweb2#5477 (review).
Al2Klimov
reviewed
Apr 8, 2026
7c4331f to
12ae5c6
Compare
Al2Klimov
approved these changes
Jun 24, 2026
The `Csp` class provides an additive builder for CSP headers: directives and their expressions are accumulated via `add()`, with duplicates silently ignored. Expressions are validated against the CSP spec: URL host sources (with scheme, port, and path), wildcards (`*` and `*.subdomain`), keywords (`'self'`, `'none'`, `'unsafe-inline'`, etc.), nonces (`'nonce-<value>'`), hash sources (sha256/384/512), report hashes, sandbox unquoted keywords, and report-to endpoint names. Fetch directives fall back through their inheritance chain to `default-src` when queried via `getDirective()`, but `getRawDirective()` and `hasRawDirective()` skip inheritance. The first nonce encountered across all directives is exposed via `getNonce()`. `fromString()` parses an existing CSP header string back into a `Csp` instance, and `merge()` combines multiple `Csp` instances into one, deduplicating expressions and preserving the base nonce. Co-authored-by: Eric Lippmann <eric.lippmann@icinga.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a Csp class which represents the Content-Security-Policy header.
This new class can be used to manage the content security policy.
This class enforces
default-src 'self'as a baseline for a secure web application.The first nonce added to any directive is selected as THE nonce for the CSP.
Setting a nonce is not supported since a nonce could appear in any number of different directives.