Skip to content

fix(security): sanitize error messages to prevent leaking internal details - #7346

Merged
JhaSourav07 merged 2 commits into
JhaSourav07:mainfrom
atul-upadhyay-7:fix/issue-7263-error-sanitization
Jul 4, 2026
Merged

fix(security): sanitize error messages to prevent leaking internal details#7346
JhaSourav07 merged 2 commits into
JhaSourav07:mainfrom
atul-upadhyay-7:fix/issue-7263-error-sanitization

Conversation

@atul-upadhyay-7

Copy link
Copy Markdown
Contributor

Fixes #7263

Problem

The sanitizeErrorMessage function in app/api/streak/route.ts only filtered messages containing ZodError/zod/schema patterns. All other error messages from GitHub API failures, internal assertion errors, or unexpected exceptions were returned verbatim to the client in both JSON and SVG error responses.

This could expose:

  • Internal authentication state (token rotation status, encrypted vs plaintext token usage)
  • Internal infrastructure details (cache server addresses, service names)
  • Internal error types and code paths that aid further exploitation

Solution

app/api/streak/route.ts

  1. Default to generic messages: sanitizeErrorMessage now returns a generic message for all unrecognized errors instead of passing through the raw message.

  2. Whitelist safe validation messages: Preserved specific user-facing messages for known client errors: org validation, multi-user validation, and rate limit quota warnings.

  3. Classify before sanitizing: Updated buildErrorResponse to detect error type (not-found, rate-limit, validation) using the raw message before sanitization, ensuring correct HTTP status codes while returning sanitized messages to clients.

app/api/streak/route.test.ts

Updated the test assertion for the multi-user validation error to match the line-wrapped SVG output.

Testing

  • All 311 streak tests pass (19 test files)
  • All 200 route tests pass
  • JSON format returns generic message for internal errors
  • SVG format returns sanitized error SVG for all non-validation errors

Copilot AI review requested due to automatic review settings July 3, 2026 12:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added the status:blocked This PR is blocked due to a failing CI check. label Jul 3, 2026
…ck with useSearchParams

The mock router.replace was not updating useSearchParams, causing the
auto-compare useEffect to race with manual setData(json) and wipe data.
Added realistic router mock that mirrors Next.js behavior, and disabled
window.caches to prevent stale Cache API interference between tests.
@github-actions github-actions Bot removed the status:blocked This PR is blocked due to a failing CI check. label Jul 3, 2026
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Size Report (Gzipped Sizes)

✨ No significant bundle size changes detected.

📊 Summary of Totals

Category PR Size Base Size Difference
Total JS 3883.44 KB 3883.44 KB 0 B
Total CSS 323.09 KB 323.09 KB 0 B

@github-actions github-actions Bot added the type:bug Something isn't working as expected label Jul 4, 2026
@Aamod007 Aamod007 added mentor:Aamod007 level:advanced Complex contributions involving architecture, optimization, or significant feature work type:security Security fixes, dependency updates, or hardening quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. labels Jul 4, 2026

@Aamod007 Aamod007 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Thanks for fixing the error message sanitization logic in the streak API. Leaking internal GitHub API errors or unhandled assertions is a real security risk, and preserving only intentional user validation messages is exactly what we need.

I'm assigning level:advanced, type:security, and quality:clean.

Great work, approving!

@JhaSourav07 JhaSourav07 added the gssoc:approved PR has been reviewed and accepted for valid contribution points label Jul 4, 2026
@JhaSourav07
JhaSourav07 merged commit 4d9be4b into JhaSourav07:main Jul 4, 2026
9 checks passed
@github-actions github-actions Bot added this to the GSSoC 2026 milestone Jul 4, 2026
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

🎉 Congratulations @atul-upadhyay-7! Your PR has been successfully merged. 🚀

Thank you for contributing to CommitPulse. Your work helps us build a better tool for the community.

⚠️ Important for GSSoC Contributors:
You are strictly advised to join our Discord Server as it is mandatory for all GSSoC participants. All important announcements, point claims, and community discussions happen there.

Keep building! 💻✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved PR has been reviewed and accepted for valid contribution points level:advanced Complex contributions involving architecture, optimization, or significant feature work mentor:Aamod007 quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. type:bug Something isn't working as expected type:security Security fixes, dependency updates, or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error sanitization bypass leaks internal API response details

4 participants