PHPackages                             elgg/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. elgg/content-security-policy

AbandonedArchivedLibrary[Security](/categories/security)

elgg/content-security-policy
============================

An immutable content-security-policy (csp) object for PHP

v1.0.0(11y ago)054MITPHP

Since Mar 18Pushed 11y ago3 watchersCompare

[ Source](https://github.com/Elgg/content-security-policy)[ Packagist](https://packagist.org/packages/elgg/content-security-policy)[ RSS](/packages/elgg-content-security-policy/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Content Security Policy (CSP) support for PHP
=============================================

[](#content-security-policy-csp-support-for-php)

Installation:

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

```

Example usage:

```
use Elgg\ContentSecurityPolicy\Directive;
use Elgg\ContentSecurityPolicy\Header;
use Elgg\ContentSecurityPolicy\Policy;
use Elgg\ContentSecurityPolicy\Source;

$policy = new Policy();
$policy = $policy->withSource(Directive::DEFAULT_SRC(), Source::SELF)
            ->withSource(Directive::IMAGE_SRC(), Source::DATA);

header(Header::STANDARD . ": $policy");
// Sends "Content-Security-Policy: default-src 'self'; img-src data:"
```

By default, the policy blocks everything it possibly can. This is by design to ensure that your site only allows what you want to allow, not what someone else thinks is a reasonable default.

```
$policy = new Policy();
echo $policy; // default-src 'none'; sandbox
```

Features:

```
Elgg\ContentSecurityPolicy\Policy
 [x] Instances are immutable
 [x] Supports configuring all standard src directives
 [x] Can be stringified into standard csp format
 [x] The default policy value allows nothing

```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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

Unknown

Total

1

Last Release

4101d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/188221fa5ea70dd4d13af1d9b839cdaba0cfc56e68bfcb1bde115cc5cea06b17?d=identicon)[ewinslow](/maintainers/ewinslow)

![](https://www.gravatar.com/avatar/a4ac1d6abe137b2a78bd0527b3c1f085be51c6a8f70e2fd81fcd7fac3d8d59bf?d=identicon)[jeabakker](/maintainers/jeabakker)

---

Top Contributors

[![ewinslow](https://avatars.githubusercontent.com/u/356564?v=4)](https://github.com/ewinslow "ewinslow (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mews/purifier

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

2.0k18.0M133](/packages/mews-purifier)[netflie/whatsapp-cloud-api

The first PHP SDK to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

664500.1k5](/packages/netflie-whatsapp-cloud-api)[paragonie/ecc

PHP Elliptic Curve Cryptography library

24772.0k35](/packages/paragonie-ecc)[oxid-esales/graphql-base

OXID eSales GraphQL base module

24105.3k16](/packages/oxid-esales-graphql-base)[flowwow/cloudpayments-php-client

cloudpayments api client

2197.1k](/packages/flowwow-cloudpayments-php-client)[fof/recaptcha

Increase your forum's security with Google reCAPTCHA

1436.9k](/packages/fof-recaptcha)

PHPackages © 2026

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