Fix stack trace leaked in error response in Elysia

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 Elysia CWE-209 / OWASP A05:2021

The vulnerable pattern in Elysia

HIGH likely Stack trace leaked in error response A05:2021 src/index.ts:38:49 36 │ } catch (err) { 37 │ // stack-trace-leak: the client learns the file layout and dependency versions. 38 │ return new Response(JSON.stringify({ error: (err as Error).stack }), { │ ~~~~~~~~~~~~~~~~~~~~ leaks internal stack trace to the client 39 │ status: 500, 40 │ headers: { 'content-type': 'application/json' },

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

The corrected handler

Use `onError` so every route answers the same way, and keep the detail in the log.

app.onError(({ error, set }) => {
  console.error(error)
  set.status = 500
  return { error: 'Internal Server Error' }
})

If you are not using Elysia

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

Rules with a tested Elysia example.

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