Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Security Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel-native design: Leverages Laravel’s middleware stack, Blade directives, and service container, ensuring seamless integration with Laravel’s core architecture. The package’s reliance on Laravel’s HTTP kernel and middleware groups (web, global) aligns with Laravel’s request lifecycle.
  • Modular security layers: CSP, HSTS, SRI, and Permissions-Policy are decoupled, allowing granular configuration. This modularity reduces risk of over-restriction (e.g., disabling CSP while keeping HSTS).
  • Defense-in-depth: Combines multiple security mechanisms (e.g., CSP + SRI) to mitigate risks from single failures (e.g., CSP violations bypassed via SRI).
  • Vapor/Livewire/Filament optimizations: Explicit support for serverless (Vapor), real-time (Livewire), and admin panel (Filament) use cases, addressing common pain points in these ecosystems.

Integration Feasibility

  • Low-friction adoption: Auto-discoverable service provider, interactive setup wizard (php artisan security:install), and published config templates reduce manual configuration overhead.
  • Laravel 11–13 compatibility: Supports modern Laravel versions with PHP 8.2–8.5, ensuring compatibility with active projects.
  • Non-breaking defaults: Opt-in features (e.g., CSP_REPORT_ONLY) and sensible defaults (e.g., strict-dynamic CSP) minimize disruption during migration.
  • Asset pipeline agnostic: Works with Vite, Laravel Mix, and raw <script> tags, though Vite integration requires explicit useCspNonce() binding.

Technical Risk

  • CSP complexity: Strict CSP (strict-dynamic + nonces) requires careful testing, especially for third-party integrations (e.g., GTM, Stripe). Misconfiguration can break functionality.
  • SRI manifest management: Manual manifest updates (sri:build-manifest) or warm-up processes (sri:warm) add operational complexity, particularly in CI/CD pipelines.
  • Performance overhead: SRI middleware scans and rewrites HTML responses, which could impact high-traffic routes if not excluded via exclude_paths.
  • Reporting dependencies: Database persistence for CSP/SRI reports requires migrations and may introduce latency if not optimized (e.g., async logging).
  • Blade auto-injection risks: CSP_NONCE_AUTO_INJECT may inadvertently nonce user-generated content (e.g., {!! $comment !!}), requiring explicit opt-outs.

Key Questions

  1. Third-party compatibility:
    • How will the CSP nonces interact with existing third-party scripts (e.g., legacy JS libraries, iframes)?
    • Are there known conflicts with specific integrations (e.g., older versions of GTM, HubSpot)?
  2. CI/CD impact:
    • How will sri:build-manifest and sri:warm be integrated into the deploy pipeline? Will it block deploys if manifest generation fails?
    • How are hash mismatches (e.g., during rollbacks) handled in the SRI observer?
  3. Monitoring and observability:
    • What metrics/alerts are recommended for CSP/SRI violation rates? Are there thresholds for critical failures?
    • How are false positives in SRI reports (e.g., from data-sri-managed tags) mitigated?
  4. Performance trade-offs:
    • What is the measured overhead of SRI middleware on HTML responses? Are there benchmarks for large templates?
    • How does the package handle edge cases like dynamic asset paths (e.g., Livewire’s per-request JS)?
  5. Rollback strategy:
    • How can CSP/SRI be temporarily disabled during incidents (e.g., CSP_REPORT_ONLY fallback)?
    • Are there mechanisms to revert to a previous manifest version if a deploy introduces hash mismatches?

Integration Approach

Stack Fit

  • Laravel ecosystem: Ideal for Laravel 11–13 apps using Blade, Vite, Livewire, or Filament. Leverages Laravel’s middleware, Blade directives, and service container.
  • Serverless/Vapor: Optimized for Vapor with bootstrap/cache/ manifest storage and warm-up flows for post-deploy CSS processing.
  • Frontend tooling: Works with Vite (via useCspNonce()), Laravel Mix, and raw asset paths. SRI manifest generation supports both static (public/build/) and dynamic (/livewire/) assets.
  • Database: Optional persistence for CSP/SRI reports via csp_reports/sri_reports tables (requires migrations).

