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