Fix cross-origin policy accepts any origin in Koa

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 Koa CWE-942 / OWASP A05:2021

The vulnerable pattern in Koa

HIGH likely Cross-origin policy accepts any origin A05:2021 src/app.ts:15:9 13 │ 14 │ // cors-permissive: reflects any origin AND sends credentials. 15 │ app.use(cors({ origin: true, credentials: true })) │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ accepts requests from any origin 16 │ 17 │ router.post('/login', async (ctx) => {

This finding comes from the Koa fixture in the owlwarden test suite. The response echoes the caller's origin and permits credentials, so any site a logged-in user visits can make authenticated requests to this API and read the replies. The browser's same-origin protection is switched off for every origin.

The corrected handler

Give @koa/cors an explicit origin list.

import cors from '@koa/cors'

app.use(cors({
  origin: ['https://app.example.com'],
  credentials: true,
}))

If you are not using Koa

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 Koa checks

Rules with a tested Koa example.

cors-permissive for every framework / All rules / owlwarden