Skip to content

Commit 5c6c847

Browse files
committed
Compact signing always protects all headers.
1 parent adf41c9 commit 5c6c847

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/cryptojwt/jws/jws.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def verify_compact_verbose(self, jws=None, keys=None, allow_none=False,
245245
"Verified message using key with kid=%s" % key.kid)
246246
self.msg = jwt.payload()
247247
self.key = key
248+
self._protected_headers = jwt.headers.copy()
248249
return {'msg': self.msg, 'key': key}
249250

250251
raise BadSignature()

tests/test_06_jws.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,9 @@ def test_signer_protected_headers():
524524
_rj = JWS(alg='ES256')
525525
info = _rj.verify_compact(_jwt, [_pub_key])
526526
assert info == payload
527+
# Protected by default
528+
protected['alg'] = "ES256"
529+
assert _rj.protected_headers() == protected
527530

528531

529532
def test_verify_protected_headers():
@@ -579,10 +582,10 @@ def test_verify_json():
579582
vkeys = [ECKey().load_key(eck.public_key())]
580583
_jws = JWS()
581584
assert _jws.verify_json(_jwt, keys=vkeys)
582-
# alg is always protected by default
583585
_protected = _jws.protected_headers()
584586
assert set(_protected.keys()) == {'foo', 'alg'}
585587
assert _protected['foo'] == protected_headers["foo"]
588+
# alg is always protected by default
586589
assert _protected['alg'] == "ES256"
587590

588591

0 commit comments

Comments
 (0)