Fix cross-origin policy accepts any origin in Nuxt

The CORS configuration accepts requests from any origin. Combined with credentials this lets any site a logged-in user visits make authenticated calls to the API and read the responses. Without credentials it may be intentional for a public API - the finding says which case it found.

medium likely Nuxt CWE-942 / OWASP A05:2021

The vulnerable pattern in Nuxt

MEDIUM likely Cross-origin policy accepts any origin A05:2021 server/middleware/cors.ts:6:3 4 │ // shape that is actually detected here. 5 │ export default defineEventHandler((event) => { 6 │ event.node.res.setHeader('Access-Control-Allow-Origin', '*') │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ accepts requests from any origin 7 │ event.node.res.setHeader('Access-Control-Allow-Credentials', 'true') 8 │ })

This finding comes from the Nuxt fixture in the owlwarden test suite. Any origin may call this API and read the response. That is a deliberate choice for a public endpoint and a mistake for anything behind a session - nothing in the source says which this is, so it is reported for you to decide.

The corrected handler

List the origins in the route rules rather than reflecting the caller's.

// nuxt.config.ts
routeRules: {
  '/api/**': {
    cors: true,
    headers: { 'Access-Control-Allow-Origin': 'https://app.example.com' },
  },
}

If you are not using Nuxt

Replace the wildcard with the origins that actually need access, and only send credentials to those.

Check your own repository

npx owlwarden scan
npx owlwarden explain cors-permissive

Runs on your machine. No account, no telemetry, no network unless you ask. In CI, SARIF uploads to code scanning and the exit code is the gate.

Other Nuxt checks

Rules with a tested Nuxt example.

cors-permissive for every framework / All rules / owlwarden