Security rules

NGB085: Error details sent to clients

Reports server code (Express / Node SSR servers, API routes) that sends a caught error to the HTTP client: the stack trace, the raw error object, or its message, in res.send(), res.json(), res.end(), res.write(), res.render() (also after res.status(500)).

Property Value
Rule ID NGB085
Category Angular SSR security
Default severity medium
CWE CWE-209, CWE-497
Built-in presets recommended: error, strict: error

Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.

What it checks

Reports server code (Express / Node SSR servers, API routes) that sends a caught error to the HTTP client: the stack trace, the raw error object, or its message, in res.send(), res.json(), res.end(), res.write(), res.render() (also after res.status(500)). Errors come from catch clauses, Express error middleware (err, req, res, next), promise .catch() handlers and Node-style (err, …) callbacks.

Why it matters

Stack traces reveal file paths, framework and library versions, and internal function names; driver errors carry SQL statements, table names, hostnames and sometimes connection strings or user data. Attackers use these details to fingerprint the server and to tune injection payloads. Express itself hides stacks in production — sending err.stack manually bypasses that.

Detection behavior and supported patterns

  • res.status(500).send(err.stack), res.json({ error: err }), res.send(Failed: ${err}), res.end(String(error)) — stack: medium severity; raw error object / driver sql / sqlMessage: medium; err.message: low
  • Error values: catch (e), the first parameter of 4-parameter Express error middleware, .catch(err => …), .then(_, err => …), last-argument Node callbacks (err, data) => …
  • Responses guarded by a development check (NODE_ENV, isDev, debug) are not reported
  • Response objects: Express Response, Node ServerResponse, and untyped res parameters next to req

Example

TypeScript
app.use((err, req, res, next) => res.status(500).send(err.stack));

Safer alternative

TypeScript
app.use((err, req, res, next) => {  logger.error({ err, id: req.id });  res.status(500).json({ error: 'Internal server error', id: req.id });});

Remediation

Log the full error on the server (with a correlation ID) and send a generic message: res.status(500).json({ error: "Internal error", id }). Map expected errors to explicit, user-safe messages.

False-positive considerations

  • Validation errors whose message is written for users (throw new ValidationError("Email is required")) are reported when sent as err.message; return a curated message or an error code instead.

Known limitations

  • Errors copied into other variables or wrapped in custom error classes before sending are not followed.
  • Error details rendered by frameworks other than Express / Node http (Fastify reply, NestJS exception filters) are not analyzed.
  • Whether err.message is safe depends on where the error was thrown; it is reported with low severity.

References

Run it

Shell
ngbastion explain NGB085