Fix stack trace leaked in error response in Astro

Returning an error's `.stack` to the client exposes absolute file paths, dependency versions, and internal call structure. Attackers use it to map the application and to fingerprint vulnerable dependency versions. Log the stack server-side and return a generic message.

high likely Astro CWE-209 / OWASP A05:2021

The vulnerable pattern in Astro

HIGH likely Stack trace leaked in error response A05:2021 src/pages/api/users.ts:49:49 47 │ } catch (err) { 48 │ // stack-trace-leak: Response constructor carries the stack to the client. 49 │ return new Response(JSON.stringify({ error: (err as Error).stack }), { │ ~~~~~~~~~~~~~~~~~~~~ leaks internal stack trace to the client 50 │ status: 500, 51 │ headers: { 'Content-Type': 'application/json' },

This finding comes from the Astro fixture in the owlwarden test suite, in GET /api/users. Stack traces expose absolute file paths, dependency versions, and internal call structure - enough to fingerprint the stack and locate other weaknesses.

The corrected handler

Log server-side and return a generic response.

console.error(err)
return new Response(JSON.stringify({ error: 'Internal Server Error' }), {
  status: 500,
  headers: { 'Content-Type': 'application/json' },
})

If you are not using Astro

Log the error server-side and return a generic message to the client.

Check your own repository

npx owlwarden scan
npx owlwarden explain stack-trace-leak

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

Rules with a tested Astro example.

stack-trace-leak for every framework / All rules / owlwarden