Skip to content

Commit b2a7484

Browse files
authored
Merge pull request #354 from lestrrat-go/topic/fix-validation
Fix JWT validation
2 parents b52d95c + a364825 commit b2a7484

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

Changes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
Changes
22
=======
33

4+
v1.1.5 12 Mar 2021
5+
This is a security fix release. The JWT validation could be skipped
6+
for empty values. Upgrade recommended
7+
8+
[Security Fix]
9+
* JWT validation could be skipped for empty fields (#352).
10+
11+
[Bug fixes]
12+
* Allow setting JWT "typ" fields to any value (#351).
13+
* Remove stray replace directive in cmd/jwx/go.mod (#349)
14+
415
v1.1.4 02 Mar 2021
516
[New features]
617
* jwt.ParseRequest, jwt.ParseHeader, jwt.ParseForm have been added.

jwt/jwt_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,19 @@ func TestJWTParseVerify(t *testing.T) {
270270
func TestValidateClaims(t *testing.T) {
271271
t.Parallel()
272272
// GitHub issue #37: tokens are invalid in the second they are created (because Now() is not after IssuedAt())
273+
t.Run("Empty fields", func(t *testing.T) {
274+
token := jwt.New()
275+
276+
if !assert.Error(t, jwt.Validate(token, jwt.WithIssuer("foo")), `token.Validate shold fail`) {
277+
return
278+
}
279+
if !assert.Error(t, jwt.Validate(token, jwt.WithJwtID("foo")), `token.Validate shold fail`) {
280+
return
281+
}
282+
if !assert.Error(t, jwt.Validate(token, jwt.WithSubject("foo")), `token.Validate shold fail`) {
283+
return
284+
}
285+
})
273286
t.Run(jwt.IssuedAtKey+"+skew", func(t *testing.T) {
274287
t.Parallel()
275288
token := jwt.New()

jwt/validate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ func Validate(t Token, options ...ValidateOption) error {
4949

5050
// check for iss
5151
if len(issuer) > 0 {
52-
if v := t.Issuer(); v != "" && v != issuer {
52+
if v := t.Issuer(); v != issuer {
5353
return errors.New(`iss not satisfied`)
5454
}
5555
}
5656

5757
// check for jti
5858
if len(jwtid) > 0 {
59-
if v := t.JwtID(); v != "" && v != jwtid {
59+
if v := t.JwtID(); v != jwtid {
6060
return errors.New(`jti not satisfied`)
6161
}
6262
}
6363

6464
// check for sub
6565
if len(subject) > 0 {
66-
if v := t.Subject(); v != "" && v != subject {
66+
if v := t.Subject(); v != subject {
6767
return errors.New(`sub not satisfied`)
6868
}
6969
}

0 commit comments

Comments
 (0)