fix(middleware): prevent authentication bypass via health check User-Agent matching - #5
Open
hacktron-app-dev[bot] wants to merge 1 commit into
Open
Conversation
…hing - Restrict User-Agent-based health check matching to the root path - Filter out empty User-Agent strings from the trusted set - Add regression tests in healthcheck_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a critical authentication bypass vulnerability in the health check middleware (
pkg/middleware/healthcheck.go).GoogleHC/1.0orPingUserAgent) on any incoming request path. In forward-authentication setups (e.g., Nginxauth_request), an attacker could send a request to a protected endpoint (like/admin) with a health check User-Agent. The reverse proxy would forward this request to/oauth2/authwith the same User-Agent, whichoauth2-proxy's health check middleware intercepted and returned200 OK. The reverse proxy interpreted this as successful authentication, granting the attacker access.PingUserAgentis"". Since empty strings were not filtered out when constructing the trustedUser-Agentset, any request lacking aUser-Agentheader matched""and bypassed authentication.Fixes
/). This ensures health checks work correctly for GCP/GKE (which target/withGoogleHC/1.0), but prevents bypasses on other paths (such as/oauth2/author/admin)."") when constructinguserAgentSet, ensuring empty User-Agent headers never match the health check criteria.Verification
pkg/middleware/healthcheck_test.goto verify that:PingUserAgentis empty.Automated fix by Hacktron for finding: http://dev.app.hacktron.ai/testset/findings/3f3e65e9-ec06-48eb-aef7-f7bd05787540