skip to Main Content

This my error

I’m still a beginner in creating Laravel Livewire applications, how to make CSP allow livewire.js

When I don’t use Content Security Policy Livewire runs fine, after I use Content Security Policy with spatie livewire.js is blocked, what is the solution?

I have used several methods

@livewireStyles(['nonce' => csp_nonce() ])

and

@livewireScripts(['nonce' => csp_nonce() ])

but it still doesn’t work

2

Answers


  1. You may have added the nonces to livewire correctly, the problem seems to be that the livewire script itself is not allowed to run by the existing policy. You can do this by:

    • Adding a host source for the script. For you dev case, you could add 127.0.0.1:8000 to script-src.
    • Adding a hash of the script and ‘strict-dynamic’ to script-src. If the hash is static this should just be to calculate the hash. If it is dynamic you’ll need to dynamically calculate the hash value.
    Login or Signup to reply.
  2. use this code

    @livewireStyles(['nonce' => csp_nonce()])
    
    @livewireScripts(['nonce' => csp_nonce()])
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search