Content Security Policy

From user interface version 5.2 and on the Crossmarx application platform supports the use of a Content Security Policy (CSP). 

Sources

Please consult creditable sources to help you collect and define the CSP directives for your application. 

  1. https://www.w3.org/TR/CSP3/
  2. https://web.archive.org/web/20251011184003/https://www.w3.org/TR/CSP3/
  3. https://content-security-policy.com/
  4. https://web.archive.org/web/20251004112907/https://content-security-policy.com/

Disclaimer

Please be sure to do your own due diligence if you create a custom CSP. As a result of its function, resources might be blocked and become unavailable. Therefore, if you choose to set your own CSP headers, you do so at your own risk. Crossmarx isn’t responsible for any downtime, broken features, or other issues caused by your custom CSP setup. You’re fully responsible for testing and managing any CSP directives you add.

What Crossmarx offers

  1. The installation of a minimal CSP on your application's server, to serve default CSP directives. 
  2. The ability for you to add a custom CSP to each response.
  3. The ability for you to receive a cryptographically secure random nonce for each response from the engine.
    #set($nonce = $document.getCSPNonce())

CSP nonces

A CSP nonce is a randomly generated token that is used exactly one time in a CSP response header. 

The nonce can be attached to allowed inline<script> or <style> tags.

The browser will then only allow the use of scripts or styles that include the matching nonce.

This protects against cross-site scripting (XSS) attacks, because injected scripts won’t have the correct nonce and therefore won’t run.

CSP Hashes

If you compute the hash of a, for example, inline JavaScript code block, you can add the hash to the script-src directive to allow it to execute.

Pros of using a Nonce vs a Hash

  • When you change the content of the script or style block you don't need to change your nonce logic, but if you are using a hash you would need to recompute the hash whenever the script or style tag inner text changes.
  • The nonce must be different for each request and must therefore be generated dynamically, as well as generating the CSP header dynamically. Normally this may involve too much complex programming but the complicated parts have been done for you already by the Crossmarx engine. Be sure to use the nonce that is generated by the engine and include it in the appropriate directives.
  • Nonces may have better support than hashes in some old browsers, for example Internet Explorer.

Support

Pretty much all major, modern browsers support CSP. If you need support for specific directives or older browsers, please be sure to check accordingly. 

How to integrate 

In the blueprint settings a script can be defined that should print a valid CSP in the property 'CSP script'. This script is parsed every request. So the CSP you want to serve can be customized based on the sort of request.