Repository navigation
Unify JOSE header merging and validation - #405
Conversation
Remove the Python 3.9 test configuration and environment from the GitHub Actions build workflow. Github moved to Ubuntu 26.04 which dropped 3.9 Assisted-by: Gemini 3.8 Flash Signed-off-by: Simo Sorce <simo@detuned.org>
Extract header merging, critical header checks, and registry validation into shared helper functions in common.py to deduplicate logic between JWS and JWE. Update JWS and JWE implementations to use the new shared helpers and handle InvalidJWSEHeader exceptions. Additionally, mark the 'zip' header parameter as required to be protected in JWE, and add unit tests for common header processing and critical header validation. Assisted-by: Gemini 3.8 Flash Signed-off-by: Simo Sorce <simo@detuned.org>
| if registry is not None: | ||
| for hdr in merged: | ||
| if hdr in registry: | ||
| if not registry.check_header(hdr, target): | ||
| raise InvalidJWSEHeader('Failed header check') |
There was a problem hiding this comment.
Changes look good to me, but I prefer to have the raise directly attached to the outer if, instead of deeply nested as in:
if registry is not None and any(
hdr for hdr in merged
if hdr in registry and not registry.check_header(hdr, target)
):
raise InvalidJWSEHeader('Failed header check')
any still ensures it breaks on first item that is true for the check.
There was a problem hiding this comment.
Sorry if I am old school, but I find your version too hard to read and understand quickly, and reading code is the most important thing ( after using it :-) ).
I find especially bad to use "perl style" if condition after the action, it is really easy to misread that kind of statement, in fact whenever I use AI and it does that I manually undo it.
There was a problem hiding this comment.
I find the generator style easier to read, but as I'm not the only one reading, I'm ok with different views.
Extract header merging, critical header checks, and registry validation into shared helper functions in common.py to deduplicate logic between JWS and JWE.
Update JWS and JWE implementations to use the new shared helpers and handle InvalidJWSEHeader exceptions. Additionally, mark the 'zip' header parameter as required to be protected in JWE, and add unit tests for common header processing and critical header validation.
Note this PR was create in response to a private issue originally reported by @shlee1223 about the fact that the "zip" and "crit" header could be places outside the protected header.
Note that the application always controls what to place in which headers, so the only issue is if a malicious endpoint were to add either header in the unprotected header in transit. The only outcome would like be a denial of service, which his already possible by corrupting the JWE in any way, so this is treated just as a regular bug.