Skip to content

Commit 169ad67

Browse files
authored
fix(custom-oidc): strip trailing slashes from issuer (#2570)
## What kind of change does this PR introduce? Bug fix ## summary Fixes `GetDiscoveryURL` constructing a malformed URL (e.g. `https://example.com//.well-known/openid-configuration`) when the configured OIDC issuer has a trailing slash.
1 parent c5969ed commit 169ad67

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

internal/models/custom_oauth_provider.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"database/sql"
55
"database/sql/driver"
66
"encoding/json"
7+
"strings"
78
"time"
89

910
"github.com/gobuffalo/pop/v6/slices"
@@ -134,7 +135,7 @@ func (p *CustomOAuthProvider) GetDiscoveryURL() string {
134135
return *p.DiscoveryURL
135136
}
136137

137-
return *p.Issuer + "/.well-known/openid-configuration"
138+
return strings.TrimRight(*p.Issuer, "/") + "/.well-known/openid-configuration"
138139
}
139140

140141
// SetDiscoveryCache stores a validated OIDC discovery document and records the cache time.

internal/models/custom_oauth_provider_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,41 @@ func (ts *CustomOAuthProviderTestSuite) TestClientSecretRoundTripThroughDB() {
451451
assert.Equal(ts.T(), secret, decrypted)
452452
}
453453

454+
func TestGetDiscoveryURLStripsTrailingSlashes(t *testing.T) {
455+
tests := []struct {
456+
name string
457+
issuer string
458+
expected string
459+
}{
460+
{
461+
name: "no trailing slash",
462+
issuer: "https://example.com",
463+
expected: "https://example.com/.well-known/openid-configuration",
464+
},
465+
{
466+
name: "single trailing slash",
467+
issuer: "https://example.com/",
468+
expected: "https://example.com/.well-known/openid-configuration",
469+
},
470+
{
471+
name: "multiple trailing slashes",
472+
issuer: "https://example.com///",
473+
expected: "https://example.com/.well-known/openid-configuration",
474+
},
475+
}
476+
477+
for _, tt := range tests {
478+
t.Run(tt.name, func(t *testing.T) {
479+
issuer := tt.issuer
480+
provider := &CustomOAuthProvider{
481+
ProviderType: ProviderTypeOIDC,
482+
Issuer: &issuer,
483+
}
484+
assert.Equal(t, tt.expected, provider.GetDiscoveryURL())
485+
})
486+
}
487+
}
488+
454489
// Helper functions
455490

456491
func (ts *CustomOAuthProviderTestSuite) createTestProvider(providerType ProviderType, identifier string) *CustomOAuthProvider {

0 commit comments

Comments
 (0)