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