Issue 1878: Validate URL call does not correctly honor already set URL

This commit is contained in:
Leandro Lafin 2024-07-11 11:15:41 -03:00
parent 734b1483d2
commit 1175b65ab5
No known key found for this signature in database
GPG Key ID: 60C427B9DF40CB72
3 changed files with 23 additions and 1 deletions

View File

@ -14,6 +14,7 @@
- [#1883](https://github.com/oauth2-proxy/oauth2-proxy/pull/1883) Ensure v8 manifest variant is set on docker images
- [#1906](https://github.com/oauth2-proxy/oauth2-proxy/pull/1906) Fix PKCE code verifier generation to never use UTF-8 characters
- [#1927](https://github.com/oauth2-proxy/oauth2-proxy/pull/1927) Fix default scope settings for none oidc providers
- [#1951](https://github.com/oauth2-proxy/oauth2-proxy/pull/1951) Fix validate URL, check if query string marker (?) or separator (&) needs to be appended (@miguelborges99)
- [#1920](https://github.com/oauth2-proxy/oauth2-proxy/pull/1920) Make sure emailClaim is not overriden if userIDClaim is not set
# V7.4.0

View File

@ -53,7 +53,11 @@ func validateToken(ctx context.Context, p Provider, accessToken string, header h
endpoint := p.Data().ValidateURL.String()
if len(header) == 0 {
params := url.Values{"access_token": {accessToken}}
endpoint = endpoint + "?" + params.Encode()
if hasQueryParams(endpoint) {
endpoint = endpoint + "&" + params.Encode()
} else {
endpoint = endpoint + "?" + params.Encode()
}
}
result := requests.New(endpoint).
@ -74,3 +78,13 @@ func validateToken(ctx context.Context, p Provider, accessToken string, header h
logger.Errorf("token validation request failed: status %d - %s", result.StatusCode(), result.Body())
return false
}
// hasQueryParams check if URL has query parameters
func hasQueryParams(endpoint string) bool {
endpointURL, err := url.Parse(endpoint)
if err != nil {
return false
}
return len(endpointURL.RawQuery) != 0
}

View File

@ -132,6 +132,13 @@ func TestValidateSessionExpiredToken(t *testing.T) {
assert.Equal(t, false, validateToken(context.Background(), vtTest.provider, "foobar", nil))
}
func TestValidateSessionValidateURLWithQueryParams(t *testing.T) {
vtTest := NewValidateSessionTest()
defer vtTest.Close()
vtTest.provider.Data().ValidateURL, _ = url.Parse(vtTest.provider.Data().ValidateURL.String() + "?query_param1=true&query_param2=test")
assert.Equal(t, true, validateToken(context.Background(), vtTest.provider, "foobar", nil))
}
func TestStripTokenNotPresent(t *testing.T) {
test := "http://local.test/api/test?a=1&b=2"
assert.Equal(t, test, stripToken(test))