Commit f7ad8bd
security: harden default error handler — safe-by-default (#51)
* security: harden default error handler — safe-by-default
BREAKING: DEFAULT_ERROR_HANDLER now only exposes error details in
NODE_ENV=development (opt-in). All other modes — production, staging,
testing, and unset NODE_ENV — return sanitized "Internal Server Error".
Previously, any mode except production leaked err.message to clients,
which could expose DB queries, file paths, or internal state.
Changes:
- lib/router/sequential.js: flip condition from === 'production' to
=== 'development', add Content-Type header
- tests/nested-routers.test.js: expect sanitized response in test mode
- tests/router-coverage.test.js: expect sanitized response in test mode
- tests/v4.4.test.js: add NODE_ENV-unset test
- tooling/pentest.js: comprehensive 48-vector security test suite
Pen test results: 48/48 passed, 0 findings (post-fix)
Test suite: 64/64 passed, 97.7% coverage
* fix: standard lint compliance in pentest.js
- Remove unused requires (http, url)
- Remove unused variables (checkPrototypePollution, timeout, nested→const)
- Fix trailing commas (standard style)
- Fix quotes (single quotes for strings)
- Fix dot notation (res.getHeader('server') not ['server'])
- Fix _body getter (captures mock response body correctly)
- Convert template literals to string concatenation for standard
---------
Co-authored-by: molty3000 <molty@21no.de>1 parent 586f4e2 commit f7ad8bd
5 files changed
Lines changed: 661 additions & 5 deletions
File tree
- lib/router
- tests
- tooling
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
21 | 22 | | |
| 23 | + | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | | - | |
| 164 | + | |
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
31 | 45 | | |
32 | 46 | | |
33 | 47 | | |
| |||
0 commit comments