Hardening XP with Security Headers and Content Security Policy
Secure your Enonic applications by using HTTP security headers and a strong Content Security Policy (CSP).
Written by Vegard Ottervig on
Secure your Enonic applications by using HTTP security headers and a strong Content Security Policy (CSP).
Written by Vegard Ottervig on
At a recent Enonic Meetup, Vigdis—Tech Lead and Web Developer at Bouvet—shared how to improve the security posture of Enonic applications by configuring security headers, with a deep dive into the Content Security Policy (CSP).
Drawing on nearly seven years of experience working with Enonic solutions across multiple clients, Vigdis offered a practical, code-oriented walkthrough aimed at developers and teams looking to enforce modern browser-side protections.
See the presentation:
Security headers are a powerful and often underused way to protect web applications from common vulnerabilities like cross-site scripting (XSS), clickjacking, and man-in-the-middle attacks.
By instructing browsers how to handle content, frames, MIME types, and external scripts, headers serve as a defensive layer in your web stack.
Among the most relevant headers are:
The core of Vigdis’ presentation focused on CSP. Unlike simpler headers, CSP gives developers fine-grained control over which resources are allowed, including scripts, images, styles, and frames.
By default, CSP should be as restrictive as possible. Vigdis demonstrated starting with default-src 'none'
, which blocks everything, and then selectively allowing only trusted sources for:
script-src
, style-src
, and img-src
(typically set to 'self'
)frame-src
for allowing embeds from platforms like YouTube, X, or Instagramunsafe-inline
Vigdis explained how different scenarios call for different strategies. Static inline scripts can be whitelisted using a hash, while dynamic or user-configured content should use a nonce. This is a random value generated per request that gets attached to both the script and the header.
Using the Security Headers app in Enonic XP, Vigdis walked through setting up common headers via a simple admin interface.
For Enonic Cloud deployments, some headers—like Strict-Transport-Security
—should be configured at the platform level to avoid duplication.
The app allows direct configuration of CSP rules, and Vigdis showcased a custom example with support for generating and injecting nonces via Java-based response processors.
She also demonstrated how to manually calculate a hash for a script and apply it via the app—highlighting the importance of byte-perfect matching (even extra spaces or newlines will change the hash).
Preview mode in Enonic doesn't enforce CSP, which makes it easier to troubleshoot configuration changes before going live.
Chrome's built-in developer tools help identify blocked resources and offer suggestions for hashes or sources to allow.
To close, Vigdis shared some best practices:
unsafe-inline
—use hashes for static scripts, and nonces for dynamic ones.Security might not always be the most glamorous part of development—but as Vigdis showed, with the right tools and a bit of planning, it can be both effective and manageable within the Enonic platform.
Want to strengthen your Enonic solution with CSP and other headers? Check out the Security Headers app or talk to your team about implementing these best practices today.
Get some more insights 🤓