tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.91k stars 248 forks source link

Nonce not being added to Ziggy script #537

Closed matthewknill closed 2 years ago

matthewknill commented 2 years ago

Ziggy version

0.8.0

Laravel version

8.83.5

Description

I am trying to add a nonce via Spatie's CSP Package, however, it doesn't seem to be added to the Ziggy script. I have tried the following to no avail:

@routes(false, csp_nonce())
@routes(null, csp_nonce())
@routes(nonce: csp_nonce()) {{-- actually results in an error --}}

All result in the following without the nonce:

<script type="text/javascript">

Ziggy call and context

// All

Ziggy configuration

// Don't have nonce so can't run

Route definition

Route::get('login', [AuthenticatedSessionController::class, 'create'])
    ->name('login')
    ->middleware('guest');

// And all other routes
bakerkretzmar commented 2 years ago

Support for passing in a CSP nonce was added in v0.9.3, those examples should all work after you update.

matthewknill commented 2 years ago

Ah my bad, I was using an outdated version. Cheers