git.iko.soy/typeable/oauth2-proxy
on master help sign in
Ensure claim extractor does not attempt profile call when URL is empty
commit25ef843115cb42da196db1e5a676cee02ad6e42e authorJoel Speed <joel.speed@hotmail.co.uk> dateFri 18 Feb 2022, 14:09 (5 years ago) parent07aba7d
3 files changed+20−1
CHANGELOG.md+1 pkg/providers/util/claim_extractor.go+1−1 pkg/providers/util/claim_extractor_test.go+18
CHANGELOG.md+1
@@ -9,6 +9,7 @@
99## Changes since v7.2.1
1010
1111- [#1561](https://github.com/oauth2-proxy/oauth2-proxy/pull/1561) Add ppc64le support (@mgiessing)
12+- [#1563](https://github.com/oauth2-proxy/oauth2-proxy/pull/1563) Ensure claim extractor does not attempt profile call when URL is empty (@JoelSpeed)
1213- [#1560](https://github.com/oauth2-proxy/oauth2-proxy/pull/1560) Fix provider data initialisation (@JoelSpeed)
1314- [#1555](https://github.com/oauth2-proxy/oauth2-proxy/pull/1555) Refactor provider configuration into providers package (@JoelSpeed)
1415- [#1394](https://github.com/oauth2-proxy/oauth2-proxy/pull/1394) Add generic claim extractor to get claims from ID Tokens (@JoelSpeed)
pkg/providers/util/claim_extractor.go+1−1
@@ -86,7 +86,7 @@ func (c *claimExtractor) GetClaim(claim string) (interface{}, bool, error) {
8686// loadProfileClaims will fetch the profileURL using the provided headers as
8787// authentication.
8888func (c *claimExtractor) loadProfileClaims() (*simplejson.Json, error) {
89− if c.profileURL == nil || c.requestHeaders == nil {
89+ if c.profileURL == nil || c.profileURL.String() == "" || c.requestHeaders == nil {
9090 // When no profileURL is set, we return a non-empty map so that
9191 // we don't attempt to populate the profile claims again.
9292 // If there are no headers, the request would be unauthorized so we also skip
pkg/providers/util/claim_extractor_test.go+18
@@ -259,6 +259,24 @@ var _ = Describe("Claim Extractor Suite", func() {
259259 Expect(counter).To(BeEquivalentTo(1))
260260 })
261261
262+ It("GetClaim should not return an error with a non-nil empty ProfileURL", func() {
263+ claims, serverClose, err := newTestClaimExtractor(testClaimExtractorOpts{
264+ idTokenPayload: "{}",
265+ profileRequestHeaders: newAuthorizedHeader(),
266+ })
267+ Expect(err).ToNot(HaveOccurred())
268+ if serverClose != nil {
269+ defer serverClose()
270+ }
271+ // Set the ProfileURL to be empty, but not nil
272+ claims.(*claimExtractor).profileURL = &url.URL{}
273+
274+ value, exists, err := claims.GetClaim("user")
275+ Expect(err).ToNot(HaveOccurred())
276+ Expect(exists).To(BeFalse())
277+ Expect(value).To(BeNil())
278+ })
279+
262280 type getClaimIntoTableInput struct {
263281 testClaimExtractorOpts
264282 into interface{}