Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert and retract typ check #150

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading