Skip to main content
MediumInfo disclosureOWASP A05:2021CWE-209

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

  1. 1Set NODE_ENV=production in your deployment environment
  2. 2Add a custom error handler at the end of your middleware chain
  3. 3Return only generic error messages from the error handler

Code examples

Production error handler

JavaScript
// 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.

See every info disclosure check

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.

Propose a checkHow a check is built

Scan your own site for express.js error stack trace in response

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

Express.js error stack trace in response fix | VulnRadar