The HTTP API relays a PRIVMSG or NOTICE body that is not an array of strings #245

Closed
opened 2026-11-02 06:26:00 +01:00 by clawbot · 1 comment
Collaborator

Over the HTTP API, HandleSendCommand in internal/handlers/api.go keeps a PRIVMSG or NOTICE body and meta as raw JSON. It checks the body only by decoding it into a list of strings, and JSON null decodes into an empty string without an error, so a body such as ["hi", null] passes. handleChannelMsg and handleDirectMsg then relay the raw body and meta to every recipient unchanged. Peers can get a body holding null and a meta that is not an object, though README.md and schema/message.json say body is an array of strings and meta an object. Found by the review of #242; read from the code on 2b1a49e.

Fix (recommended, no owner decision needed): a PRIVMSG or NOTICE whose body is not an array of strings, or whose meta is present and not a JSON object, is refused with HTTP 400 and invalid request body, the answer a request that is not JSON already gets, and nothing is relayed. Change nothing else.

Definition of done

  1. A PRIVMSG or NOTICE over the HTTP API whose body holds anything but strings (null, a number, an object) gets HTTP 400, and no recipient gets a message.
  2. The same for a meta that is present and is not an object.
  3. A valid message is relayed as before.
  4. Tests in internal/handlers for items 1 to 3.
  5. README.md, where it describes the HTTP API's errors for these commands, says what the code now does.
  6. One reviewed PR against next.

Model: opus-5-5

Over the HTTP API, `HandleSendCommand` in `internal/handlers/api.go` keeps a `PRIVMSG` or `NOTICE` body and meta as raw JSON. It checks the body only by decoding it into a list of strings, and JSON `null` decodes into an empty string without an error, so a body such as `["hi", null]` passes. `handleChannelMsg` and `handleDirectMsg` then relay the raw `body` and `meta` to every recipient unchanged. Peers can get a `body` holding `null` and a `meta` that is not an object, though `README.md` and `schema/message.json` say `body` is an array of strings and `meta` an object. Found by the review of https://git.eeqj.de/sneak/neoirc/pulls/242; read from the code on `2b1a49e`. Fix (recommended, no owner decision needed): a `PRIVMSG` or `NOTICE` whose `body` is not an array of strings, or whose `meta` is present and not a JSON object, is refused with HTTP 400 and `invalid request body`, the answer a request that is not JSON already gets, and nothing is relayed. Change nothing else. ## Definition of done 1. A `PRIVMSG` or `NOTICE` over the HTTP API whose `body` holds anything but strings (`null`, a number, an object) gets HTTP 400, and no recipient gets a message. 2. The same for a `meta` that is present and is not an object. 3. A valid message is relayed as before. 4. Tests in `internal/handlers` for items 1 to 3. 5. `README.md`, where it describes the HTTP API's errors for these commands, says what the code now does. 6. One reviewed PR against `next`. Model: opus-5-5
Author
Collaborator

#247 refuses such a PRIVMSG or NOTICE with HTTP 400 invalid request body before anything is relayed, and README.md says so.

Model: opus-5-5

https://git.eeqj.de/sneak/neoirc/pulls/247 refuses such a `PRIVMSG` or `NOTICE` with HTTP 400 `invalid request body` before anything is relayed, and `README.md` says so. Model: opus-5-5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/neoirc#245