PHPackages                             flowpack/content-security-policy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. flowpack/content-security-policy

ActiveNeos-package[Security](/categories/security)

flowpack/content-security-policy
================================

Configure your content-security-policy header easily with yaml.

2.0.0(2mo ago)57.1k↓31.4%1MITPHPPHP ^8.1CI passing

Since Oct 21Pushed 2mo ago8 watchersCompare

[ Source](https://github.com/Flowpack/Flowpack.ContentSecurityPolicy)[ Packagist](https://packagist.org/packages/flowpack/content-security-policy)[ RSS](/packages/flowpack-content-security-policy/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (7)Dependencies (12)Versions (12)Used By (0)

Flowpack.ContentSecurityPolicy
==============================

[](#flowpackcontentsecuritypolicy)

- [Flowpack.ContentSecurityPolicy](#flowpackcontentsecuritypolicy)
    - [Introduction](#introduction)
    - [Usage](#usage)
    - [Custom directives and values](#custom-directives-and-values)
        - [Show CSP configuration](#show-csp-configuration)
    - [Throwing exceptions on configuration errors](#throwing-exceptions-on-configuration-errors)
    - [Disable or report only](#disable-or-report-only)
    - [Nonce](#nonce)
    - [Backend](#backend)
        - [Custom backend routes](#custom-backend-routes)
    - [Thank you](#thank-you)

Introduction
------------

[](#introduction)

Flow/Neos package to set your site's content security policy header easily with yaml.

Usage
-----

[](#usage)

Import the package using composer:

```
composer require flowpack/content-security-policy
```

The package is automatically active once imported. By default, the response header `Content-Security-Policy` will now be included.

It will use the default configuration which looks like this:

```
Flowpack:
  ContentSecurityPolicy:
    enabled: true
    report-only: false
    content-security-policy:
      default:
        base-uri:
          'self': true
        connect-src:
          'self': true
        default-src:
          'self': true
        form-action:
          'self': true
        img-src:
          'self': true
        media-src:
          'self': true
        frame-src:
          'self': true
        object-src:
          'self': true
        script-src:
          'self': true
        style-src:
          'self': true
        style-src-attr:
          'self': true
        style-src-elem:
          'self': true
        font-src:
          'self': true
      custom: [ ]
```

Now only resources from the same origin are allowed for the most common directives. It is enabled by default and the report-only mode is disabled.

Custom directives and values
----------------------------

[](#custom-directives-and-values)

If you want to override the default config don't forget to add this package as a dependency in the composer.json file of your package. Otherwise, it might not work because of the loading order of the packages.

The default configuration will probably not suit your needs so you can add your own configuration by adding the array custom like this in your own yaml configuration files:

```
Flowpack:
  ContentSecurityPolicy:
    content-security-policy:
      custom:
        frame-src:
          'https://www.youtube.com': true
          'https://staticxx.facebook.com': true
```

If you fully want to override the entire default config then just override the default key in yaml.

### Show CSP configuration

[](#show-csp-configuration)

To show the parsed configuration, the built-in command `./flow cspconfig:show` can be used. It shows all directives used by the frontend and the backend.

Throwing exceptions on configuration errors
-------------------------------------------

[](#throwing-exceptions-on-configuration-errors)

By default, in production, invalid directives are logged as critical errors and skipped so the rest of the policy is still applied. Also invalid custom backend routes are logged and ignored in production. In development, exceptions are throw instead, which surfaces misconfiguration immediately. You can change that behavior like this:

```
Flowpack:
  ContentSecurityPolicy:
    throw-exception-on-configuration-error: true
```

Disable or report only
----------------------

[](#disable-or-report-only)

To disable the header simply set `enabled` to false. If you want to add it as a report only header set `report-only` to true. That way you have the option to see the possible errors without breaking functionality.

Nonce
-----

[](#nonce)

You might want to use a nonce to allow inline scripts and styles to be still secure. To do this simply add `{nonce}` as an option in a directive. Like this:

```
Flowpack:
  ContentSecurityPolicy:
    content-security-policy:
      custom:
        script-src:
          '{nonce}': true
```

Now the header will include a `nonce-automatedgeneratedrandomstring` in the script-src directive. So inline scripts without the corresponding nonce will be blocked.

The nonce will be automatically added to all your script/style tags.

Backend
-------

[](#backend)

Due to the current nature of the Neos backend being rendered a bit different then the frontend a separate policy is added for the backend. I currently have found no suitable way the add the nonce in the inline scripts in the Neos UI package. So the CSP for the backend looks like this:

```
Flowpack:
  ContentSecurityPolicy:
    content-security-policy:
      backend:
        base-uri:
          'self': true
        connect-src:
          'self': true
        default-src:
          'self': true
        form-action:
          'self': true
        img-src:
          'self': true
          'data:': true
        media-src:
          'self': true
        frame-src:
          'self': true
        object-src:
          'self': true
        script-src:
          'self': true
          'unsafe-inline': true
          'unsafe-eval': true
        style-src:
          'self': true
          'unsafe-inline': true
        style-src-attr:
          'self': true
          'unsafe-inline': true
        style-src-elem:
          'self': true
          'unsafe-inline': true
        font-src:
          'self': true
          'data:': true
      custom-backend: [ ]
```

Unsafe inline scripts and styles are allowed in the backend because otherwise the backend won't work.

Again you can add your own policies in the custom-backend array the same way as the custom array for the frontend.

### Custom backend routes

[](#custom-backend-routes)

By default, the backend policy is applied to all paths starting with `/neos`. If you have additional routes that require the same permissive policy (e.g. a custom admin UI at `/monocle`), add them to `custom-backend.matchUris`. Each entry is a PHP regex (without delimiters) matched against the request path.

```
Flowpack:
  ContentSecurityPolicy:
    policies:
      custom-backend:
        matchUris:
          - '^/monocle(/.*)?$'
```

The built-in `'^/neos'` pattern in `backend.matchUris` is unaffected, so the Neos backend continues to work without any changes. You only need to touch `backend.matchUris` if you want to replace the default `/neos` match entirely.

Thank you
---------

[](#thank-you)

This package originates from .

Thank you Lars Nieuwenhuizen for your work.

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance87

Actively maintained with recent releases

Popularity30

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~92 days

Recently: every ~113 days

Total

7

Last Release

65d ago

Major Versions

1.3.0 → 2.0.02026-04-30

### Community

Maintainers

![](https://www.gravatar.com/avatar/25d49a6af82b72d2764774a05c307808375016d7aeaaef3862472a6580ff38a7?d=identicon)[flowpack](/maintainers/flowpack)

---

Top Contributors

[![t-heuser](https://avatars.githubusercontent.com/u/53174153?v=4)](https://github.com/t-heuser "t-heuser (25 commits)")

---

Tags

content-security-policycspflowneosneoscms

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/flowpack-content-security-policy/health.svg)

```
[![Health](https://phpackages.com/badges/flowpack-content-security-policy/health.svg)](https://phpackages.com/packages/flowpack-content-security-policy)
```

###  Alternatives

[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k18.7M143](/packages/mews-purifier)[neos/neos

An open source Content Application Platform based on Flow. A set of core Content Management features is resting within a larger context that allows you to build a perfectly customized experience for your users.

1151.0M777](/packages/neos-neos)[neos/neos-development-collection

Neos packages in a joined repository for pull requests.

267103.9k1](/packages/neos-neos-development-collection)[neos/media

The Media package

101.2M53](/packages/neos-media)[wwwision/privateresources

A Flow package that allows for protecting persistent resources from unauthorized access

1138.6k2](/packages/wwwision-privateresources)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
