jeffersongoncalves/laravel-amplitude
A Laravel package for integrating Amplitude analytics into your application, making it easy to configure credentials and send event tracking data from your app. A lightweight wrapper for wiring Amplitude into Laravel projects with minimal setup.
Architecture fit. The package renders <script> tags server-side from the Blade/render layer, so it sits directly in the path of any Content-Security-Policy the application enforces. Prior to 1.1.0 it was effectively incompatible with a nonce-based script-src policy: any app that dropped 'unsafe-inline' would have its package-emitted scripts silently blocked. This release closes that gap by having the package read Laravel's Vite CSP nonce and stamp it onto every script it renders. That is the architecturally correct integration point — the package consumes the framework's existing nonce mechanism rather than inventing a parallel one — and it moves the package from "blocked by strict CSP" to "compatible with strict CSP."
Integration feasibility. Low effort. The change is additive and, by the description, conditional: when no nonce is set the rendered output should be unchanged. For apps already using Vite's nonce API or laravel-security-headers, the nonce is presumably already available in the container, so adoption is a version bump plus verification. No config changes, no new dependencies, and no published-asset changes are implied — though that last point needs confirming (see below).
Technical risk. Low-to-moderate, concentrated in two areas rather than in the code change itself:
nonce attribute is a policy violation, not a cosmetic bug.There is also a smaller risk to test suites and downstream HTML assertions that match exact <script> markup; any snapshot or string-match test on rendered output will need updating.
Key questions. I would not sign off on a broad rollout without answers to these:
Vite::cspNonce() / the framework's csp_nonce() helper, a config value, or a custom resolver? This determines whether it works in apps that don't use Vite-served assets.Stack fit. Laravel with Blade templating, Vite for asset bundling, and a CSP layer (either laravel-security-headers or hand-rolled middleware). The release explicitly names Vite's nonce as the source of truth, so apps that have already migrated to Vite are the natural first adopters. Apps still on Laravel Mix or serving assets outside Vite will likely see no benefit until they migrate, since no nonce will be set in the container.
Migration path. This is a minor-version, additive change: patch-level upgrade, no code changes, no config migration, no data migration. The only conditional step is re-publishing views if the nonce logic lives in a published view and the consumer has customized it. Confirm this before upgrading rather than after.
Compatibility. Two axes to check:
'unsafe-inline', should see byte-identical output. Verify with a diff of rendered HTML in a non-nonce environment; that is the cheapest possible regression test.Sequencing. I would run this as a narrow, staged rollout rather than a fleet-wide bump:
Content-Security-Policy-Report-Only in staging and either no policy or 'unsafe-inline' in production.script-src 'nonce-…' without 'unsafe-inline' in production, one application at a time.unsafe-inline exceptions that existed solely to accommodate this package.Step 7 is the payoff and is worth tracking explicitly — retiring a CSP exception is a real security win and the main reason to prioritize this upgrade.
Maintenance. Low. The change is small and self-contained, and it tracks a framework-provided primitive rather than a bespoke mechanism, which means it should age well across Laravel upgrades. The maintenance obligation it creates is mostly documentation: consumers need to know that the package now participates in the nonce lifecycle and what that implies for caching.
Support. Expect a predictable cluster of tickets, and pre-empt them in release notes:
Each of these is diagnosable in minutes if CSP violation reporting is wired up, and near-impossible otherwise. Treat report collection as a prerequisite of the rollout, not an afterthought.
Scaling. The material consequence: per-response nonces make HTML uncacheable at the edge. Applications that currently serve cached HTML through a CDN will either lose that caching for pages containing package scripts or must isolate those pages. On high-traffic pages this is a genuine cost and latency consideration that belongs in the upgrade decision, not in the post-incident review. Apps with low HTML cache hit rates, or that already run per-request sessions on those pages, are unaffected.
Failure modes. Ranked by likelihood and blast radius:
Ramp-up. Modest. An engineer already comfortable with CSP and Vite's nonce API can complete staging validation in roughly half a day; the caching investigation in step 5 is the variable and can run to several days in organizations with a CDN. The enforcing-policy flip in production typically requires security or platform sign-off, so budget for review latency rather than engineering time. No training beyond a short note to on-call about the new failure signature — "widget missing, no app error" now means "check CSP reports."
Recommendation. Adopt. This is a security-enabling feature that removes a standing obstacle to a strict CSP, at near-zero integration cost and with backward-compatible behavior. Prioritize it for any application already running or planning a nonce-based policy; treat it as optional for applications with no CSP ambitions. Gate the production rollout on answers to the sourcing and caching questions above, and on CSP violation reporting being live before enforcement.
How can I help you explore Laravel packages today?