Skip to content

Check presence among claims - #98

Merged
zejn merged 1 commit into
mpdavis:masterfrom
shenek:present_check
Apr 28, 2019
Merged

Check presence among claims#98
zejn merged 1 commit into
mpdavis:masterfrom
shenek:present_check

Conversation

@shenek

Copy link
Copy Markdown
Contributor

Right now if you e.g. trying to validate that subject matches a name and the subject is missing in the claim, the validation passes.

>>>token=jwt.encode(algorithm='HS256', claims={'a': 'b'}, key='secret')
>>>jwt.decode(algorithms=['HS256'], key='secret', subject='my_sub', token=token)
>>> {'a': 'b'}

This patch adds options to suppress such behaviour.

>>>token=jwt.encode(algorithm='HS256', claims={'a': 'b'}, key='secret')
>>>jwt.decode(algorithms=['HS256'], key='secret', subject='my_sub', token=token, options={'present_sub': True})
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"/<my_venvs>/JWT/lib/python3.6/site-packages/jose/jwt.py", line168, indecodeoptions=defaults)
File"/<my_venvs>/JWT/lib/python3.6/site-packages/jose/jwt.py", line469, in_validate_claimsraiseJWTError('missing required key "%s" among claims'%required_claim)
jose.exceptions.JWTError: missingrequiredkey"sub"amongclaims

@codecov-io

codecov-io commented May 30, 2018

Copy link
Copy Markdown

Codecov Report

Merging #98 into master will decrease coverage by 13.1%.
The diff coverage is 100%.

Impacted file tree graph

@@ Coverage Diff @@## master #98 +/- ##
===========================================
- Coverage 96.54% 83.44% -13.11% 
===========================================
Files 14 14 Lines 1071 1075 +4 ===========================================
- Hits 1034 897 -137 - Misses 37 178 +141
Impacted FilesCoverage Δ
jose/jwt.py100% <100%> (ø)⬆️
jose/backends/__init__.py36.36% <0%> (-63.64%)⬇️
jose/backends/ecdsa_backend.py61.33% <0%> (-37.34%)⬇️
jose/backends/pycrypto_backend.py58.47% <0%> (-37.29%)⬇️
jose/backends/rsa_backend.py59.44% <0%> (-37.07%)⬇️
jose/utils.py71.92% <0%> (-15.79%)⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c3c1a6...ec4ad99. Read the comment docs.

@zejn

zejn commented Apr 15, 2019

Copy link
Copy Markdown
Collaborator

Hi, @shenek!

I'm sorry to come back to this after such a long time.

I find your contribution generally sensible. I'd change the "present" word into something less ambiguous - different people might read "present" as either presence or presentation (or even a gift), so I think changing this to "require" might make it a bit more obvious what is meant.

Additionally, if a require_claim options is set, the verify_claim option should automatically be set too.

The pull request should also add an entry to changelog.

Note that if you don't have time to look into this again after all this time, I'll totally understand.

@shenek
shenekforce-pushed the present_check branch 4 times, most recently from ebd206e to 6c0c8f1CompareApril 26, 2019 14:52
@shenek

Copy link
Copy Markdown
ContributorAuthor

Hi,

I tried to resolve your notes. I hope that it is fine now.

Cheers.

@zejn

zejn commented Apr 27, 2019

Copy link
Copy Markdown
Collaborator

Thanks, @shenek, this is pretty awesome.

@zejn
zejn merged commit 739f44f into mpdavis:masterApr 28, 2019
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@shenek@codecov-io@zejn