test(error-shape): also catch message: field leakage (#354)#355
Merged
Conversation
`tests/unit/controller-error-shape.test.js` scanned for variants of `error: String(err) / err.message / error.message` to catch the original 137-occurrence leak that #140 cleaned up. But the runtime-shipped response body uses `message:` as its key — and a future contributor who writes `res.status(500).json({ message: err.message })` would route around the global error-handler's policy without the test catching the regression. Extend the regex set to cover the parallel `message:` patterns: - `message: String(error)` / `message: String(err)` - `message: err.message` - `message: error.message` A grep of `app/` confirms zero existing occurrences — this is a pure-tightening change. The global error-handler in `app/middleware/error-handler.js` is the ONE place allowed to echo err.message (under err.expose === true); the test specifically scans `app/controllers` and `app/middleware` so the handler's own file is covered too — its `message = err.message` assignment is NOT a `message: err.message` object-literal shape, so the regex doesn't false-positive there. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #354.
Summary
Extends
controller-error-shape.test.jsto scan formessage: err.message/message: error.message/message: String(error)/message: String(err)in addition to the existingerror:patterns. Pure tightening — no existing occurrences.Test plan
npm run lint && npm test— 794 passing (1 new assertion per existing test.each iteration, same test count).Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/