fix(group-translate): prototype-safe lookups, per-chat serialization, strict translate response (v1.0.3)#3
Merged
Merged
Conversation
…rialization, strict translate response (v1.0.3) - ensureParticipant rejects prototype keys (__proto__/constructor/prototype) and uses hasOwnProperty, so a crafted participant/target id can't read or write Object.prototype. - handleMessage is serialized per (session, chat) via a self-evicting promise chain, closing a load->mutate->save race that duplicated the help announcement and dropped participant-language updates. - LibreTranslateClient.translate validates translatedText is a string; a partial/empty response now fails (circuit-counted, excluded from the reply) instead of posting 'undefined'.
# Conflicts: # README.md
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
Three robustness fixes to group-translate, released as v1.0.3.
Prototype-safe participant lookups
ensureParticipantindexedstate.participants[wid]directly. A crafted author/target id of__proto__resolved toObject.prototype(truthy), and the subsequentpushName/enabledwrite landed on the global prototype — prototype pollution. Lookups now reject__proto__/constructor/prototype(a real WhatsApp id never equals these) and useObject.prototype.hasOwnProperty.call(...)for existence.Per-(session, chat) serialization
Concurrent messages for the same group each ran
load → mutate → saveindependently, so the second save clobbered the first (lost participant-language updates) and two first-messages could both send the help announcement.handleMessagenow chains per${sessionId}:${chatId}through a promise lock with a settled tail (no chain poisoning) and self-eviction when the chain drains.Strict translate response
LibreTranslateClient.translatereturneddata.translatedTextfrom a type-asserted body with no runtime check; a partial/empty response became the literal stringundefinedin the group. It now throws whentranslatedTextisn't a string — the call is counted by the circuit breaker and excluded from the combined reply, mirroring the existing/detectguard.Tests
__proto__sender wid does not polluteObject.prototype./translateresponse lackingtranslatedTextrejects.tsc --noEmitclean, bundle packages cleanly.