Security middleware does not work on prod but does work on dev
Hey!
I just implemented the security module from Nuxt3 (https://nuxt-security.vercel.app/?utm_source=nuxt.com&utm_medium=aside-module&utm_campaign=nuxt.com). However, I encountered an issue where some features don't seem to work in my production (Netlify) environment. I tested it in my development environment, and there, it works fine. Not sure if it has something to do with ssr or Netlify.
I am facing the following issues (config in a seperate comment):
- In CORS, the access-control-allow-origin header includes my same-origin but also adds a * wildcard. My Nuxt configuration is provided in a separate comment below.
- For XSS protection, it should be enabled by default in Nuxt3. On my development environment, it correctly throws an error when I add
?test=<script>alert(1)</script>
, but this does not happen in my production environment.Nuxt Security
Nuxt Security
Automatically configure your app to follow OWASP security patterns and principles by using HTTP Headers and Middleware.

7 Replies
Hi @[PATH] Luckɣsեriike (Orin). I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided in the knowledge sources, I don't have enough specific details to fully address your issue with the Nuxt security module in production. However, I can provide some general insights and suggestions based on related information:
1. CORS Configuration:
The CORS issue you're experiencing might be related to how the security module interacts with your production environment. It's possible that there are conflicting configurations or that the production server is overriding some settings.
2. XSS Protection:
Regarding XSS protection, Nuxt 3 indeed has some built-in protections. However, the behavior difference between development and production environments could be due to various factors, including how the security module is initialized or how your production server is configured.
To troubleshoot these issues, you might want to consider the following:
1. Double-check your Nuxt configuration, especially the security module settings, to ensure they are correctly applied in the production environment.
2. Review your deployment process to make sure all necessary configurations are properly transferred to the production environment.
3. Check if there are any environment-specific settings that might be interfering with the security module in production.
4. Consider reaching out to the Nuxt Security module maintainers with a detailed description of your setup and the issues you're facing. They might have more specific insights into why these discrepancies are occurring between development and production environments.
5. Ensure that your production server (e.g., Nginx, Apache) isn't overriding any headers set by the Nuxt application.
For more general information about security in Nuxt applications, you might find this video helpful: Are Front-end frameworks a security vulnerability by default?. It discusses security considerations when using front-end frameworks like Nuxt.
If you continue to face issues, it would be helpful to create a minimal reproduction of the problem and share it with the Nuxt community or the security module maintainers for more specific assistance.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@402218840408326154> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
The config for the security plug-in...

the cors middleware in server/middleware/cors.ts

now the xxss setting is set to 1; mode=block but it does not block the page visit.

you can import each npm packages that use that module and use it use fromNodeListener(cors());
But is this the way to do it?