Skip to content

Commit

Permalink
Revert and retract typ check (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored Nov 8, 2023
1 parent a8f09b7 commit a087c84
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 20 deletions.
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
ErrUnsupportedAlg = errors.New("algorithm is not supported")

// ErrNotJWTType indicates that JWT token type is not JWT.
// Deprecated: leftover after a wrong feature, present due to backward compatibility.
ErrNotJWTType = errors.New("token of not JWT type")

// ErrInvalidFormat indicates that token format is not valid.
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module github.com/cristalhq/jwt/v5

go 1.19

retract (
v5.3.0 // check 'typ' is too strict.
v5.2.0 // check 'typ' is too strict.
)
9 changes: 0 additions & 9 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
)

// Parse decodes a token and verifies it's signature.
func Parse(raw []byte, verifier Verifier) (*Token, error) {
token, err := ParseNoVerify(raw)
if err != nil {
// See: https://github.com/cristalhq/jwt/issues/147
if errors.Is(err, ErrNotJWTType) {
return token, ErrNotJWTType
}
return nil, err
}
if err := verifier.Verify(token); err != nil {
Expand Down Expand Up @@ -82,10 +77,6 @@ func parse(token []byte) (*Token, error) {
header: header,
claims: claims,
}
if !constTimeEqual(tk.header.Type, "JWT") {
// See: https://github.com/cristalhq/jwt/issues/147
return tk, ErrNotJWTType
}
return tk, nil
}

Expand Down
11 changes: 0 additions & 11 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,6 @@ func TestParseAnotherAlgorithm(t *testing.T) {
mustEqual(t, err, ErrAlgorithmMismatch)
}

func TestParseWrongType(t *testing.T) {
const tokenHS256 = `eyJhbGciOiJIUzI1NiIsInR5cCI6IkJPTUJPTSJ9.eyJqdGkiOiJqdXN0IGFuIGlkIiwiYXVkIjoiYXVkaWVuY2UifQ.t5oEdZGp0Qbth7lo5fZlV_o4-r9gMoYBSktXbarjWoo`
verifier := must(NewVerifierHS(HS256, []byte("key")))

token, err := Parse([]byte(tokenHS256), verifier)
mustEqual(t, err, ErrNotJWTType)
if token == nil {
t.Fatal()
}
}

func TestParseMalformed(t *testing.T) {
f := func(got string) {
t.Helper()
Expand Down

0 comments on commit a087c84

Please sign in to comment.