How to fix: API error response leaks a stack trace or internal file path
A JSON API error response includes a "stack" field containing a real stack trace, or a "message" field referencing an internal filesystem path, exposing implementation details to any caller who triggers the error.
Why it matters
Stack traces and internal paths reveal the framework and version in use, the deployment directory layout, and internal module structure: the reconnaissance an attacker needs to fingerprint the stack and look up known vulnerabilities for that exact version, or to craft path traversal and local file inclusion payloads with a real starting path.
The response must actually be JSON-shaped (an application/json content type or an /api/ URL path) and the offending value must sit inside a genuine "stack" or "message" JSON field, not any file-path-looking text elsewhere on the page. A roughly 200-character lookback before the match excludes content preceded by a fenced code block, <code>/<pre>, or the words example/documentation, so a blog post or docs page discussing this exact vulnerability in prose does not self-trigger it.
How to fix it
- 1Never send a raw Error.stack or native driver error message to the client; log it server-side and return a generic message plus an internal error id for support lookups
- 2Centralize error handling at the framework boundary (an Express error-handling middleware, a Next.js error handler) so no individual route can leak an unhandled exception
- 3Add a test that exercises a forced 500 response and asserts the body contains no file paths or stack frames
Code examples
Express: centralized error handler that strips internals
app.use((err, req, res, next) => {
console.error(err); // full detail stays server-side
const isProd = process.env.NODE_ENV === 'production';
res.status(err.status || 500).json({
error: isProd ? 'Internal server error' : err.message,
requestId: req.id,
});
});References
Detected automatically by VulnRadar. The check id is api-verbose-error-internal-path, stable across every scan so you can filter or diff on it.
More api checks
- LowTRACE method referenced in API response body
- InfoREST endpoint allows DELETE
- LowGraphQL introspection field suggestions
- MediumGraphQL endpoint has no rate-limit headers
- LowOpenAPI server URL leaks internal host
- LowCORS preflight result not cached
- HighBearer token in URL query string
- MediumJSONP callback parameter accepted
Questions
- How severe is API error response leaks a stack trace or internal file path?
- VulnRadar rates this medium severity in the api category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id api-verbose-error-internal-path, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does API error response leaks a stack trace or internal file path map to?
- It maps to CWE-209. In the OWASP Top 10 it falls under A05:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.