Skip to content

Commit 641dafe

Browse files
authored
Don't mutate options dictionary in .decode_complete()
Fixes jpadilla#679
1 parent 1f1fe15 commit 641dafe

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

jwt/api_jwt.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ def decode_complete(
7171
options: Optional[Dict] = None,
7272
**kwargs,
7373
) -> Dict[str, Any]:
74-
if options is None:
75-
options = {"verify_signature": True}
76-
else:
77-
options.setdefault("verify_signature", True)
74+
options = dict(options or {}) # shallow-copy or initialize an empty dict
75+
options.setdefault("verify_signature", True)
7876

7977
# If the user has set the legacy `verify` argument, and it doesn't match
8078
# what the relevant `options` entry for the argument is, inform the user

tests/test_api_jwt.py

+8
Original file line numberDiff line numberDiff line change
@@ -674,3 +674,11 @@ def test_decode_legacy_verify_warning(self, jwt, payload):
674674
jwt.decode(
675675
jwt_message, secret, verify=True, options={"verify_signature": False}
676676
)
677+
678+
def test_decode_no_options_mutation(self, jwt, payload):
679+
options = {"verify_signature": True}
680+
orig_options = options.copy()
681+
secret = "secret"
682+
jwt_message = jwt.encode(payload, secret)
683+
jwt.decode(jwt_message, secret, options=options, algorithms=["HS256"])
684+
assert options == orig_options

0 commit comments

Comments
 (0)