Fix authentication bypass via User-Agent-based Health Check on proxy prefix paths - #7
Open
hacktron-app-dev[bot] wants to merge 1 commit into
Open
Conversation
…check on proxy prefix paths By checking if the request path starts with the proxy prefix, we ensure that authentication-critical endpoints like `/oauth2/auth` cannot be bypassed by matching configured health-check User-Agents.
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 addresses a severe authentication bypass vulnerability (WEB-1062) in
oauth2-proxy.Root Cause
Under Nginx
auth_requestconfiguration, Nginx forwards subrequests to/oauth2/authto verify if a client is authenticated. However, when health-check user agents (such asGoogleHC/1.0or custom ping user agents) are enabled, the health check middleware intercepts any request with matching User-Agent headers, returning200 OK("OK") without calling the authentication handlers. If a malicious client crafts a request with a health check User-Agent, Nginx receives a200 OKon/oauth2/authand forwards the request to the protected upstream, bypassing authentication completely.Solution
We modified the health check middleware to ensure that requests hitting the proxy prefix (e.g.,
/oauth2/...) are excluded from User-Agent-based health check matches. If a request is explicitly mapped to a health-check path (like/ping), it continues to function as before. However, any request pointing to paths starting with the configuredProxyPrefixwill no longer be intercepted by a matching User-Agent.Verification
pkg/middleware/healthcheck_test.goverifying:/oauth2/authwith a health check User-Agent correctly fall through./oauth2%2fauthwith a health check User-Agent correctly fall through.Automated fix by Hacktron for finding: http://dev.app.hacktron.ai/testset/findings/0d7a0967-b73c-4628-9233-426599269658