Skip to content

refactor: prevent internal error exposure in API responses#77

Merged
kubrickcode merged 1 commit into
mainfrom
develop/shlee/57
Nov 29, 2025
Merged

refactor: prevent internal error exposure in API responses#77
kubrickcode merged 1 commit into
mainfrom
develop/shlee/57

Conversation

@kubrickcode
Copy link
Copy Markdown
Owner

Resolved security issue where internal implementation details (JWT parsing, Redis connection, etc.) were exposed to clients via direct err.Error() return

  • Separate internal error logging from external responses with WriteErrorWithLog
  • Map 20 sentinel errors to user-friendly messages
  • Apply to all 3 API handlers (callback, refresh, verify)
  • Add error response tests for each API handler

fix #57

Resolved security issue where internal implementation details (JWT parsing, Redis connection, etc.) were exposed to clients via direct err.Error() return

- Separate internal error logging from external responses with WriteErrorWithLog
- Map 20 sentinel errors to user-friendly messages
- Apply to all 3 API handlers (callback, refresh, verify)
- Add error response tests for each API handler

fix #57
@vercel
Copy link
Copy Markdown

vercel Bot commented Nov 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
github-project-status-viewer Ready Ready Preview Comment Nov 29, 2025 6:16am
github-project-status-viewer-p4ii Ready Ready Preview Comment Nov 29, 2025 6:16am

@github-actions github-actions Bot added the refactor Refactoring code label Nov 29, 2025
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @kubrickcode, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the security posture of the application by refactoring how errors are handled and presented to API clients. It ensures that internal system details, such as database connection failures or token parsing specifics, are no longer exposed in public API responses. Instead, these errors are logged internally for debugging, while clients receive generic, actionable error messages, thereby preventing potential information leakage.

Highlights

  • Enhanced Error Handling: Introduced a new utility function, httputil.WriteErrorWithLog, to centralize error handling. This function logs the internal error details while presenting sanitized, user-friendly messages to API clients, preventing exposure of sensitive implementation specifics.
  • Comprehensive Error Mapping: Mapped approximately 20 distinct internal sentinel errors (e.g., JWT parsing failures, Redis connection issues) to generic, client-safe error codes and descriptions, significantly improving security by obscuring backend complexities.
  • API Handler Integration: Applied the new error handling mechanism across all three core API handlers (callback, refresh, and verify), ensuring consistent and secure error responses throughout the authentication flow.
  • Robust Error Testing: Added dedicated test suites for each affected API handler and the new httputil package. These tests specifically verify that internal error details are not exposed in API responses and that appropriate user-facing messages are returned.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@kubrickcode
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great security enhancement that prevents internal error details from being exposed in API responses. The introduction of WriteErrorWithLog and the mapping of sentinel errors to generic, user-friendly messages is well-implemented. The changes are consistently applied across the callback, refresh, and verify handlers. The addition of comprehensive tests for error sanitization in each handler is excellent and significantly improves confidence in the changes. I have a couple of minor suggestions related to code duplication in tests and adherence to the repository's style guide.

Comment thread server/api/callback/index_test.go
Comment thread server/pkg/httputil/errors.go
@kubrickcode kubrickcode merged commit 8a13469 into main Nov 29, 2025
13 checks passed
@kubrickcode kubrickcode deleted the develop/shlee/57 branch November 29, 2025 06:18
@kubrickcode
Copy link
Copy Markdown
Owner Author

🎉 This PR is included in version 2.0.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

refactor Refactoring code released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sanitize Go API error messages

1 participant