Skip to content

Fix: Return 400 for an invalid DELETE /api/v1/messages body - #766

Merged
axllent merged 1 commit into
axllent:developfrom
yamamoto7:fix/delete-messages-invalid-body
Nov 3, 2026
Merged

axllent merged 1 commit into
axllent:developfrom
yamamoto7:fix/delete-messages-invalid-body

Conversation

@yamamoto7

Copy link
Copy Markdown
Contributor

Summary

DELETE /api/v1/messages treats every JSON decode error as a request to delete all messages, so a malformed body empties the mailbox and returns 200 ok. This PR returns 400 for those bodies and deletes nothing, as PUT /api/v1/messages already does.

Reproduced against develop (984165e) and this branch, each case starting with 3 messages:

Request body Before After
{ids:[abc]} 200, 0 left 400, 3 left
{"IDs":"abc"} 200, 0 left 400, 3 left
{"IDs":["abc" (truncated) 200, 0 left 400, 3 left
'{ids:[<ID>]}' (from #88) 200, 0 left 400, 3 left
ids=<ID> (form encoded) 200, 0 left 400, 3 left
Content-Length: 500, connection dropped mid-body 200, 0 left 400, 3 left
No body, {}, {"IDs":[]} 200, 0 left unchanged
{"IDs":["<ID>"]} 200, 2 left unchanged

Fix

DeleteMessages now returns the decode error as a 400, except for io.EOF, which is what an empty body gives. A body cut off partway gives io.ErrUnexpectedEOF, so it is rejected too.

Not changed: valid JSON with the wrong key, such as {"message_ids":["..."]}, still deletes everything, because it counts as "no IDs provided". decoder.DisallowUnknownFields() would reject it (I tried it), but it would also reject clients that send extra fields, so I left it for you to decide.

Related issues

#765

Type of change

  • Bug fix
  • New feature
  • Refactor / code cleanup
  • Documentation
  • Other (please describe):

Test plan

  • TestAPIv1Messages now covers invalid bodies and a truly empty body. The old "empty body" step sent {}, so I renamed it. On the parent commit it fails with Expected an error for invalid body {ids:[abc]}.
  • gofmt -s, go vet, golangci-lint on ./server/, ./server/apiv1/, and the Go test packages from .github/workflows/tests.yml pass on SQLite. ./internal/storage, ./server and ./server/apiv1 pass on rqlite/rqlite:latest (v10.6.6).
  • npm test, npm run lint, npm run package pass, and the Playwright e2e tests (46) pass in the Playwright Linux image.
  • Sent 24 request bodies to a local build, before and after. Only undecodable bodies and dropped connections changed.
  • Checked Delete all, Delete selected, search Delete all and delete from the message view in Chromium, before and after. "Delete all" sends no body, so it still works.

AI assistance disclosure

Please indicate whether AI tools (e.g. Claude, Copilot, ChatGPT, Cursor) were used in preparing this pull request:

  • No AI was used
  • Assisted — AI was used for suggestions, explanations, or small snippets, but the code was primarily written and understood by me
  • Extensive — AI generated a significant portion of the code in this PR

If AI was used, briefly describe how (which tools, and for what parts):

Checklist

  • I have tested my changes locally
  • I have read and understood all code being submitted (including any AI-generated portions)
  • Documentation has been updated where relevant

@axllent
axllent merged commit 8e7a084 into axllent:develop Nov 3, 2026
8 checks passed
@axllent

axllent commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Thank you

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