Skip to content

Single broadcast API mangles JSON bodies that aren't plain objects #2378

Open

Description

@mandar1045

TL;DR:
POST /api/broadcast/:topic/events/:event works out the payload type from keys in the parsed body instead of from Content-Type, so two kinds of JSON body come out wrong:

  • A body that isn't an object ([1,2,3], "hello", 42) returns 202, but subscribers get {"_json": [1,2,3]}. That's how Plug wraps non-object JSON, and it's passed straight through.
  • An object with a _binary key is treated as a binary payload: v2 subscribers get a binary frame containing only the _binary value, and v1 subscribers get nothing.
curl -X POST "$REALTIME_URL/api/broadcast/room/events/msg" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '[1,2,3]'
# subscribers receive {"_json":[1,2,3]}

curl -X POST "$REALTIME_URL/api/broadcast/room/events/msg" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"_binary":"x","other":1}'
# v2 subscribers get a binary "x", v1 subscribers get nothing

#1864 says the content type decides the payload type, and the schema describes the body as a JSON object, so non-object bodies should probably get a 422.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions