Frequently Asked Questions

Find answers for difficult questions.


Testing CORS configuration

In the default configuration for CORS in Nuxt Security module, only the request that is coming from your origin (the same host by default) will be accepted and others will be rejected.

To test it, run your application and then in another test application running on a different port, send a request to the first app. You will get the CORS error there.

ℹ Read more about it here.

Set Content-Security-Policy-Report-Only

The HTTP Content-Security-Policy-Report-Only response header allows web developers to experiment with policies by monitoring (but not enforcing) their effects. These violation reports consist of JSON documents sent via an HTTP POST request to the specified URI.

You can add it to your project like this:

// nuxt.config.tsrouteRules: {  '/**': {    headers: {      'Content-Security-Policy-Report-Only': '<YOUR_DESIRED_VALUE>'    },  },},
ℹ Read more about it here.

Conflicting headers with Firebase Auth

When working with Firebase Auth, and more specifically the signInWithPopup method, you would need to disabled the following headers that are set by Nuxt Security automatically:

// nuxt.config.tssecurity:{  headers: {    crossOriginOpenerPolicy: false,    crossOriginEmbedderPolicy: false,  }}
ℹ Read more about it here.

Allowing images and scripts from external domains

In several situations you will need to allow fetching images from external domains. Here is how you can do that:

// nuxt.config.tssecurity: {  headers: {    contentSecurityPolicy: {      'img-src': ['https://upload.wikimedia.org'], // <--- add the domain you want to fetch the image from here    }  }}

Next, you need to configure your img tag to include the crossorigin attribute:

<img  src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Cat_August_2010-4.jpg/272px-Cat_August_2010-4.jpg"  alt="Cat Image Here"  crossorigin/>
ℹ Read more about it here.

Using nonce with CSP for Nuxt Image

Having securely configured images is crucial for modern web applications. Check out how to do it below:

// nuxt.config.tssecurity: {  nonce: true,  headers: {    contentSecurityPolicy: {      'img-src': ["'self'", 'data:', 'https:'],      'style-src': ["'self'", "'nonce-{{nonce}}'"],      'script-src': [        "'self'", // backwards compatibility for older browsers that don't support strict-dynamic        "'nonce-{{nonce}}'",        "'strict-dynamic'"      ],      'script-src-attr': ["'self'", "'nonce-{{nonce}}'", "'strict-dynamic'"]    }  }}

And then configure NuxtImg like following:

<template>  <NuxtImg src="https://localhost:8000/api/image/xyz" :nonce="nonce" /></template><script lang="ts" setup>const nonce = useNonce()</script>
ℹ Read more about it here.

Issue on Firefox when using IFrame

When working with IFrames in Firefox you may encounter an issue NS_ERROR_FAILURE and to solve it, you would need to disable the following header that are set by Nuxt Security automatically:

// nuxt.config.tssecurity:{  headers: {    crossOriginOpenerPolicy: false,  }}
ℹ Read more about it here.