Skip to content

Commit 9845546

Browse files
Merge pull request #50 from vrtdev/feature/grant-subject-string
The subject field of grants needs to be a string, not an array.
2 parents ab822eb + 79b9a6e commit 9845546

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/delegate.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,22 @@ 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 new subject to avoid future join ambiguity
108+
if ',' in subject:
109+
return bad_request('', 'subject contains invalid comma')
110+
111+
existing_sub = refresh_token.get('sub', [])
112+
if isinstance(existing_sub, str):
113+
existing_sub = [x.strip() for x in existing_sub.split(',')] # Convert string to list
114+
elif isinstance(existing_sub, list):
115+
pass # Already a list, no change needed
116+
107117
delegate_token = {
108118
'iat': int(time.time()),
109119
'exp': exp,
110120
'domains': list(domains),
111121
'azp': refresh_token['azp'], # Authorized Party
112-
'sub': refresh_token.get('sub', []) + [subject], # subject
122+
'sub': ','.join(existing_sub + [subject]), # sub must be string adhering to jwt spec: https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2
113123
}
114124
logger.info({"message": "Issuing JWT", "jwt": delegate_token})
115125
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)