CSP Builder
Create a Content Security Policy header without having to write every directive from scratch.
$_POST['default_src'] ?? "'self'", 'script-src' => $_POST['script_src'] ?? "'self'", 'style-src' => $_POST['style_src'] ?? "'self'", 'img-src' => $_POST['img_src'] ?? "'self' data:", 'font-src' => $_POST['font_src'] ?? "'self'", 'connect-src' => $_POST['connect_src'] ?? "'self'", 'frame-src' => $_POST['frame_src'] ?? "'self'", 'object-src' => $_POST['object_src'] ?? "'none'", 'base-uri' => $_POST['base_uri'] ?? "'self'", 'form-action' => $_POST['form_action'] ?? "'self'", 'frame-ancestors' => $_POST['frame_ancestors'] ?? "'self'" ]; $parts = []; foreach ($directives as $name => $value) { $value = trim((string)$value); if ($value !== '') { $parts[] = $name . ' ' . $value; } } $policy = implode('; ', $parts) . ';'; if (isset($_POST['nonce']) && $_POST['nonce'] === '1') { try { $nonce = base64_encode(random_bytes(16)); } catch (Throwable $e) { $nonce = ''; } } } ?>
Create a Content Security Policy header without having to write every directive from scratch.