This trait is used to give a CSP header to the result for a single action.
The content security policy components, for compile time dependency injection.
CSP Configuration.
CSP Configuration.
true if the header should be Content-Security-Policy-Report-Only.
A function that decides based on the headers of the request if a check is needed.
the CSP nonce configuration
a list of CSP hashes that can be added to the header
the CSP directives configuration
Provider for Content Security Policy configuration.
Provider for Content Security Policy configuration.
This filter enables the Content-Security-Policy header in Play for all requests.
This filter enables the Content-Security-Policy header in Play for all requests.
Please see the documentation for more information.
CSP Hash Configuration.
CSP Hash Configuration.
the algorithm from https://www.w3.org/TR/CSP3/#grammardef-hash-algorithm
set to the hash value in configuration
the pattern in directives to substitute with hash.
The content security policy module.
CSP Nonce Configuration.
CSP Nonce Configuration.
if true, a nonce is generated in processing
the pattern in directives to substitute with nonce, DEFAULT_CSP_NONCE_PATTERN by default.
if true, renders HeaderNames.X_CONTENT_SECURITY_POLICY_NONCE_HEADER
This trait processes a request header for CSP related logic.
CSPReportAction exposes CSP content violations according to the CSP reporting spec
CSPReportAction exposes CSP content violations according to the CSP reporting spec
Be warned that Firefox and Chrome handle CSP reports very differently, and Firefox omits fields which are in the specification. As such, many fields are optional to ensure browser compatibility.
To use this in a controller, add something like the following:
class CSPReportController @Inject()(cc: ControllerComponents, cspReportAction: CSPReportActionBuilder) extends AbstractController(cc) { private val logger = org.slf4j.LoggerFactory.getLogger(getClass) private def logReport(report: ScalaCSPReport): Unit = { logger.warn(s"violated-directive: ${report.violatedDirective}, blocked = ${report.blockedUri}, policy = ${report.originalPolicy}") } val report: Action[ScalaCSPReport] = cspReportAction { request => logReport(request.body) Ok("{}").as(JSON) } }
A result processor that applies a CSPResult to a play request pipeline -- either an ActionBuilder or a Filter.
The default CSPActionBuilder.
The default CSPActionBuilder.
This is useful for runtime dependency injection.
The default CSP processor.
The default CSP processor. This handles processing of a CSP Nonce and hashes into a Content-Security-Policy series of directives, based off the CSPConfig.
If a request has the attribute RequestAttrKey.CSPNonce, then that nonce is used. Otherwise, a nonce is generated from 16 bytes of SecureRandom.
This trait is used by CSPActionBuilder and CSPFilter to apply the CSPResult to a Play HTTP result as headers.
This trait is used by CSPActionBuilder and CSPFilter to apply the CSPResult to a Play HTTP result as headers.
Appends as play.api.http.HeaderNames.CONTENT_SECURITY_POLICY
or
play.api.http.HeaderNames.CONTENT_SECURITY_POLICY_REPORT_ONLY
,
depending on config.reportOnly.
If cspResult.nonceHeader
is defined then
play.api.http.HeaderNames.X_CONTENT_SECURITY_POLICY_NONCE_HEADER
is set as an additional header.
Result of parsing a CSP report.
This singleton object contains factory methods for creating new CSPActionBuilders.
This singleton object contains factory methods for creating new CSPActionBuilders.
Useful in compile time dependency injection.
This singleton object contains factory methods to create a CSPConfig instance from configuration.
This trait is used to give a CSP header to the result for a single action.
To use this in a controller, add something like the following: