Fix stack trace leaked in error response in NestJS
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 NestJS CWE-209 / OWASP A05:2021
The vulnerable pattern in NestJS
This finding comes from the NestJS 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
Throw the exception without a custom body; let the built-in filter shape the response.
this.logger.error(err)
throw new InternalServerErrorException()
If you are not using NestJS
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 NestJS checks
Rules with a tested NestJS example.
- cors-permissive medium Cross-origin policy accepts any origin
- hardcoded-secret high Credential hardcoded in source
- insecure-cookie medium Cookie set without its protective attributes
- install-lifecycle-script medium Package declares an install-time script
- open-redirect medium Redirect target comes from the caller
- security-headers-missing medium Security headers are not configured
- sensitive-data-logged medium Sensitive data written to a log
- sql-injection high SQL query built by string interpolation
- ssrf high Server fetches a URL the caller controls
- weak-crypto high Broken cryptographic primitive protecting a secret
stack-trace-leak for every framework / All rules / owlwarden