Repository navigation
Don't mutate the caller's events in triggerBatch - #251
Open
OsamaAnsar wants to merge 1 commit into
Open
OsamaAnsar wants to merge 1 commit into
OsamaAnsar wants to merge 1 commit into
Conversation
triggerBatch overwrote data on each event in the array it was given with the JSON string, or the ciphertext for private-encrypted- channels. Triggering the same batch twice (for example when retrying) therefore encrypted the data a second time, and receivers could not decrypt it. Build new event objects for the request body instead, as trigger() already does.
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.
Summary
triggerBatchmutates the array the caller passes in.lib/events.js:57-61overwritesbatch[i].datain place with the JSON string, or with the ciphertext forprivate-encrypted-channels.Effects:
poststubbed to capture the body: the first call decrypts to{"hello":"world"}, the second call decrypts to the first call's ciphertext JSON string.dataobject silently becomes a string.trigger()doesn't have this problem: it builds a neweventobject for each request.Fix
triggerBatchnow builds a new array of new event objects ({ ...event, data: <encoded> }) and posts that, leaving the caller's events untouched. The request body is the same as before (same keys, same order), andencrypt/ensureJSONare called exactly as before. The copy is shallow, which is enough since only the top-leveldataproperty is replaced.Test plan
Added to
tests/integration/pusher/trigger.js:#triggerBatch(plain client): the events passed in are unchanged after the call, anddatais still an object.#triggerBatch(withencryptionMasterKey): the same batch is triggered twice, and both request bodies contain an encrypted event that decrypts to the original data. The caller's events are still unchanged afterwards.Both fail without the fix (I reverted only
lib/events.jsand re-ran: 2 failing, the second with the encrypted data decrypting to the ciphertext JSON string rather than the original data) and pass with it.Also ran, on Node 24.19.0:
npm run local-test(tests/integration/**): 131 passing, 0 failingnpm run lint(eslint + prettier --check): cleanNot run:
tests/remote/**(part ofnpm test), since it needs real Pusher credentials.CHANGELOG
triggerBatchno longer modifies the events passed in, so a batch can be reused or retried without double-encrypting events on encrypted channels.