Skip to content

fix: validate error-derived status codes to prevent process crash (DoS)#122

Merged
jkyberneees merged 1 commit into
masterfrom
fix/error-status-code-validation
Jul 19, 2026
Merged

fix: validate error-derived status codes to prevent process crash (DoS)#122
jkyberneees merged 1 commit into
masterfrom
fix/error-status-code-validation

Conversation

@jkyberneees

Copy link
Copy Markdown
Collaborator

Summary

A thrown error carrying a numeric status/code/statusCode outside the valid HTTP range (100–999) was passed straight to res.statusCode, which throws RangeError: Invalid status code inside the error handler. That exception propagates as an uncaughtException and terminates the process — a single request becomes a full outage. Realistic trigger: libraries that set numeric non-HTTP codes on their errors (e.g. err.code = 99), or err.status = 12345.

Fix

New toHttpStatusCode() helper in libs/utils.js (accepts only integers in 100–999, otherwise falls back) applied at all three status-code sinks:

  • index.js — default error handler
  • libs/response-extensions.jsparseErr (the res.send(err) path)
  • libs/response-extensions.jsbeforeEnd, guarding the res.send(data, code) argument (falls back to the already-set res.statusCode)

Tests

  • New regression tests SEC-005/SEC-005b in specs/security.test.js: out-of-range (99), oversized (12345) and non-integer codes, via both custom (res.send(err)) and default error handlers, plus a server-liveness check after the bad requests.
  • Verified live: crash payloads now return 500 {"code":500,"message":"Internal Server Error"} and the process stays up.
  • Full suite: 136/136 passing; standard lint clean.

Found during a security review of the framework; full findings document is intentionally kept local and not part of this PR.

A thrown error carrying a numeric status/code/statusCode outside the
valid HTTP range (100-999) was passed straight to res.statusCode, which
throws 'RangeError: Invalid status code' inside the error handler. The
exception propagated as an uncaughtException and terminated the process,
turning a single request into a full outage (e.g. err.code = 99 as set
by some libraries).

Add toHttpStatusCode() in libs/utils.js and apply it at all three
status-code sinks: the default error handler (index.js), parseErr and
the res.send(data, code) path via beforeEnd (libs/response-extensions.js).

Regression tests: specs/security.test.js SEC-005/SEC-005b cover
out-of-range, oversized and non-integer codes for both custom and
default error handlers, plus a server-liveness check.
@jkyberneees
jkyberneees merged commit a0ed00b into master Jul 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant