Skip to content

Commit 90526d0

Browse files
committed
fix(jwt): no need to verify typ header value
#20
1 parent e461837 commit 90526d0

3 files changed

Lines changed: 2 additions & 19 deletions

File tree

src/joserfc/errors.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,5 @@ class InvalidTokenError(JoseError):
118118
description = "The token is not valid yet"
119119

120120

121-
class InvalidTypeError(JoseError):
122-
error = "invalid_type"
123-
description = 'The "typ" value in header is invalid'
124-
125-
126121
class InvalidPayloadError(JoseError):
127122
error = "invalid_payload"

src/joserfc/jwt.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
decrypt_compact,
1414
)
1515
from .jwk import KeyFlexible
16-
from .errors import InvalidTypeError, InvalidPayloadError
16+
from .errors import InvalidPayloadError
1717
from .util import to_bytes
1818
from .registry import Header
1919

@@ -93,13 +93,7 @@ def decode(
9393
except (TypeError, ValueError):
9494
raise InvalidPayloadError()
9595

96-
token = Token(header, claims)
97-
typ = token.header.get("typ")
98-
# https://www.rfc-editor.org/rfc/rfc7519#section-5.1
99-
# If present, it is RECOMMENDED that its value be "JWT".
100-
if typ and typ != "JWT":
101-
raise InvalidTypeError()
102-
return token
96+
return Token(header, claims)
10397

10498

10599
def _decode_jwe(

tests/jwt/test_jwt.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from joserfc.jwk import OctKey
44
from joserfc.errors import (
55
InvalidPayloadError,
6-
InvalidTypeError,
76
MissingClaimError,
87
)
98

@@ -14,11 +13,6 @@ def test_invalid_payload(self):
1413
data = jws.serialize_compact({"alg": "HS256"}, b"hello", key)
1514
self.assertRaises(InvalidPayloadError, jwt.decode, data, key)
1615

17-
def test_invalid_type(self):
18-
key = OctKey.import_key("secret")
19-
data = jws.serialize_compact({"alg": "HS256", "typ": "JOSE"}, b'{"iss":"a"}', key)
20-
self.assertRaises(InvalidTypeError, jwt.decode, data, key)
21-
2216
def test_claims_registry(self):
2317
key = OctKey.import_key("secret")
2418
data = jwt.encode({"alg": "HS256"}, {"sub": "a"}, key)

0 commit comments

Comments
 (0)