Remove OIDC authorization flow to fix data race vulnerability (#526)

## Summary

Fixes a concurrent map access vulnerability in the OIDC handler that
could cause remote unauthenticated DoS.

## Changes

- Removed OIDC authorization flow endpoints ( and )
- Removed the unsynchronized  map that caused the data race
- Kept only the OIDC token exchange endpoint ()
- Simplified  by removing OAuth2 flow dependencies

The map was being accessed concurrently by the start (write) and
callback (read/delete) endpoints without synchronization, causing
runtime panics. Since the token exchange flow doesn't require session
state, removing the authorization flow eliminates the vulnerability
entirely.
This commit is contained in:
adam jones 2025-09-22 13:41:32 +01:00 • committed by GitHub
commit 5746e7e99b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,9 +13,7 @@ import (
// MockGenericOIDCValidator for testing
type MockGenericOIDCValidator struct {
validateFunc func(ctx context.Context, token string) (*auth.OIDCClaims, error)
authURLFunc func(state, nonce, redirectURI string) string
exchangeCodeFunc func(ctx context.Context, code, redirectURI string) (string, error)
validateFunc func(ctx context.Context, token string) (*auth.OIDCClaims, error)
}
func (m *MockGenericOIDCValidator) ValidateToken(ctx context.Context, token string) (*auth.OIDCClaims, error) {
@ -25,20 +23,6 @@ func (m *MockGenericOIDCValidator) ValidateToken(ctx context.Context, token stri
return nil, fmt.Errorf("not implemented")
}
func (m *MockGenericOIDCValidator) GetAuthorizationURL(state, nonce, redirectURI string) string {
if m.authURLFunc != nil {
return m.authURLFunc(state, nonce, redirectURI)
}
return ""
}
func (m *MockGenericOIDCValidator) ExchangeCodeForToken(ctx context.Context, code, redirectURI string) (string, error) {
if m.exchangeCodeFunc != nil {
return m.exchangeCodeFunc(ctx, code, redirectURI)
}
return "", fmt.Errorf("not implemented")
}
func TestOIDCHandler_ExchangeToken(t *testing.T) {
tests := []struct {
name string
@ -121,34 +105,3 @@ func TestOIDCHandler_ExchangeToken(t *testing.T) {
})
}
}
func TestOIDCHandler_StartAuth(t *testing.T) {
config := &config.Config{
OIDCEnabled: true,
OIDCIssuer: "https://accounts.google.com",
OIDCClientID: "test-client-id",
OIDCClientSecret: "test-secret",
JWTPrivateKey: "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
}
mockValidator := &MockGenericOIDCValidator{
authURLFunc: func(state, nonce, redirectURI string) string {
return fmt.Sprintf("https://accounts.google.com/oauth/authorize?client_id=%s&state=%s&nonce=%s&redirect_uri=%s",
config.OIDCClientID, state, nonce, redirectURI)
},
}
handler := auth.NewOIDCHandler(config)
handler.SetValidator(mockValidator)
ctx := context.Background()
authURL, err := handler.StartAuth(ctx, "http://localhost:3000/callback")
require.NoError(t, err)
assert.Contains(t, authURL, "https://accounts.google.com/oauth/authorize")
assert.Contains(t, authURL, "client_id=test-client-id")
assert.Contains(t, authURL, "state=")
assert.Contains(t, authURL, "nonce=")
}
// Note: validateExtraClaims and buildPermissions are tested through ExchangeToken integration tests