Repository navigation
fix(automation): reject a malformed notifications/read body instead of marking everything read - #6236
Draft
shunxinyi-ljs wants to merge 2 commits into
Draft
shunxinyi-ljs wants to merge 2 commits into
shunxinyi-ljs wants to merge 2 commits into
Conversation
The handler discarded the bind error, and MarkRead treats an empty ID list as "everything", so a payload that failed to decode left IDs nil and marked the caller's whole notification history read with 200. An absent body still means "mark all" (io.EOF); only bodies that fail to parse are rejected now.
This branch has not been deployed
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.
Description
POST /api/v1/notifications/readdiscards the JSON bind error:MarkReadtreats an empty ID list as "everything" (WHERE read_at IS NULL, no id filter) — the documented meaning of{}. So a body that fails to decode leftreq.IDsnil, took that branch, and returned 200 after marking the caller's entire notification history read. A typo was indistinguishable from the intended "mark all".Only bodies that fail to parse are rejected now; an absent body still reads as
io.EOFand keeps the documented meaning:Affected inputs:
{"ids": 1},{"ids": "abc"},{"ids": [1, 2]},{"ids": ["ok", 2]},not json at all,{"ids": ["a"]— all now 400input.invalid_argument.Type of Change
Related Issue
Fixes #6237
Testing
TestMarkNotificationsReadRejectsMalformedBodyposts the six bodies above through a gin router with the realmiddleware.ErrorHandlerand asserts 400. The baseline run fails inside(*AutomationHandler).MarkNotificationsReadat theh.notifications.MarkRead(...)call — i.e. the malformed request did reach the service. The test constructs&AutomationHandler{}(nil service), so reaching it panics andgin.Recoveryturns that into 500; the fix passes on the following commit.empty body/{}unchanged: both still mean "mark everything read".internal/handlercannot be built here —internal/agent/toolsneeds cgo +pg_query, unavailable on this Windows machine and in its WSL image. Verification is the CI job shown above (Linux).gofmtclean on touched files;git diff --checkclean.Checklist
git diff --check origin/main...HEADpassesgolangci-lintis not installed here; CI covers it — passing)Screenshots / Recordings
Not a UI change.