Skip to content

Validate message body ranges and harden receive JSON handling - #867

Open
k-bx wants to merge 2 commits into
bbernhard:masterfrom
k-bx:k-bx/2026-07-10-length-validation
Open

Validate message body ranges and harden receive JSON handling#867
k-bx wants to merge 2 commits into
bbernhard:masterfrom
k-bx:k-bx/2026-07-10-length-validation

Conversation

@k-bx

@k-bx k-bx commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Prevent malformed Signal body ranges from being sent and ensure receive responses remain valid JSON when signal-cli emits logs or diagnostics on stderr.

Changes

  • Validate mentions and text-style ranges against the final message’s UTF-16 length.
  • Validate quote mentions against the quoted message.
  • Reject quote mentions when no quote message is provided.
  • Keep signal-cli stderr out of command responses.
  • Preserve INFO and WARN log severity when classifying stderr.
  • Treat unprefixed stderr diagnostics, such as stack traces, as warnings.
  • Parse newline-delimited receive output as a JSON stream instead of constructing arrays through string concatenation.
  • Return a clear error when receive output contains malformed JSON.
  • Add regression coverage for Unicode offsets, invalid ranges, streamed messages, and stderr classification.

Motivation

Signal body-range offsets use UTF-16 code units. Offsets calculated using UTF-8 bytes—especially around emoji and other non-BMP characters—can produce messages that fail validation when received.

Additionally, combining signal-cli stdout and stderr could mix routine logs or exception output into JSON responses, making otherwise valid receive output unparsable.

Testing

go test ./...

@bbernhard

Copy link
Copy Markdown
Owner

Thanks for the PR!

Can you please do me a favor and split that up in smaller PRs - that makes it easier to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants