|
| 1 | +From 84c7f3d0b9dccb4a20d0ad4de10896d40344ba26 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Kanishk-Bansal < [email protected]> |
| 3 | +Date: Fri, 28 Mar 2025 20:43:26 +0000 |
| 4 | +Subject: [PATCH] CVE-2025-30204 |
| 5 | +Upstream Patch Reference : |
| 6 | +v4 : https://github.com/golang-jwt/jwt/commit/2f0e9add62078527821828c76865661aa7718a84 |
| 7 | +v5 : https://github.com/golang-jwt/jwt/commit/0951d184286dece21f73c85673fd308786ffe9c3 |
| 8 | +--- |
| 9 | + github.com/golang-jwt/jwt/v4/parser.go | 36 +++++++++++++++++++++++--- |
| 10 | + github.com/golang-jwt/jwt/v5/parser.go | 36 +++++++++++++++++++++++--- |
| 11 | + 2 files changed, 66 insertions(+), 6 deletions(-) |
| 12 | + |
| 13 | +diff --git a/vendor/github.com/golang-jwt/jwt/v4/parser.go b/vendor/github.com/golang-jwt/jwt/v4/parser.go |
| 14 | +index c0a6f69..8e7e67c 100644 |
| 15 | +--- a/vendor/github.com/golang-jwt/jwt/v4/parser.go |
| 16 | ++++ b/vendor/github.com/golang-jwt/jwt/v4/parser.go |
| 17 | +@@ -7,6 +7,8 @@ import ( |
| 18 | + "strings" |
| 19 | + ) |
| 20 | + |
| 21 | ++const tokenDelimiter = "." |
| 22 | ++ |
| 23 | + type Parser struct { |
| 24 | + // If populated, only these methods will be considered valid. |
| 25 | + // |
| 26 | +@@ -123,9 +125,10 @@ func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyf |
| 27 | + // It's only ever useful in cases where you know the signature is valid (because it has |
| 28 | + // been checked previously in the stack) and you want to extract values from it. |
| 29 | + func (p *Parser) ParseUnverified(tokenString string, claims Claims) (token *Token, parts []string, err error) { |
| 30 | +- parts = strings.Split(tokenString, ".") |
| 31 | +- if len(parts) != 3 { |
| 32 | +- return nil, parts, NewValidationError("token contains an invalid number of segments", ValidationErrorMalformed) |
| 33 | ++ var ok bool |
| 34 | ++ parts, ok = splitToken(tokenString) |
| 35 | ++ if !ok { |
| 36 | ++ return nil, nil, NewValidationError("token contains an invalid number of segments", ValidationErrorMalformed) |
| 37 | + } |
| 38 | + |
| 39 | + token = &Token{Raw: tokenString} |
| 40 | +@@ -175,3 +178,30 @@ func (p *Parser) ParseUnverified(tokenString string, claims Claims) (token *Toke |
| 41 | + |
| 42 | + return token, parts, nil |
| 43 | + } |
| 44 | ++ |
| 45 | ++// splitToken splits a token string into three parts: header, claims, and signature. It will only |
| 46 | ++// return true if the token contains exactly two delimiters and three parts. In all other cases, it |
| 47 | ++// will return nil parts and false. |
| 48 | ++func splitToken(token string) ([]string, bool) { |
| 49 | ++ parts := make([]string, 3) |
| 50 | ++ header, remain, ok := strings.Cut(token, tokenDelimiter) |
| 51 | ++ if !ok { |
| 52 | ++ return nil, false |
| 53 | ++ } |
| 54 | ++ parts[0] = header |
| 55 | ++ claims, remain, ok := strings.Cut(remain, tokenDelimiter) |
| 56 | ++ if !ok { |
| 57 | ++ return nil, false |
| 58 | ++ } |
| 59 | ++ parts[1] = claims |
| 60 | ++ // One more cut to ensure the signature is the last part of the token and there are no more |
| 61 | ++ // delimiters. This avoids an issue where malicious input could contain additional delimiters |
| 62 | ++ // causing unecessary overhead parsing tokens. |
| 63 | ++ signature, _, unexpected := strings.Cut(remain, tokenDelimiter) |
| 64 | ++ if unexpected { |
| 65 | ++ return nil, false |
| 66 | ++ } |
| 67 | ++ parts[2] = signature |
| 68 | ++ |
| 69 | ++ return parts, true |
| 70 | ++} |
| 71 | +diff --git a/vendor/github.com/golang-jwt/jwt/v5/parser.go b/vendor/github.com/golang-jwt/jwt/v5/parser.go |
| 72 | +index ecf99af..054c7eb 100644 |
| 73 | +--- a/vendor/github.com/golang-jwt/jwt/v5/parser.go |
| 74 | ++++ b/vendor/github.com/golang-jwt/jwt/v5/parser.go |
| 75 | +@@ -8,6 +8,8 @@ import ( |
| 76 | + "strings" |
| 77 | + ) |
| 78 | + |
| 79 | ++const tokenDelimiter = "." |
| 80 | ++ |
| 81 | + type Parser struct { |
| 82 | + // If populated, only these methods will be considered valid. |
| 83 | + validMethods []string |
| 84 | +@@ -136,9 +138,10 @@ func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyf |
| 85 | + // It's only ever useful in cases where you know the signature is valid (since it has already |
| 86 | + // been or will be checked elsewhere in the stack) and you want to extract values from it. |
| 87 | + func (p *Parser) ParseUnverified(tokenString string, claims Claims) (token *Token, parts []string, err error) { |
| 88 | +- parts = strings.Split(tokenString, ".") |
| 89 | +- if len(parts) != 3 { |
| 90 | +- return nil, parts, newError("token contains an invalid number of segments", ErrTokenMalformed) |
| 91 | ++ var ok bool |
| 92 | ++ parts, ok = splitToken(tokenString) |
| 93 | ++ if !ok { |
| 94 | ++ return nil, nil, newError("token contains an invalid number of segments", ErrTokenMalformed) |
| 95 | + } |
| 96 | + |
| 97 | + token = &Token{Raw: tokenString} |
| 98 | +@@ -196,6 +199,33 @@ func (p *Parser) ParseUnverified(tokenString string, claims Claims) (token *Toke |
| 99 | + return token, parts, nil |
| 100 | + } |
| 101 | + |
| 102 | ++// splitToken splits a token string into three parts: header, claims, and signature. It will only |
| 103 | ++// return true if the token contains exactly two delimiters and three parts. In all other cases, it |
| 104 | ++// will return nil parts and false. |
| 105 | ++func splitToken(token string) ([]string, bool) { |
| 106 | ++ parts := make([]string, 3) |
| 107 | ++ header, remain, ok := strings.Cut(token, tokenDelimiter) |
| 108 | ++ if !ok { |
| 109 | ++ return nil, false |
| 110 | ++ } |
| 111 | ++ parts[0] = header |
| 112 | ++ claims, remain, ok := strings.Cut(remain, tokenDelimiter) |
| 113 | ++ if !ok { |
| 114 | ++ return nil, false |
| 115 | ++ } |
| 116 | ++ parts[1] = claims |
| 117 | ++ // One more cut to ensure the signature is the last part of the token and there are no more |
| 118 | ++ // delimiters. This avoids an issue where malicious input could contain additional delimiters |
| 119 | ++ // causing unecessary overhead parsing tokens. |
| 120 | ++ signature, _, unexpected := strings.Cut(remain, tokenDelimiter) |
| 121 | ++ if unexpected { |
| 122 | ++ return nil, false |
| 123 | ++ } |
| 124 | ++ parts[2] = signature |
| 125 | ++ |
| 126 | ++ return parts, true |
| 127 | ++} |
| 128 | ++ |
| 129 | + // DecodeSegment decodes a JWT specific base64url encoding. This function will |
| 130 | + // take into account whether the [Parser] is configured with additional options, |
| 131 | + // such as [WithStrictDecoding] or [WithPaddingAllowed]. |
| 132 | +-- |
| 133 | +2.45.2 |
| 134 | + |
0 commit comments