Encrypt annotation data payloads on encrypted channels - #680
Draft
SimonWoolf wants to merge 1 commit into
Draft
Conversation
Annotation had no encrypt() method, so annotation data was published in plaintext even when the channel had a cipher configured, while Message and PresenceMessage were correctly encrypted before serialisation. The REST get() path compounded this by hardcoding cipher=None when building its response handler, so it could not have decrypted an encrypted annotation either. (The realtime receive path already passed the channel's cipher.) Add Annotation.encrypt(), mirroring Message.encrypt(), and call it from both publish paths. Pass the channel's cipher when decoding REST get() responses. Unlike messages, annotations commonly carry no data at all, so encrypt() returns early rather than failing in TypedBuffer.from_obj(). The docstrings claiming annotations are not encrypted because the server needs to parse them for summarisation were correct for the original early-preview API, where aggregation read JSON data payloads. That changed before public release, when aggregation moved to the count field specifically so the server would not have to read payloads. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Annotationhad noencrypt()method at all, so annotationdatawas published in plaintext even when the channel had a cipher configured — whileMessage(ably/types/message.py:235) andPresenceMessage(ably/types/presence.py:123) were correctly encrypted before serialisation at their publish sites (ably/rest/channel.py:80,ably/realtime/channel.py:415).The REST
get()path compounded it by hardcodingcipher=Nonewhen building its response handler, so it could not have decrypted an encrypted annotation either. The realtime receive path (ably/realtime/channel.py:768) already passedcipher=self.ciphercorrectly, so it was only the REST direction that was broken.Changes
Annotation.encrypt(), mirroringMessage.encrypt().rest/annotations.py,realtime/annotations.py), guarded onchannel.cipherlike the message paths are.get()responses.One deliberate difference from
Message.encrypt(): annotations very commonly carry nodataat all — a reaction is fully described by itsname, and every existing annotation test passesdata=None.Message.encrypt()would raiseTypeError: Unexpected object type <class 'NoneType'>fromTypedBuffer.from_obj()on that input; it just never gets called that way in practice.Annotation.encrypt()returns early instead. Worth notingMessage.encrypt()has the same latent flaw if it is ever called withdata=None, but I have left it alone.🤖 Generated with Claude Code