Repository navigation
Fix: Return 400 for an invalid DELETE /api/v1/messages body - #766
Merged
axllent merged 1 commit intoNov 3, 2026
Merged
Conversation
Owner
|
Thank you |
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.
Summary
DELETE /api/v1/messagestreats every JSON decode error as a request to delete all messages, so a malformed body empties the mailbox and returns200 ok. This PR returns 400 for those bodies and deletes nothing, asPUT /api/v1/messagesalready does.Reproduced against
develop(984165e) and this branch, each case starting with 3 messages:{ids:[abc]}{"IDs":"abc"}{"IDs":["abc"(truncated)'{ids:[<ID>]}'(from #88)ids=<ID>(form encoded)Content-Length: 500, connection dropped mid-body{},{"IDs":[]}{"IDs":["<ID>"]}Fix
DeleteMessagesnow returns the decode error as a 400, except forio.EOF, which is what an empty body gives. A body cut off partway givesio.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
Test plan
TestAPIv1Messagesnow covers invalid bodies and a truly empty body. The old "empty body" step sent{}, so I renamed it. On the parent commit it fails withExpected an error for invalid body {ids:[abc]}.gofmt -s,go vet,golangci-linton./server/,./server/apiv1/, and the Go test packages from.github/workflows/tests.ymlpass on SQLite../internal/storage,./serverand./server/apiv1pass onrqlite/rqlite:latest(v10.6.6).npm test,npm run lint,npm run packagepass, and the Playwright e2e tests (46) pass in the Playwright Linux image.AI assistance disclosure
Please indicate whether AI tools (e.g. Claude, Copilot, ChatGPT, Cursor) were used in preparing this pull request:
If AI was used, briefly describe how (which tools, and for what parts):
Checklist