[Vuejs]-How to configure or disable Content Security Policy(CSP) in Nuxt 3 to render images?

1👍

0👍

If you set img-src to [] (empty array), you are allowing everything. You can also be specific and set it to ["'self'", 'data:', 'https://www.example.com']. Setting img-src to undefined (also a valid value) seems to give you the default settings, which are ["'self'", 'data:'].

Your nuxt.config.ts file could look like this:

export default defineNuxtConfig({
  modules: [
    'nuxt-security',
  ],
  security: {
    headers: {
      contentSecurityPolicy: {
        'img-src': ["'self'", 'data:', 'https://www.example.com'],
      },
    },
  },
})

A couple of gotchas:

  • This value works: 'https://www.example.com' and this does not: 'example.com'
  • This value works: "'self'" and this does not: 'self'

Leave a comment