kingsoft/csp-builder

Content Security Policy builder for PHP

1.1.0 2023-03-31 08:54 UTC

This package is auto-updated.

Last update: 2024-12-06 20:34:51 UTC


README

Generate a CSP header

Installation

This project using composer.

composer require kingsoft/csp-builder

Usage

<?php
use CSP\CspBuilder;

$csp = (new CspBuilder())
  ->addCspPolicy('script-src', CspBuilder::SELF)
  ->addCspPolicy('script-src', CspBuilder::NONCE)
  ->addCspPolicyNonce('script-src')
  ->setCspHeader();

define('NONCE', $csp-> getNonce());

<script nonce="<?= NONCE ?>">
</script>