make-dev/laravel-security
Drop-in security headers for Laravel 11–13: HSTS, CSP with per-request nonces and strict-dynamic, X-Content-Type-Options, Permissions-Policy, and Subresource Integrity. Includes CSP/SRI violation report endpoints, logging/db storage, and Vapor-friendly SRI manifests.
Installation
composer require make-dev/laravel-security
The package auto-discovers the service provider.
Run the interactive setup wizard
php artisan security:install
Follow prompts to configure CSP, HSTS, Permissions-Policy, and SRI based on your stack (e.g., GTM, Stripe, HubSpot). This generates config/security.php.
Build the SRI manifest (after asset compilation)
php artisan sri:build-manifest
Run migrations (if using DB persistence)
php artisan migrate
Enable strict CSP for a new Laravel 13 app with Vite + Filament:
php artisan security:install and select:
AppServiceProvider::boot():
Vite::useCspNonce(app(\MakeDev\Security\Services\CspNonce::class)->value());
<script @cspNonce src="https://www.googletagmanager.com/gtm.js?id=GTM-XXXX"></script>
CSP Integration
@cspNonce for inline scripts:
<script @cspNonce>console.log('Safe!');</script>
AppServiceProvider or Filament’s ->cspNonce().'exclude_paths' => ['admin', 'livewire'],
SRI for Assets
php artisan sri:build-manifest --skip-css # For Vapor CSS post-processing
php artisan sri:warm
'host_allowlist' => ['self', 'asset', 'https://cdn.example.com'],
Violation Reporting
'csp_report_db' => true,
'sri_report_db' => true,
'csp_report_uri' => 'https://your-reporting-service.com/csp',
Third-Party Integrations
'directives' => [
'script-src' => ['self', 'nonce-{NONCE}', 'https://www.googletagmanager.com'],
],
sri:warm for dynamic assets (e.g., Livewire JS).->cspNonce() in panel config.vite.config.js to generate SRI hashes:
export default defineConfig({
build: {
manifest: true,
outDir: 'public/build',
},
});
CSP_NONCE_AUTO_INJECT if rendering user-generated HTML with {!! !!}.SRI Manifest Mismatches
sri:warm for dynamic assets or exclude paths:
'skip_url_patterns' => ['/livewire/'],
CSP Nonce Leaks
{!! $comment !!}) can bypass CSP.CSP_NONCE_AUTO_INJECT and manually nonce trusted scripts.Double CSP Headers
'directives' => [
'script-src' => ['self', 'nonce-{NONCE}', 'https://fortify.net'],
],
SRI Observer Noise
host_allowlist; rely on CSP for them.CSP_REPORT_ONLY=true php artisan serve
sri_reports table or logs. Verify hashes with:
openssl dgst -sha384 -binary public/js/app.js | openssl base64 -A
SubresourceIntegrity middleware runs after web group (auto-handled by the package).Environment Variables
.env:
CSP_ASSET_DOMAIN=https://cdn.example.com
SRI_CACHE_STORE=redis
CSP_ASSET_DOMAIN=https://cdn1.example.com,https://cdn2.example.com
Path Exclusions
str_starts_with):
'exclude_paths' => ['api/', 'admin.*'], // Admin routes with regex
Permissions-Policy
'features' => [
'geolocation' => ['self'],
'camera' => ['none'], // Block entirely
],
Custom Directives
config/security.php:
'directives' => [
'frame-ancestors' => ['self'],
'form-action' => ['self'],
],
Report Processing
app/Providers/SecurityServiceProvider.php:
$this->app->bind(\MakeDev\Security\Services\CspReportHandler::class, function () {
return new CustomCspReportHandler();
});
Manifest Build
'hash_algorithm' => 'sha256', // Default is sha384
'scan_dirs' => ['public/js', 'public/css', 'vendor/alpinejs'],
Vapor-Specific
sri:warm with DynamoDB:
'cache_store' => env('AWS_DYNAMODB'),
How can I help you explore Laravel packages today?