fix: sanitize error logging to prevent credential exposure (#217)#223
Open
saurabhhhcodes wants to merge 1 commit into
Open
fix: sanitize error logging to prevent credential exposure (#217)#223saurabhhhcodes wants to merge 1 commit into
saurabhhhcodes wants to merge 1 commit into
Conversation
…#217) Add error-sanitizer utility that strips sensitive fields (config, request, response, headers, stack) and redacts credential patterns from error objects before logging or returning in HTTP responses. Add Express global error handler as a safety net that sanitizes uncaught errors and returns a generic message. Update route catch blocks to use sanitized error logging.
|
Someone is attempting to deploy a commit to the Dot_NotSam's projects Team on Vercel. A member of the Team first needs to authorize it. |
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 #217
Changes
New utility:
src/utils/error-sanitizer.jssanitizeErrorForLogging(error)— Strips sensitive keys (config,request,response,headers,stack) and redacts credential patterns (GitHub tokens, Bearer tokens, API keys) from error objects before logging.sanitizeErrorResponse(error)— Returns a generic{ error, status }envelope for HTTP responses.Global Express error handler (
src/server.js)Added an error-handling middleware that catches uncaught errors, logs only the sanitized representation, and returns a generic
Internal server errorresponse — preventing any accidental leak of credentials or stack traces.Route catch blocks updated
profile.route.js— UsessanitizeErrorForLoggingin the catch handler; sends a generic detail string (noterror.message) to the SVG error response.theme-comparison.route.js— Same sanitized logging pattern.Tests:
src/utils/error-sanitizer.test.js(28 tests)config,request,response,headers,stackghp_,gho_,github_pat_tokens from string valuescode,status,url)Acceptance criteria coverage
console.log/error outputerror.confignot included in error responses (defense in depth — project uses nativefetch, not Axios)