You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
raiseJWSError("No algorithm was specified in the JWS header.")
ifalgorithmsisnotNoneandalgnotinalgorithms:
raiseJWSError("The specified alg value is not allowed")
algorithms may be a plain string here (I have not seen any list normalization before this code is reached). So the expression alg not in algorithms tries to assess whether a boolean (in my scenario) belongs to a string, and fails with an unexpected TypeError.
Even in a normal scenario, with alg being a string, I'm not sure this code is correct either. If algorithms is a plain string, the test will assess whether alg is a substring of algorithms. This looks wrong: its both too permissive and differs from the list behavior.
I'm not familiar with this project, but I believe a fix may look like
ifalgorithmsisnotNone:
ifisinstance(algorithms, str):
algorithms=[algorithms]
ifalgnotinalgorithms:
raiseJWSError("The specified alg value is not allowed")
The text was updated successfully, but these errors were encountered:
The point here might be that "alg" header is expecting to contain a string rather than a boolean. Same with the string value, as it is expecting a valid algorithm. Expecting a proper behaviour on a library might require a proper usage of it, so I don't think this code needs to be added. It may just be a good contribution to the Documentation.
I beg to differ: JWTs are typically sent by clients, and should be considered as untrusted input. I agree the JWT is invalid, but I think a proper exception should be raised, not a generic, undocumented one.
Hello!
I'm having a small issue with functions
jwt.decode
andjws.verify
in a corner-case scenario.I'm playing with a handcrafted, invalid JWT where the
"alg"
header has been set totrue
(not allowed to share, sorry!):When trying to decode or verify it, it fails with a
TypeError
. I'd have expected aJWSError
instead:This happens when the argument
algorithms
is a string. With a list, this seems to behave normally:Still, according to docs, both strings and lists of strings are valid types for
algorithms
:python-jose/jose/jws.py
Lines 48 to 55 in 96474ec
I believe the root issue is here:
python-jose/jose/jws.py
Lines 250 to 257 in 96474ec
algorithms
may be a plain string here (I have not seen any list normalization before this code is reached). So the expressionalg not in algorithms
tries to assess whether a boolean (in my scenario) belongs to a string, and fails with an unexpectedTypeError
.Even in a normal scenario, with
alg
being a string, I'm not sure this code is correct either. Ifalgorithms
is a plain string, the test will assess whetheralg
is a substring ofalgorithms
. This looks wrong: its both too permissive and differs from the list behavior.I'm not familiar with this project, but I believe a fix may look like
The text was updated successfully, but these errors were encountered: