Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(issues): check blocker visibility on remove_blocked_by (MUL-10206) (#11561)

Multica Evefd9d635d2876
diff --git a/server/internal/handler/issue.go b/server/internal/handler/issue.go
index 986a2de0b6..9182b1d17d 100644
--- a/server/internal/handler/issue.go
+++ b/server/internal/handler/issue.go
@@ -3669,7 +3669,7 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
- if !h.validateBlockerVisibility(w, r, wsUUID, req.BlockedBy) {
+ if !h.validateBlockerVisibility(w, r, wsUUID, blockerIDs) {
return
}
res, err := h.IssueService.Create(r.Context(), service.IssueCreateParams{
@@ -3782,11 +3782,11 @@ func (h *Handler) CreateIssue(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusCreated, CreateIssueResponse{IssueResponse: resp, PRAutoCompleteDisabled: req.PRAutoCompleteDisabled})
}
+// UpdateIssueRequest leaves out blocked_by and remove_blocked_by: they are
+// read only through parseIssueBlockerEdit.
type UpdateIssueRequest struct {
- BlockedBy []string `json:"blocked_by,omitempty"`
- RemoveBlockedBy []string `json:"remove_blocked_by,omitempty"`
- ExpectedRevision *int64 `json:"expected_revision,omitempty"`
- Title *string `json:"title"`
+ ExpectedRevision *int64 `json:"expected_revision,omitempty"`
+ Title *string `json:"title"`
// TitleBase is the title adopted by the editor before producing Title. It
// protects title edits without coupling them to unrelated issue mutations.
TitleBase *string `json:"title_base,omitempty"`
@@ -3931,7 +3931,7 @@ var errIssueFieldConflict = errors.New("issue text field conflict")
// session that could merge it.
var errIssueDescriptionRevisionConflict = errors.New("issue description revision conflict")
-func (h *Handler) updateIssueAtomically(ctx context.Context, workspaceID pgtype.UUID, params db.UpdateIssueParams, rawFields map[string]json.RawMessage, titleBase, descriptionBase *string, descriptionBaseRevision *int64, attachmentIDs []pgtype.UUID, statusKey string, workflowAssignee bool) (db.Issue, db.Issue, bool, error) {
+func (h *Handler) updateIssueAtomically(ctx context.Context, workspaceID pgtype.UUID, params db.UpdateIssueParams, rawFields map[string]json.RawMessage, blockers issueBlockerEdit, titleBase, descriptionBase *string, descriptionBaseRevision *int64, attachmentIDs []pgtype.UUID, statusKey string, workflowAssignee bool) (db.Issue, db.Issue, bool, error) {
if h.TxStarter == nil {
return db.Issue{}, db.Issue{}, false, errors.New("atomic issue update requires transaction starter")
}
@@ -4022,11 +4022,8 @@ func (h *Handler) updateIssueAtomically(ctx context.Context, workspaceID pgtype.
}
}
- var blockerInput UpdateIssueRequest
- _ = json.Unmarshal(rawFields["blocked_by"], &blockerInput.BlockedBy)
- _ = json.Unmarshal(rawFields["remove_blocked_by"], &blockerInput.RemoveBlockedBy)
- for _, value := range blockerInput.RemoveBlockedBy {
- if err = qtx.RemoveIssueBlocker(ctx, db.RemoveIssueBlockerParams{WorkspaceID: workspaceID, IssueID: issue.ID, BlockerIssueID: parseUUID(value)}); err != nil {
+ for _, blocker := range blockers.remove {
+ if err = qtx.RemoveIssueBlocker(ctx, db.RemoveIssueBlockerParams{WorkspaceID: workspaceID, IssueID: issue.ID, BlockerIssueID: blocker}); err != nil {
return db.Issue{}, current, false, err
}
}
@@ -4034,12 +4031,12 @@ func (h *Handler) updateIssueAtomically(ctx context.Context, workspaceID pgtype.
if blockerActor.id == "" {
blockerActor = wakeupActor{kind: issue.CreatorType, id: uuidToString(issue.CreatorID)}
}
- for _, value := range blockerInput.BlockedBy {
- if err = service.AddIssueBlocker(ctx, qtx, workspaceID, issue.ID, parseUUID(value), blockerActor.kind, parseUUID(blockerActor.id)); err != nil {
+ for _, blocker := range blockers.add {
+ if err = service.AddIssueBlocker(ctx, qtx, workspaceID, issue.ID, blocker, blockerActor.kind, parseUUID(blockerActor.id)); err != nil {
return db.Issue{}, current, false, err
}
}
- if len(blockerInput.BlockedBy)+len(blockerInput.RemoveBlockedBy) > 0 {
+ if blockers.changes() {
if _, err = tx.Exec(ctx, "UPDATE issue SET revision=revision+1,updated_at=clock_timestamp(),last_activity_at=clock_timestamp() WHERE id=$1 AND workspace_id=$2", issue.ID, workspaceID); err != nil {
return db.Issue{}, current, false, err
}
@@ -4107,20 +4104,15 @@ func (h *Handler) UpdateIssue(w http.ResponseWriter, r *http.Request) {
req.Description = sanitizeNullBytesPtr(req.Description)
req.DescriptionBase = sanitizeNullBytesPtr(req.DescriptionBase)
- if _, ok := h.parseBlockerIDs(w, req.BlockedBy); !ok {
- return
- }
- if _, ok := h.parseBlockerIDs(w, req.RemoveBlockedBy); !ok {
- return
- }
- if !h.validateBlockerVisibility(w, r, prevIssue.WorkspaceID, req.BlockedBy) {
- return
- }
-
// Track which fields were explicitly present in JSON (even if null)
var rawFields map[string]json.RawMessage
json.Unmarshal(bodyBytes, &rawFields)
+ blockers, ok := h.parseIssueBlockerEdit(w, r, prevIssue.WorkspaceID, rawFields)
+ if !ok {
+ return
+ }
+
if prevIssue.TriageState.Valid {
if field := triageLockedField(rawFields); field != "" {
writeIssueInTriage(w, field)
@@ -4409,7 +4401,7 @@ func (h *Handler) UpdateIssue(w http.ResponseWriter, r *http.Request) {
if req.Description != nil || req.TitleBase != nil || req.DescriptionBase != nil || len(attachmentIDs) > 0 || issueBlockerGraphTouched(rawFields) {
var lockedPrev db.Issue
issue, lockedPrev, attachmentsChanged, err = h.updateIssueAtomically(
- writeCtx, prevIssue.WorkspaceID, params, rawFields, req.TitleBase, req.DescriptionBase, req.DescriptionBaseRevision, attachmentIDs, statusKeyForGuard, handoff != nil,
+ writeCtx, prevIssue.WorkspaceID, params, rawFields, blockers, req.TitleBase, req.DescriptionBase, req.DescriptionBaseRevision, attachmentIDs, statusKeyForGuard, handoff != nil,
)
if lockedPrev.ID.Valid {
prevIssue = lockedPrev
@@ -4531,7 +4523,7 @@ func (h *Handler) UpdateIssue(w http.ResponseWriter, r *http.Request) {
}
// The other end of each edge lists this issue under blocking, so clients
// refresh more than this issue when its blockers change.
- updatedPayload["blockers_changed"] = len(req.BlockedBy)+len(req.RemoveBlockedBy) > 0
+ updatedPayload["blockers_changed"] = blockers.changes()
if handoff != nil {
updatedPayload["workflow_handoff"] = workflowHandoffPayload(issue, handoff, h.workflowHandoffBrief(r.Context(), issue, handoff), willRun)
}
@@ -4976,12 +4968,6 @@ func (h *Handler) BatchUpdateIssues(w http.ResponseWriter, r *http.Request) {
req.Updates.Title = sanitizeNullBytesPtr(req.Updates.Title)
req.Updates.Description = sanitizeNullBytesPtr(req.Updates.Description)
- if _, ok := h.parseBlockerIDs(w, req.Updates.BlockedBy); !ok {
- return
- }
- if _, ok := h.parseBlockerIDs(w, req.Updates.RemoveBlockedBy); !ok {
- return
- }
if len(req.IssueIDs) == 0 {
writeError(w, http.StatusBadRequest, "issue_ids is required")
return
@@ -5052,7 +5038,8 @@ func (h *Handler) BatchUpdateIssues(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
- if !h.validateBlockerVisibility(w, r, wsUUID, req.Updates.BlockedBy) {
+ blockers, ok := h.parseIssueBlockerEdit(w, r, wsUUID, rawUpdates)
+ if !ok {
return
}
// Status is validated against this workspace's catalog, so it has to wait
@@ -5337,7 +5324,7 @@ func (h *Handler) BatchUpdateIssues(w http.ResponseWriter, r *http.Request) {
// legacy single-update clients that omit description_base.
var lockedPrev db.Issue
issue, lockedPrev, _, err = h.updateIssueAtomically(
- writeCtx, prevIssue.WorkspaceID, params, rawUpdates, nil, nil, nil, nil, issueStatusGuard, handoff != nil,
+ writeCtx, prevIssue.WorkspaceID, params, rawUpdates, blockers, nil, nil, nil, nil, issueStatusGuard, handoff != nil,
)
if err == nil {
prevIssue = lockedPrev
@@ -5423,7 +5410,7 @@ func (h *Handler) BatchUpdateIssues(w http.ResponseWriter, r *http.Request) {
"title_changed": req.Updates.Title != nil && prevIssue.Title != issue.Title,
"prev_title": prevIssue.Title,
"parent_changed": prevIssue.ParentIssueID != issue.ParentIssueID,
- "blockers_changed": len(req.Updates.BlockedBy)+len(req.Updates.RemoveBlockedBy) > 0,
+ "blockers_changed": blockers.changes(),
"prev_parent_issue_id": uuidToPtr(prevIssue.ParentIssueID),
"prev_status": prevIssue.Status,
"duplicate_of_issue_id": liveDuplicateMark(issue.Status, issue.DuplicateOfIssueID),
diff --git a/server/internal/handler/issue_blocker.go b/server/internal/handler/issue_blocker.go
index a3ae0dc8d4..e43f354bda 100644
--- a/server/internal/handler/issue_blocker.go
+++ b/server/internal/handler/issue_blocker.go
@@ -8,7 +8,6 @@ import (
"net/http"
"strings"
- "github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgtype"
"github.com/multica-ai/multica/server/internal/projectaccess"
@@ -174,7 +173,10 @@ func publicBlockerResponse(issue IssueResponse) IssueResponse {
return issue
}
-func (h *Handler) validateBlockerVisibility(w http.ResponseWriter, r *http.Request, ws pgtype.UUID, ids []string) bool {
+// validateBlockerVisibility rejects an ID that is not an issue the caller can
+// open in this workspace. A hidden issue and a missing one get the same 400, so
+// the answer never tells the caller whether a private issue exists.
+func (h *Handler) validateBlockerVisibility(w http.ResponseWriter, r *http.Request, ws pgtype.UUID, ids []pgtype.UUID) bool {
if len(ids) == 0 {
return true
}
@@ -182,22 +184,57 @@ func (h *Handler) validateBlockerVisibility(w http.ResponseWriter, r *http.Reque
if !ok {
return false
}
- if hidden.Empty() {
- return true
+ refs, err := h.Queries.ListIssueRefsInWorkspace(r.Context(), db.ListIssueRefsInWorkspaceParams{WorkspaceID: ws, Ids: ids})
+ if err != nil {
+ writeError(w, 500, "failed to resolve blocker access")
+ return false
+ }
+ visible := make(map[pgtype.UUID]bool, len(refs))
+ for _, ref := range refs {
+ visible[ref.ID] = hidden.CanSeeProject(ref.ProjectID)
}
for _, id := range ids {
- project, err := h.Queries.GetIssueProjectID(r.Context(), parseUUID(id))
- if errors.Is(err, pgx.ErrNoRows) {
- continue
- }
- if err != nil {
- writeError(w, 500, "failed to resolve blocker access")
- return false
- }
- if !hidden.CanSeeProject(project) {
+ if !visible[id] {
writeError(w, 400, "blocker issue not found in this workspace")
return false
}
}
return true
}
+
+// issueBlockerEdit is the blocker change an issue update makes. It is read
+// once, from the exact keys that decide whether the blocker graph is written,
+// and the transaction writes these parsed IDs: the IDs that pass the checks
+// are the IDs written.
+type issueBlockerEdit struct {
+ add, remove []pgtype.UUID
+}
+
+func (e issueBlockerEdit) changes() bool {
+ return len(e.add)+len(e.remove) > 0
+}
+
+func (h *Handler) parseIssueBlockerEdit(w http.ResponseWriter, r *http.Request, ws pgtype.UUID, fields map[string]json.RawMessage) (issueBlockerEdit, bool) {
+ var edit issueBlockerEdit
+ var ok bool
+ if edit.add, ok = h.parseBlockerField(w, r, ws, fields["blocked_by"]); !ok {
+ return issueBlockerEdit{}, false
+ }
+ if edit.remove, ok = h.parseBlockerField(w, r, ws, fields["remove_blocked_by"]); !ok {
+ return issueBlockerEdit{}, false
+ }
+ return edit, true
+}
+
+func (h *Handler) parseBlockerField(w http.ResponseWriter, r *http.Request, ws pgtype.UUID, raw json.RawMessage) ([]pgtype.UUID, bool) {
+ var values []string
+ if raw != nil && json.Unmarshal(raw, &values) != nil {
+ writeError(w, http.StatusBadRequest, "invalid request body")
+ return nil, false
+ }
+ ids, ok := h.parseBlockerIDs(w, values)
+ if !ok || !h.validateBlockerVisibility(w, r, ws, ids) {
+ return nil, false
+ }
+ return ids, true
+}
diff --git a/server/internal/handler/issue_blocker_test.go b/server/internal/handler/issue_blocker_test.go
index 516c351e3b..da4bdd7b75 100644
--- a/server/internal/handler/issue_blocker_test.go
+++ b/server/internal/handler/issue_blocker_test.go
@@ -3,6 +3,7 @@ package handler
import (
"context"
"encoding/json"
+ "fmt"
"net/http"
"strings"
"testing"
@@ -486,3 +487,78 @@ func TestIssueBlockerReleaseHidesReferencesFromGuest(t *testing.T) {
}
}
}
+
+// Removing a dependency is gated like adding one: a member who can't open the
+// private prerequisite can't drop it, even with its ID in hand — including a
+// member who added it before losing access to the project.
+func TestIssueBlockerRemovalRequiresBlockerVisibility(t *testing.T) {
+ agent := seededReadyAgentID(t)
+ svc := service.IssueWakeupService{Tasks: testHandler.TaskService}
+ // Bodies are raw JSON so a test can repeat a key in a chosen order.
+ writes := map[string]func(user, id, updates string) *testutil.Response{
+ "single": func(user, id, updates string) *testutil.Response {
+ return testutil.Call(t, testHandler.UpdateIssue, withURLParam(asUser(newRequest("PUT", "/api/issues/"+id, json.RawMessage(updates)), user), "id", id))
+ },
+ "batch": func(user, id, updates string) *testutil.Response {
+ return testutil.Call(t, testHandler.BatchUpdateIssues, asUser(newRequest("POST", "/api/issues/batch-update?workspace_id="+testWorkspaceID, map[string]any{
+ "issue_ids": []string{id}, "updates": json.RawMessage(updates),
+ }), user))
+ },
+ }
+ for name, write := range writes {
+ t.Run(name, func(t *testing.T) {
+ f := newPrivateProjectFixture(t)
+ t.Cleanup(func() {
+ dbfx.Exec(t, "DELETE FROM issue_blocker WHERE issue_id=$1", f.publicIssue)
+ cleanupChildDoneIssue(f.publicIssue)
+ })
+ dbfx.Exec(t, "UPDATE issue SET status='todo',assignee_type='agent',assignee_id=$2 WHERE id=$1", f.publicIssue, agent)
+ edges := func() int {
+ return dbfx.Count(t, "SELECT count(*) FROM issue_blocker WHERE issue_id=$1 AND blocker_issue_id=$2", f.publicIssue, f.secretIssue)
+ }
+ runs := func() int {
+ return dbfx.Count(t, "SELECT count(*) FROM agent_task_queue WHERE issue_id=$1", f.publicIssue)
+ }
+ tick := func() {
+ t.Helper()
+ if err := svc.TickWorkspaces(context.Background(), parseUUID(testWorkspaceID)); err != nil {
+ t.Fatal(err)
+ }
+ }
+ write(f.insider, f.publicIssue, fmt.Sprintf(`{"blocked_by":[%q]}`, f.secretIssue)).Want(http.StatusOK)
+ remove := fmt.Sprintf(`{"remove_blocked_by":[%q]}`, f.secretIssue)
+ write(f.outsider, f.publicIssue, remove).Want(http.StatusBadRequest)
+ // A second key that differs only in case must not swap the checked
+ // list for another one before the write.
+ for _, key := range []string{"blocked_by", "remove_blocked_by"} {
+ body := fmt.Sprintf(`{%q:[%q],%q:[]}`, key, f.secretIssue, strings.ToUpper(key))
+ write(f.outsider, f.publicIssue, body).Want(http.StatusBadRequest)
+ }
+ removeProjectMemberRow(t, f.projectID, f.insider)
+ hidden := write(f.insider, f.publicIssue, remove).Want(http.StatusBadRequest).Text()
+ // A missing ID gets the same answer as a hidden one, so a member who
+ // lost access can't learn whether the private issue still exists.
+ missing := write(f.insider, f.publicIssue, fmt.Sprintf(`{"remove_blocked_by":[%q]}`, uuid.NewString())).Want(http.StatusBadRequest).Text()
+ if hidden != missing {
+ t.Fatalf("hidden blocker answered %q, missing blocker %q", hidden, missing)
+ }
+ tick()
+ if n := edges(); n != 1 {
+ t.Fatalf("rejected removals left %d edges, want 1", n)
+ }
+ if n := runs(); n != 0 {
+ t.Fatalf("rejected removals started %d runs", n)
+ }
+ // The edge was the only thing holding the run back: a member who
+ // can see the prerequisite removes it and the issue starts.
+ write(testUserID, f.publicIssue, remove).Want(http.StatusOK)
+ tick()
+ if n := edges(); n != 0 {
+ t.Fatalf("authorized removal left %d edges", n)
+ }
+ if n := runs(); n != 1 {
+ t.Fatalf("authorized removal started %d runs, want 1", n)
+ }
+ })
+ }
+}