Programatically change Content Security Policy (CSP) on specific page
Hello, I want to programatically add more links to CSP on one specific page and I need to fetch those links from DB.
I tried to use
useHead
composable on both said page and on middleware before navigating to it. In both cases it didn't work, even though I could see updated header if I inspected it.
So I assume there is some race condition that I didn't take into account.
Is there correct/better way to do it, or any advice what I can try to make it work?1 Reply
Hi!
useHead is for HTML HEAD tags: https://nuxt.com/docs/api/composables/use-head
What you need is to set response HEADERS.
This module helps with CSP Headers:
https://nuxt-security.vercel.app/documentation/headers/csp
I don't know if it allows to do it only at one specific page, but it is a good point to start finding a solution for your need
Nuxt
useHead · Nuxt Composables
useHead customizes the head properties of individual pages of your Nuxt app.
Content Security Policy
Enabled Prevent unwanted content from being injected in your app.