Skip to content

Commit 6ccf0a3

Browse files
Add comment about authenticated push JWT token validation. (GoogleCloudPlatform#5090)
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.
1 parent 2a15f9b commit 6ccf0a3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

appengine-java8/pubsub/src/main/java/com/example/appengine/pubsub/PubSubAuthenticatedPush.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,16 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp)
7777
// messsages have prompted a singple push server to handle them, in which
7878
// case they would all share the same token for a limited time window.
7979
GoogleIdToken idToken = verifier.verify(authorization);
80+
81+
GoogleIdToken.Payload payload = idToken.getPayload();
82+
// IMPORTANT: you should validate claim details not covered by signature
83+
// and audience verification above, including:
84+
// - Ensure that `payload.getEmail()` is equal to the expected service
85+
// account set up in the push subscription settings.
86+
// - Ensure that `payload.getEmailVerified()` is set to true.
87+
8088
messageRepository.saveToken(authorization);
81-
messageRepository.saveClaim(idToken.getPayload().toPrettyString());
89+
messageRepository.saveClaim(payload.toPrettyString());
8290
// parse message object from "message" field in the request body json
8391
// decode message data from base64
8492
Message message = getMessage(req);

0 commit comments

Comments
 (0)