Skip to content

fix(automation): reject a malformed notifications/read body instead of marking everything read - #6236

Draft
shunxinyi-ljs wants to merge 2 commits into
Tencent:mainfrom
shunxinyi-ljs:fix/automation-notification-bind-error
Draft

shunxinyi-ljs wants to merge 2 commits into
Tencent:mainfrom
shunxinyi-ljs:fix/automation-notification-bind-error

Conversation

@shunxinyi-ljs

@shunxinyi-ljs shunxinyi-ljs commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

POST /api/v1/notifications/read discards the JSON bind error:

var req markNotificationsReadRequest
_ = c.ShouldBindJSON(&req)
if err := h.notifications.MarkRead(c.Request.Context(), req.IDs); err != nil { ... }

MarkRead treats 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 left req.IDs nil, 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.EOF and keeps the documented meaning:

if err := c.ShouldBindJSON(&req); err != nil && !stderrors.Is(err, io.EOF) {
    _ = c.Error(errors.NewBadRequestError("Invalid request parameters: " + err.Error()))
    return
}

Affected inputs: {"ids": 1}, {"ids": "abc"}, {"ids": [1, 2]}, {"ids": ["ok", 2]}, not json at all, {"ids": ["a"] — all now 400 input.invalid_argument.

Type of Change

  • 🐛 Bug fix

Related Issue

Fixes #6237

Testing

  • Regression test added first, on its own commit, so CI shows it failing on the current code: TestMarkNotificationsReadRejectsMalformedBody posts the six bodies above through a gin router with the real middleware.ErrorHandler and asserts 400. The baseline run fails inside (*AutomationHandler).MarkNotificationsRead at the h.notifications.MarkRead(...) call — i.e. the malformed request did reach the service. The test constructs &AutomationHandler{} (nil service), so reaching it panics and gin.Recovery turns that into 500; the fix passes on the following commit.
  • empty body / {} unchanged: both still mean "mark everything read".
  • Not run on this host: internal/handler cannot be built here — internal/agent/tools needs cgo + pg_query, unavailable on this Windows machine and in its WSL image. Verification is the CI job shown above (Linux).
  • gofmt clean on touched files; git diff --check clean.

Checklist

  • git diff --check origin/main...HEAD passes
  • Changed source files are formatted
  • Targeted tests for the changed packages pass (CI, Linux)
  • Diff-scoped lint (golangci-lint is not installed here; CI covers it — passing)
  • Full-repository checks (not runnable on this host, see above)
  • Self-reviewed the code
  • Added tests covering the change
  • Updated related documentation (comment states the empty-body contract)
  • Breaking changes: no — the only changed path is a request that used to be silently misapplied.

Screenshots / Recordings

Not a UI change.

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

No deployments
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.

[Bug]: notifications/read marks every notification read when the request body fails to parse

1 participant