Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Fix logout path check for oidc overrides (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergicastro authored Feb 22, 2024
1 parent cfe4795 commit c924e2c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
12 changes: 7 additions & 5 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ func mergeAndValidateOIDCConfigs(cfg *configv1.Config) error {
// Set the defaults
applyOIDCDefaults(f.GetOidc())

// validate the logout path is not the root path
if f.GetOidc().GetLogout() != nil {
if isRootPath(f.GetOidc().GetLogout().GetPath()) {
return fmt.Errorf("%w: invalid logout path", ErrMustNotBeRootPath)
}
}

// validate the callback and the logout path are different
callbackURI, _ := url.Parse(f.GetOidc().GetCallbackUri())
if f.GetOidc().GetLogout() != nil && callbackURI.Path == f.GetOidc().GetLogout().GetPath() {
Expand Down Expand Up @@ -245,11 +252,6 @@ func validateOIDCConfigURLs(c *oidcv1.OIDCConfig) error {
if hasRootPath(c.GetCallbackUri()) {
return fmt.Errorf("%w: invalid callback URL", ErrMustNotBeRootPath)
}
if c.GetLogout() != nil {
if isRootPath(c.GetLogout().GetPath()) {
return fmt.Errorf("%w: invalid logout path", ErrMustNotBeRootPath)
}
}
return nil
}

Expand Down
1 change: 1 addition & 0 deletions internal/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestValidateConfig(t *testing.T) {
{"invalid-health-port", "testdata/invalid-health-port.json", errCheck{is: ErrHealthPortInUse}},
{"invalid-callback-uri", "testdata/invalid-callback.json", errCheck{is: ErrMustNotBeRootPath}},
{"invalid-logout-path", "testdata/invalid-logout.json", errCheck{is: ErrMustNotBeRootPath}},
{"valid-logout-override-default", "testdata/valid-logout-override-default.json", errCheck{is: nil}},
{"invalid-callback-and-logout-path", "testdata/invalid-callback-logout.json", errCheck{is: ErrMustBeDifferentPath}},
{"oidc-dynamic", "testdata/oidc-dynamic.json", errCheck{is: nil}},
{"valid", "testdata/mock.json", errCheck{is: nil}},
Expand Down
68 changes: 68 additions & 0 deletions internal/testdata/valid-logout-override-default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"allow_unmatched_requests": true,
"listen_address": "0.0.0.0",
"listen_port": "10003",
"log_level": "trace",
"default_oidc_config": {
"authorization_uri": "https://fake/auth",
"token_uri": "https://fake/token",
"jwks_fetcher": {
"jwks_uri": "https://fake/certs"
},
"client_id": "global_id",
"client_secret": "global_secret",
"id_token": {
"preamble": "Bearer",
"header": "Authorization"
},
"logout": {
"path": "/globallogout",
"redirect_uri": "https://fake/logout"
}
},
"threads": 8,
"chains": [
{
"name": "jaeger",
"match": {
"header": ":authority",
"prefix": "some"
},
"filters": [
{
"oidc_override": {
"authorization_uri": "https://fake/auth",
"token_uri": "https://fale/token",
"callback_uri": "https://some/login",
"client_id": "client-id",
"logout": {
"redirect_uri": "https://fake/logout"
}
}
}
]
},
{
"name": "local",
"match": {
"header": ":local",
"prefix": "localhost"
},
"filters": [
{
"oidc_override": {
"callback_uri": "https://localhost/login",
"client_id": "local_id",
"client_secret": "local_secret",
"cookie_name_prefix": "local",
"logout": {
"path": "/local",
"redirect_uri": "https://localhost/logout"
},
"scopes": []
}
}
]
}
]
}

0 comments on commit c924e2c

Please sign in to comment.