feat(config): Add TrustedProxies support to config #21
Conversation
Refactor string slice env parsing for AllowedHosts and TrustedProxies. Ensures robust handling of comma-separated values from environment variables, including Docker scenarios.
- Add stack trace logging on panic recovery for better debugging - Set CSRF cookie SameSite attribute to Lax for improved security - Implement Unwrap method for responseWriter to support http.ResponseController
Enhances getClientIP to validate X-Forwarded-For only from trusted proxies. Adds helpers for trusted proxy checks, allowed hosts, and IP normalization.
Adds unit tests for getClientIP and CheckAllowedHosts middleware, covering trusted proxies, X-Forwarded-For handling, and allowed host logic for domains, IPs, and CIDRs.
Ensure session is destroyed only if authenticated but user ID is missing, preventing possible session tampering.
Covers redirect, session destruction, error logging, and cache control.
Summary of ChangesHello @madalinpopa, 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 application's network configuration and security by introducing explicit support for trusted proxies, which is crucial for accurate client IP identification in production environments. It also refines existing middleware functionalities, such as panic recovery and session management, and bolsters the codebase with new, comprehensive unit tests for these critical components. The changes ensure more robust and secure handling of incoming requests and application state. Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for TrustedProxies to correctly identify client IPs behind a proxy, which is a great security and functionality enhancement. The changes include updates to configuration, middleware for handling trusted proxies and allowed hosts, and improved panic recovery logging. The introduction of comprehensive tests for the new middleware logic is also a valuable addition.
My review focuses on a couple of performance considerations in the new middleware logic. Specifically, both isAllowedHost and isTrustedProxy functions re-process configuration strings on every request, which can be inefficient. I've suggested refactoring to pre-process these configurations once during middleware initialization. Overall, this is a solid contribution with significant improvements.
Trusted proxies are now parsed once and cached for efficient lookup, reducing repeated parsing and improving performance.
Improve allowed host validation by normalizing hosts once and reusing the parsed list, reducing redundant normalization and improving performance.
No description provided.