Skip to content

Harden Express request handling#14

Merged
kasnder merged 2 commits into
mainfrom
agent/harden-express-request-handling
Jul 13, 2026
Merged

Harden Express request handling#14
kasnder merged 2 commits into
mainfrom
agent/harden-express-request-handling

Conversation

@kasnder

@kasnder kasnder commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

  • forward every async Express 4 route rejection into centralized error middleware
  • return controlled 500 responses for unexpected handler failures while preserving exposed parser status codes
  • limit public form parsing to /search with a separate 100kb default
  • mount the 25mb JSON/text parsers only on authenticated analyser upload endpoints
  • add HTTP regressions for rejected async work, public and nonexistent routes, analyzer authentication, and JSON/text body limits

Root cause

Express 4 does not automatically pass rejected route promises to next, so database failures from routes such as /analysis, /queue, /uploadAnalysis, and /reportAnalysisFailure could become unhandled rejections. Separately, the analyzer-sized JSON, text, and form parsers were mounted globally, allowing any public or nonexistent route to consume the large request-body allowance.

Impact

Async route failures now terminate as controlled HTTP errors instead of risking process-level unhandled rejections. Public requests cannot use the analyzer upload allowance, while existing authenticated analyzer JSON and text uploads retain the configurable BODY_LIMIT behavior. The public search form has an independently configurable PUBLIC_FORM_BODY_LIMIT defaulting to 100kb.

Validation

  • npm test — 24 tests passed
  • node --check server.js
  • node --check routes/index.js
  • node --check lib/asyncHandler.js
  • node --check test/requestHandling.test.js
  • git diff --check

@kasnder

kasnder commented Jul 13, 2026

Copy link
Copy Markdown
Member Author

Review complete. I applied the one robustness fix from the review: the centralized error middleware now accepts either err.status or err.statusCode before validating the 4xx/5xx range (commit 0750b26). npm test passes: 24/24.

The /about and /ping async-to-sync simplification is harmless, though it is slightly outside the PR’s stated focus. No other correctness concerns found.

@kasnder
kasnder marked this pull request as ready for review July 13, 2026 14:59
@kasnder
kasnder merged commit d778ce9 into main Jul 13, 2026
2 checks passed
@kasnder
kasnder deleted the agent/harden-express-request-handling branch July 13, 2026 14:59
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