summaryrefslogtreecommitdiff
path: root/vendor/github.com/coreos/go-oidc
diff options
context:
space:
mode:
authorLibravatar kim <grufwub@gmail.com>2025-08-10 15:05:54 +0200
committerLibravatar kim <gruf@noreply.codeberg.org>2025-08-10 15:05:54 +0200
commit67100809b399b60e58490fa8b1c0a72be75ac820 (patch)
treeae6df939bf9fe557a766120bee3363f89b47f961 /vendor/github.com/coreos/go-oidc
parent[feature + performance] add JSON logging format (#4355) (diff)
downloadgotosocial-67100809b399b60e58490fa8b1c0a72be75ac820.tar.xz
[chore] update dependencies (#4361)
- codeberg.org/gruf/go-kv/v2 v2.0.5 => v2.0.6 - github.com/coreos/go-oidc/v3 v3.14.1 => v3.15.0 - github.com/miekg/dns v1.1.67 => v1.1.68 - github.com/tdewolff/minify/v2 v2.23.9 => v2.23.11 - github.com/yuin/goldmark v1.7.12 => v1.7.13 - golang.org/x/crypto v0.40.0 => v0.41.0 - golang.org/x/image v0.29.0 => v0.30.0 - golang.org/x/net v0.42.0 => v0.43.0 - golang.org/x/sys v0.34.0 => v0.35.0 - golang.org/x/text v0.27.0 => v0.28.0 - modernc.org/sqlite v1.38.0 => v1.38.2 Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4361 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/github.com/coreos/go-oidc')
-rw-r--r--vendor/github.com/coreos/go-oidc/v3/oidc/verify.go99
1 files changed, 41 insertions, 58 deletions
diff --git a/vendor/github.com/coreos/go-oidc/v3/oidc/verify.go b/vendor/github.com/coreos/go-oidc/v3/oidc/verify.go
index 52b27b746..a8bf107d4 100644
--- a/vendor/github.com/coreos/go-oidc/v3/oidc/verify.go
+++ b/vendor/github.com/coreos/go-oidc/v3/oidc/verify.go
@@ -1,15 +1,11 @@
package oidc
import (
- "bytes"
"context"
- "encoding/base64"
"encoding/json"
- "errors"
"fmt"
"io"
"net/http"
- "strings"
"time"
jose "github.com/go-jose/go-jose/v4"
@@ -145,18 +141,6 @@ func (p *Provider) newVerifier(keySet KeySet, config *Config) *IDTokenVerifier {
return NewVerifier(p.issuer, keySet, config)
}
-func parseJWT(p string) ([]byte, error) {
- parts := strings.Split(p, ".")
- if len(parts) < 2 {
- return nil, fmt.Errorf("oidc: malformed jwt, expected 3 parts got %d", len(parts))
- }
- payload, err := base64.RawURLEncoding.DecodeString(parts[1])
- if err != nil {
- return nil, fmt.Errorf("oidc: malformed jwt payload: %v", err)
- }
- return payload, nil
-}
-
func contains(sli []string, ele string) bool {
for _, s := range sli {
if s == ele {
@@ -219,12 +203,49 @@ func resolveDistributedClaim(ctx context.Context, verifier *IDTokenVerifier, src
//
// token, err := verifier.Verify(ctx, rawIDToken)
func (v *IDTokenVerifier) Verify(ctx context.Context, rawIDToken string) (*IDToken, error) {
- // Throw out tokens with invalid claims before trying to verify the token. This lets
- // us do cheap checks before possibly re-syncing keys.
- payload, err := parseJWT(rawIDToken)
+ var supportedSigAlgs []jose.SignatureAlgorithm
+ for _, alg := range v.config.SupportedSigningAlgs {
+ supportedSigAlgs = append(supportedSigAlgs, jose.SignatureAlgorithm(alg))
+ }
+ if len(supportedSigAlgs) == 0 {
+ // If no algorithms were specified by both the config and discovery, default
+ // to the one mandatory algorithm "RS256".
+ supportedSigAlgs = []jose.SignatureAlgorithm{jose.RS256}
+ }
+ if v.config.InsecureSkipSignatureCheck {
+ // "none" is a required value to even parse a JWT with the "none" algorithm
+ // using go-jose.
+ supportedSigAlgs = append(supportedSigAlgs, "none")
+ }
+
+ // Parse and verify the signature first. This at least forces the user to have
+ // a valid, signed ID token before we do any other processing.
+ jws, err := jose.ParseSigned(rawIDToken, supportedSigAlgs)
if err != nil {
return nil, fmt.Errorf("oidc: malformed jwt: %v", err)
}
+ switch len(jws.Signatures) {
+ case 0:
+ return nil, fmt.Errorf("oidc: id token not signed")
+ case 1:
+ default:
+ return nil, fmt.Errorf("oidc: multiple signatures on id token not supported")
+ }
+ sig := jws.Signatures[0]
+
+ var payload []byte
+ if v.config.InsecureSkipSignatureCheck {
+ // Yolo mode.
+ payload = jws.UnsafePayloadWithoutVerification()
+ } else {
+ // The JWT is attached here for the happy path to avoid the verifier from
+ // having to parse the JWT twice.
+ ctx = context.WithValue(ctx, parsedJWTKey, jws)
+ payload, err = v.keySet.VerifySignature(ctx, rawIDToken)
+ if err != nil {
+ return nil, fmt.Errorf("failed to verify signature: %v", err)
+ }
+ }
var token idToken
if err := json.Unmarshal(payload, &token); err != nil {
return nil, fmt.Errorf("oidc: failed to unmarshal claims: %v", err)
@@ -254,6 +275,7 @@ func (v *IDTokenVerifier) Verify(ctx context.Context, rawIDToken string) (*IDTok
AccessTokenHash: token.AtHash,
claims: payload,
distributedClaims: distributedClaims,
+ sigAlgorithm: sig.Header.Algorithm,
}
// Check issuer.
@@ -306,45 +328,6 @@ func (v *IDTokenVerifier) Verify(ctx context.Context, rawIDToken string) (*IDTok
}
}
- if v.config.InsecureSkipSignatureCheck {
- return t, nil
- }
-
- var supportedSigAlgs []jose.SignatureAlgorithm
- for _, alg := range v.config.SupportedSigningAlgs {
- supportedSigAlgs = append(supportedSigAlgs, jose.SignatureAlgorithm(alg))
- }
- if len(supportedSigAlgs) == 0 {
- // If no algorithms were specified by both the config and discovery, default
- // to the one mandatory algorithm "RS256".
- supportedSigAlgs = []jose.SignatureAlgorithm{jose.RS256}
- }
- jws, err := jose.ParseSigned(rawIDToken, supportedSigAlgs)
- if err != nil {
- return nil, fmt.Errorf("oidc: malformed jwt: %v", err)
- }
-
- switch len(jws.Signatures) {
- case 0:
- return nil, fmt.Errorf("oidc: id token not signed")
- case 1:
- default:
- return nil, fmt.Errorf("oidc: multiple signatures on id token not supported")
- }
- sig := jws.Signatures[0]
- t.sigAlgorithm = sig.Header.Algorithm
-
- ctx = context.WithValue(ctx, parsedJWTKey, jws)
- gotPayload, err := v.keySet.VerifySignature(ctx, rawIDToken)
- if err != nil {
- return nil, fmt.Errorf("failed to verify signature: %v", err)
- }
-
- // Ensure that the payload returned by the square actually matches the payload parsed earlier.
- if !bytes.Equal(gotPayload, payload) {
- return nil, errors.New("oidc: internal error, payload parsed did not match previous payload")
- }
-
return t, nil
}