fix(backend): sanitize error handler to prevent internal info leak#204
Merged
Conversation
Verify that createStatsRouter is correctly wired into the Express app: - Mount at /api/stats returns 200 (not 404) with correct stats shape - Empty database returns zeroed totals and 100% uptime with 24 hourly buckets - Inserted agents/tasks/payments are reflected in the response - Closed database is handled gracefully and returns 500 - Full-app wiring test confirms /api/stats is mounted via createApp The router mount and OpenAPI registration were already present in app.ts and openapi.ts; this commit adds the missing test coverage.
…pta-Node#159) - Check NODE_ENV to determine error detail level - Production: return generic error code (err.code || INTERNAL_SERVER_ERROR) and a safe user-facing message; never expose raw err.message or stack - Development: include full error message and stack trace for debugging - Always log full error server-side via Pino (err, requestId, path, method) - Always include requestId and path in every response for traceability - Add tests: production mode leaks no internal details; development mode exposes full error message and stack trace
|
@DevSolex is attempting to deploy a commit to the Jaja's projects Team on Vercel. A member of the Team first needs to authorize it. |
devJaja
self-requested a review
July 24, 2026 20:28
devJaja
approved these changes
Jul 24, 2026
Contributor
Author
Appreciate the review! |
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.
Summary
Fixes the global error handler leaking internal implementation details (raw error messages, stack traces, file paths) to API clients.
Closes #159
Changes
backend/src/api/middleware/errorHandler.tsNODE_ENVto determine error detail levelerr.code || 'INTERNAL_SERVER_ERROR'and a safe generic message — never expose rawerr.messageor stack traceerr.messageanderr.stackfor debuggingerr,requestId,path,method)requestIdandpathin every response for traceabilitybackend/tests/errorHandler.test.ts(new)12 tests covering all acceptance criteria:
err.codewhen present, falls back toINTERNAL_SERVER_ERROR, respectserr.statusCode, always includesrequestIdandpathmessagefield, always includesrequestIdTest Results
Acceptance Criteria
NODE_ENVto determine error detail levelrequestIdin the response for debugging