How to fix: Express.js error stack trace in response
The response contains an Express.js error page with a stack trace, indicating the app is running in development mode or missing a production error handler.
Why it matters
Express development error pages expose full stack traces with file paths, line numbers, and sometimes variable values, giving an attacker a detailed map of the application's internal structure.
Express's default error handler prints stack traces when NODE_ENV is not "production". This must be disabled and replaced with a custom error handler before deployment.
How to fix it
- 1Set NODE_ENV=production in your deployment environment
- 2Add a custom error handler at the end of your middleware chain
- 3Return only generic error messages from the error handler
Code examples
Production error handler
// Must be the LAST middleware in the chain:
app.use((err, req, res, next) => {
console.error("[Error]", err); // log server-side
res.status(err.status || 500).json({
error: "An unexpected error occurred"
// Never include: err.message, err.stack
});
});References
Detected automatically by VulnRadar. The check id is express-error-format-disclosure, stable across every scan so you can filter or diff on it.
More info disclosure checks
- MediumRails Session Cookie Missing HttpOnly Flag
- InfoServer header truncated
- InfoPHP session cookie naming exposes runtime
- Infoconfig.js / settings.js referenced (verify contents)
- Infoenv.js / environment.js referenced (verify contents)
- InfoSitemap.xml publicly accessible
- InfoOpenAPI schema version exposed in URL
- LowCORS exposes internal CDN hostname
Questions
- How severe is Express.js error stack trace in response?
- VulnRadar rates this medium severity in the info disclosure 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 express-error-format-disclosure, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does Express.js error stack trace in response 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.