|
| 1 | +From 703e6193f4462ef2f617387c01798035fe620250 Mon Sep 17 00:00:00 2001 |
| 2 | +From: jykanase < [email protected]> |
| 3 | +Date: Fri, 28 Mar 2025 04:25:18 +0000 |
| 4 | +Subject: [PATCH] CVE-2024-51744 |
| 5 | + |
| 6 | +Upstream patch reference: https://github.com/golang-jwt/jwt/commit/7b1c1c00a171c6c79bbdb40e4ce7d197060c1c2c |
| 7 | +--- |
| 8 | + vendor/github.com/dgrijalva/jwt-go/parser.go | 37 +++++++++++--------- |
| 9 | + 1 file changed, 21 insertions(+), 16 deletions(-) |
| 10 | + |
| 11 | +diff --git a/vendor/github.com/dgrijalva/jwt-go/parser.go b/vendor/github.com/dgrijalva/jwt-go/parser.go |
| 12 | +index d6901d9..9fddb7d 100644 |
| 13 | +--- a/vendor/github.com/dgrijalva/jwt-go/parser.go |
| 14 | ++++ b/vendor/github.com/dgrijalva/jwt-go/parser.go |
| 15 | +@@ -13,13 +13,21 @@ type Parser struct { |
| 16 | + SkipClaimsValidation bool // Skip claims validation during token parsing |
| 17 | + } |
| 18 | + |
| 19 | +-// Parse, validate, and return a token. |
| 20 | +-// keyFunc will receive the parsed token and should return the key for validating. |
| 21 | +-// If everything is kosher, err will be nil |
| 22 | ++// Parse parses, validates, verifies the signature and returns the parsed token. keyFunc will |
| 23 | ++// receive the parsed token and should return the key for validating. |
| 24 | + func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error) { |
| 25 | + return p.ParseWithClaims(tokenString, MapClaims{}, keyFunc) |
| 26 | + } |
| 27 | + |
| 28 | ++// ParseWithClaims parses, validates, and verifies like Parse, but supplies a default object |
| 29 | ++// implementing the Claims interface. This provides default values which can be overridden and |
| 30 | ++// allows a caller to use their own type, rather than the default MapClaims implementation of |
| 31 | ++// Claims. |
| 32 | ++// |
| 33 | ++// Note: If you provide a custom claim implementation that embeds one of the standard claims (such |
| 34 | ++// as RegisteredClaims), make sure that a) you either embed a non-pointer version of the claims or |
| 35 | ++// b) if you are using a pointer, allocate the proper memory for it before passing in the overall |
| 36 | ++// claims, otherwise you might run into a panic. |
| 37 | + func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc) (*Token, error) { |
| 38 | + token, parts, err := p.ParseUnverified(tokenString, claims) |
| 39 | + if err != nil { |
| 40 | +@@ -56,12 +64,17 @@ func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyf |
| 41 | + return token, &ValidationError{Inner: err, Errors: ValidationErrorUnverifiable} |
| 42 | + } |
| 43 | + |
| 44 | ++ // Perform validation |
| 45 | ++ token.Signature = parts[2] |
| 46 | ++ if err := token.Method.Verify(strings.Join(parts[0:2], "."), token.Signature, key); err != nil { |
| 47 | ++ return token, &ValidationError{Inner: err, Errors: ValidationErrorSignatureInvalid} |
| 48 | ++ } |
| 49 | ++ |
| 50 | + vErr := &ValidationError{} |
| 51 | + |
| 52 | + // Validate Claims |
| 53 | + if !p.SkipClaimsValidation { |
| 54 | + if err := token.Claims.Valid(); err != nil { |
| 55 | +- |
| 56 | + // If the Claims Valid returned an error, check if it is a validation error, |
| 57 | + // If it was another error type, create a ValidationError with a generic ClaimsInvalid flag set |
| 58 | + if e, ok := err.(*ValidationError); !ok { |
| 59 | +@@ -69,22 +82,14 @@ func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyf |
| 60 | + } else { |
| 61 | + vErr = e |
| 62 | + } |
| 63 | ++ return token, vErr |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | +- // Perform validation |
| 68 | +- token.Signature = parts[2] |
| 69 | +- if err = token.Method.Verify(strings.Join(parts[0:2], "."), token.Signature, key); err != nil { |
| 70 | +- vErr.Inner = err |
| 71 | +- vErr.Errors |= ValidationErrorSignatureInvalid |
| 72 | +- } |
| 73 | +- |
| 74 | +- if vErr.valid() { |
| 75 | +- token.Valid = true |
| 76 | +- return token, nil |
| 77 | +- } |
| 78 | ++ // No errors so far, token is valid. |
| 79 | ++ token.Valid = true |
| 80 | + |
| 81 | +- return token, vErr |
| 82 | ++ return token, nil |
| 83 | + } |
| 84 | + |
| 85 | + // WARNING: Don't use this method unless you know what you're doing |
| 86 | +-- |
| 87 | +2.45.2 |
| 88 | + |
0 commit comments