Skip to content

Commit c81a944

Browse files
fayssalmartanigcpgcf-merge-on-green[bot]engelke
authored
Add comment about authenticated push JWT token validation (GoogleCloudPlatform#5729)
This snippet is used in the Cloud Pub/Sub docs (https://cloud.google.com/pubsub/docs/push#validating_tokens) and many users are not aware that signature verification of the token is not enough, the claim needs to be validated also. Co-authored-by: gcf-merge-on-green[bot] <60162190+gcf-merge-on-green[bot]@users.noreply.github.com> Co-authored-by: Charles Engelke <engelke@google.com>
1 parent 50afaf0 commit c81a944

File tree

1 file changed

+7
-0
lines changed
  • appengine/standard_python3/pubsub

1 file changed

+7
-0
lines changed

appengine/standard_python3/pubsub/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ def receive_messages_handler():
8585
# case they would all share the same token for a limited time window.
8686
claim = id_token.verify_oauth2_token(token, requests.Request(),
8787
audience='example.com')
88+
89+
# IMPORTANT: you should validate claim details not covered by signature
90+
# and audience verification above, including:
91+
# - Ensure that `claim["email"]` is equal to the expected service
92+
# account set up in the push subscription settings.
93+
# - Ensure that `claim["email_verified"]` is set to true.
94+
8895
CLAIMS.append(claim)
8996
except Exception as e:
9097
return 'Invalid token: {}\n'.format(e), 400

0 commit comments

Comments
 (0)