Repository navigation
feat: verify SNS deliveries and reject a token without a user id - #137
Merged
Merged
Conversation
Add Webhook.verifyAndParseSns and StreamSDKClient.verifyAndParseSns, which verify the signature message attribute on SNS HTTP(S) deliveries before parsing, and correct the parseSns and parseSqs docs. TokenBuilder.createToken rejects a null, empty or blank userId: a secret-signed token without a user id authenticates as the server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Submit a pull request
CLA
Description of the pull request
Tickets: https://linear.app/stream/issue/CHA-7200, https://linear.app/stream/issue/CHA-7202
Webhook.verifyAndParseSns(notificationBody, secret)andclient.verifyAndParseSns(...)verify thesignaturemessage attribute (the same HMAC asX-Signature) on SNS HTTP(S) deliveries before parsing. TheparseSnsandparseSqsJavadoc no longer says IAM authenticates SNS HTTP deliveries.TokenBuilder.createToken(and soCall.createSRTCredentials) throwsIllegalArgumentExceptionfor a null, empty or blankuserId. A secret-signed token without a user id authenticates as the server.How to verify:
./gradlew spotlessCheck test --tests 'io.getstream.WebhookTest' --tests 'io.getstream.services.framework.TokenBuilderTest'Webhook.java,WebhookTest.javaandsrc/test/resources/fixtures/webhooks/are generated by GetStream/chat#21473 at openapi-v241.18.5. Merge after it, so the next regeneration produces the same files.BEGIN_COMMIT_OVERRIDE
feat: add
verifyAndParseSnsto verify thesignatureattribute on SNS HTTP(S) deliveries before parsingfix:
TokenBuilder.createTokenrejects a null, empty or blankuserIdinstead of minting a server-side tokenfix:
Webhook.verifySignaturereturns false for a null or empty secret or signature instead of throwingEND_COMMIT_OVERRIDE
Note
Medium Risk
Touches webhook authentication and token minting; behavior change for callers that passed blank userIds, with new security paths covered by conformance tests.
Overview
Adds
Webhook.verifyAndParseSns(andStreamSDKClient.verifyAndParseSns) for SNS HTTP(S) subscriptions: unwrap the envelope, decode the inner message, verify the HMAC inMessageAttributes.signature(same asX-Signature), then parse.parseSns/parseSqsstay unsigned and their docs now say to use them only for IAM-protected queue paths, not public SNS POSTs.verifySignaturenow returnsfalsewhen the secret or signature is null or empty, and conformance fixtures/tests cover SNS verification and forged/missing signatures.TokenBuilder.createTokenthrowsIllegalArgumentExceptionfor null, empty, or blankuserIdso the SDK no longer mints a server-authenticating token by mistake.Reviewed by Cursor Bugbot for commit 06d31d7. Bugbot is set up for automated code reviews on this repo. Configure here.