Skip to content

Keep rejected request bodies out of logs and responses - #2491

Merged
kmcginnes merged 2 commits into
mainfrom
t3/redact-body-parser-error-logs
Oct 29, 2026
Merged

kmcginnes merged 2 commits into
mainfrom
t3/redact-body-parser-error-logs

Conversation

@kmcginnes

@kmcginnes kmcginnes commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A request body the parser rejects no longer reaches the logs or the response, since request bodies can hold database queries that the logging docs say are only logged at debug and trace.

User-facing: a request the server rejects now fails with its real status (400, 413, or 415) instead of a 500, and a request over the 50 MB limit shows "Request Too Large".

 app.use(
-  bodyParser.json(...)
+  rejectUnreadableBody(bodyParser.json(...))
 )
 // same for urlencoded

 rejectUnreadableBody(parser)
+  on parser error -> RejectedRequestBodyError(status, type, safe message)

Body-parser attaches the raw body to parse errors, and the JSON parse message quotes part of it. The wrapper converts any error from a body parser into a RejectedRequestBodyError that carries only the status, type, and a message. Parse failures get a fixed message, and the other parser messages are fixed text. The error handler is unchanged, so every other error logs as before. Detection is by origin, not by error shape.

Evidence

Before: a malformed /gremlin body wrote the raw body to the error log and returned a 500.
After: request bodies the parser rejects in packages/graph-explorer-proxy-server/src/app.test.ts sends malformed JSON, a bad charset, an oversized body, and an oversized form body containing a marker. Each asserts the marker is absent from every logger call at every level and from the response, with the expected status. createDisplayError.test.ts covers the 413 message.

Merge Danger

Door: two-way

Impact: error responses for rejected bodies change status and gain type. The Graph Explorer client is the only consumer, and it already shows the server message for these statuses.


🤖 Written by an AI agent on my behalf.

@kmcginnes
kmcginnes force-pushed the t3/redact-body-parser-error-logs branch from b1b1a96 to 94ad82c Compare October 28, 2026 20:55
@kmcginnes kmcginnes changed the title Keep rejected request bodies out of error logs Keep rejected request bodies out of logs and responses Oct 28, 2026

@kmcginnes kmcginnes left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@kmcginnes
kmcginnes merged commit e772418 into main Oct 29, 2026
4 checks passed
@kmcginnes
kmcginnes deleted the t3/redact-body-parser-error-logs branch October 29, 2026 00:07
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