fix: address findings from 10 independent code reviews#467
Conversation
Bugs fixed: - Fix slice mutation during iteration in OnRemoveUserFromGroup (missing break) - Fix FindByDN/FindBySAMAccountName returning pointers into cache internals that escape the read lock — now return value copies - Fix CSRF tokens cached in HTML by excluding detail pages with forms from template cache (stale tokens caused 403 on form submission) - Fix handle500 potential infinite recursion if template render fails - Fix handle500 only handling 401 — now uses fiber error code for all types - Fix TemplateCache.Stop() panic on double-close (add sync.Once) - Fix RenderWithCache using context.Background() instead of request context Security: - Add LDAP filter metacharacters (*, (, ), null byte) to username validation - Stop leaking internal error details to users in 500 pages - Fix BorderColor() panic on unknown FlashType (return fallback instead) Code quality: - Remove dead code: OptionalAuth, GetCachedManifest, manifestCache, App.logger - Fix createCSRFConfig returning *fiber.Handler unnecessarily - Fix shutdown order: drain Fiber before stopping caches - Pre-allocate Filter result slice - Add sync.Mutex to mock test helpers for thread safety Signed-off-by: Sebastian Mendel <sebastian.mendel@netresearch.de> Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
Summary of ChangesHello, 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 delivers a comprehensive set of fixes and improvements based on extensive code reviews of the per-user LDAP credentials feature. The changes significantly enhance the application's robustness, security posture, and overall code quality. Key areas addressed include preventing common programming pitfalls, safeguarding against security vulnerabilities, and streamlining internal processes for better maintainability. 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 addresses a comprehensive list of findings from previous code reviews, encompassing critical bugs, security vulnerabilities, and code quality enhancements. The changes are substantial and well-executed. However, a critical security vulnerability remains: the newly added username validation for LDAP injection prevention is inconsistently applied. It is currently only present in the authenticateViaUPNBind function, leaving the service-account-based authentication path in authenticateUser potentially vulnerable. Moving this validation to the top-level authenticateUser function will ensure consistent protection across both authentication methods. Additionally, I have one suggestion for improvement regarding error handling in the flash.go template helper to enhance observability.
Override svgo to >=4.0.1 to fix Billion Laughs entity expansion DoS in the transitive dependency chain cssnano > postcss-svgo > svgo. Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
d5948a5 to
ba237a2
Compare
Summary
Addresses critical bugs, security issues, and code quality findings from 10 independent code reviews of the per-user LDAP credentials feature (#430).
Bug Fixes
OnRemoveUserFromGroup— added missingbreakafter removalFindByDN/FindBySAMAccountName/Findnow return value copies instead of pointers into cache internalsTemplateCache.Stop()double-close panic — guarded withsync.OnceRenderWithCacheignoring request context — switched fromcontext.Background()toc.UserContext()handle500recursion risk — rewritten to handle all Fiber error codes, prevent template render recursion, hide internal errors from usersSecurity
*,(,), null byte) to rejection listhandle500now shows generic message instead of internal error detailsCode Quality
OptionalAuth,GetCachedManifest,manifestCache,manifestMutex,App.loggercreateCSRFConfig— returnsfiber.Handlerdirectly instead of*fiber.HandlerFilterpre-allocation — pre-allocates result slice capacitysync.Mutexto test helper call count trackingTest plan
go vetcleangofumptformatting applied-raceon ldap_cache package)