Skip to content

Commit 5263e49

Browse files
The subject field of grants needs to be a string, not an array.
jpadilla/pyjwt#1005 This was always in the jwt specification, but was not enforced in the jwt python library until recently.
1 parent ab822eb commit 5263e49

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/delegate.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,19 @@ def handler(event, context: LambdaContext) -> dict:
104104
if not domains.issubset(refresh_token['domains']):
105105
return bad_request('', 'domain requested outside refresh_token')
106106

107+
# Validate no commas in subject or existing sub chain to avoid join ambiguity
108+
if ',' in subject:
109+
return bad_request('', 'subject contains invalid comma')
110+
existing_sub = refresh_token.get('sub', [])
111+
if any(',' in s for s in existing_sub if isinstance(s, str)):
112+
return bad_request('', 'existing sub chain contains invalid comma')
113+
107114
delegate_token = {
108115
'iat': int(time.time()),
109116
'exp': exp,
110117
'domains': list(domains),
111118
'azp': refresh_token['azp'], # Authorized Party
112-
'sub': refresh_token.get('sub', []) + [subject], # subject
119+
'sub': ', '.join(existing_sub + [subject]), # sub must be string adhering to jwt spec: https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2
113120
}
114121
logger.info({"message": "Issuing JWT", "jwt": delegate_token})
115122
raw_delegate_token = jwt.encode(

src/use_grant.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def handler(event, context) -> dict:
2020
raw_grant,
2121
get_grant_jwt_secret(),
2222
algorithms=['HS256'],
23+
options={'require': [], 'verify_sub': False}, # Disable validation for now until sub field are all strings.
2324
)
2425
assert 'exp' in grant
2526
assert 'azp' in grant

0 commit comments

Comments
 (0)