Skip to content

fix: sanitize error logging to prevent credential exposure (#217)#223

Open
saurabhhhcodes wants to merge 1 commit into
SamXop123:mainfrom
saurabhhhcodes:security/error-sanitization-217
Open

fix: sanitize error logging to prevent credential exposure (#217)#223
saurabhhhcodes wants to merge 1 commit into
SamXop123:mainfrom
saurabhhhcodes:security/error-sanitization-217

Conversation

@saurabhhhcodes

Copy link
Copy Markdown

Closes #217

Changes

New utility: src/utils/error-sanitizer.js

  • sanitizeErrorForLogging(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 error response — preventing any accidental leak of credentials or stack traces.

Route catch blocks updated

  • profile.route.js — Uses sanitizeErrorForLogging in the catch handler; sends a generic detail string (not error.message) to the SVG error response.
  • theme-comparison.route.js — Same sanitized logging pattern.

Tests: src/utils/error-sanitizer.test.js (28 tests)

  • Handles null/undefined errors
  • Strips config, request, response, headers, stack
  • Redacts ghp_, gho_, github_pat_ tokens from string values
  • Redacts nested sensitive strings
  • Preserves safe custom properties (code, status, url)
  • Survives circular references

Acceptance criteria coverage

  • ✅ GitHub token never appears in HTTP response bodies
  • ✅ GitHub token never appears in console.log/error output
  • error.config not included in error responses (defense in depth — project uses native fetch, not Axios)
  • ✅ Error responses in production return generic message, not stack trace (global error handler)

…#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.
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

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.

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.

[Security] GitHub API token leaked in error responses and potentially in logs

1 participant