Migration Path

  1. Pre-migration:
    • Audit third-party integrations (e.g., GTM, Stripe) for CSP compatibility. Test nonced scripts in staging.
    • Identify asset paths excluded from SRI (e.g., Livewire, admin panels) via exclude_paths.
    • Back up existing CSP headers (if any) before running the wizard.
  2. Installation:
    • Run composer require make-dev/laravel-security.
    • Execute php artisan security:install to generate config/security.php with wizard-guided presets.
    • For custom setups, publish the config: php artisan vendor:publish --tag=make-dev-laravel-security.
  3. Configuration:
    • Configure CSP_ASSET_DOMAIN for CDN/asset hosts.
    • Set SRI_SCAN_DIRS to match asset build output (e.g., ['public/build']).
    • Bind Vite’s nonce: Vite::useCspNonce(app(\MakeDev\Security\Services\CspNonce::class)->value()).
  4. Manifest generation:
    • Build the SRI manifest in CI/CD: php artisan sri:build-manifest.
    • For Vapor/CSS warm-up: php artisan sri:warm post-deploy.
  5. Testing:
    • Validate CSP headers with SecurityHeaders.com or curl -I.
    • Test SRI integrity with php artisan sri:validate-manifest.
    • Monitor CSP/SRI reports in logs or database (if enabled).

Compatibility

  • Laravel versions: Confirmed compatibility with 11–13. May require adjustments for older versions (e.g., Blade directive syntax).
  • PHP versions: PHP 8.2–8.5 only (no 7.x support).
  • Frontend frameworks: Explicit support for Vite, Livewire, Filament. Works with raw Blade but requires manual nonce handling for {!! !!}.
  • CDNs/asset hosts: Supports multi-domain CSP/SRI via asset_domain config. Requires explicit allowlisting for SRI.
  • Third-party scripts: CSP nonces must be manually added to vendor scripts (e.g., @cspNonce in Blade). Wizard presets automate this for common integrations.

Sequencing

  1. Phase 1: CSP-only (low risk)
    • Enable CSP in report-only mode (CSP_REPORT_ONLY=true).
    • Monitor reports for violations, adjust directives, then switch to enforcement (CSP_REPORT_ONLY=false).
  2. Phase 2: SRI (moderate risk)
    • Build and validate the SRI manifest.
    • Enable SRI middleware and observer, monitor reports for hash mismatches.
  3. Phase 3: HSTS/Permissions-Policy (high impact)
    • Enable HSTS with a short max-age (e.g., 300s) for testing, then increase.
    • Tighten Permissions-Policy incrementally (e.g., deny geolocation first).

Operational Impact

Maintenance

  • Configuration drift: Centralized config/security.php reduces drift but requires version control for customizations.
  • Manifest updates: SRI manifests must be regenerated after asset builds. Automate with CI/CD hooks (e.g., post-build script).
  • Report management: CSP/SRI reports may require periodic cleanup (e.g., log rotation, DB archiving).
  • Dependency updates: Monitor for breaking changes in minor releases (e.g., CSP directive syntax).

Support

  • Debugging violations:
    • CSP reports: Use csp_reports table or log channel to identify blocked resources.
    • SRI failures: Check sri_reports for hash mismatches or observer errors.
  • Common issues:
    • Broken scripts: Missing @cspNonce on third-party tags or auto-injected nonces in user-generated content.
    • SRI manifest errors: Incorrect scan_dirs or skipped patterns (e.g., Livewire JS).
    • Performance: Exclude high-traffic routes from SRI middleware if rewrites are costly.
  • Tooling: Integrate with error tracking (e.g., Sentry) to alert on CSP/SRI failures.

Scaling

  • Performance:
    • SRI middleware: O(n) complexity per HTML response. Mitigate with exclude_paths for non-critical routes.
    • CSP nonces: Minimal overhead (per-request singleton).
    • Report endpoints: Rate-limited (throttle:) to prevent abuse.
  • Database scaling:
    • CSP/SRI reports: Consider async logging or a separate DB for high-volume apps.
    • SRI manifest: JSON
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky