Skip to content

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

Go

fix(activity): redact duplicate marks that name an issue the reader can't see (#11280)

Multica Eve23716812bf0f
diff --git a/server/cmd/server/activity_listeners.go b/server/cmd/server/activity_listeners.go
index b970d0da6e..cfe7887af8 100644
--- a/server/cmd/server/activity_listeners.go
+++ b/server/cmd/server/activity_listeners.go
@@ -388,7 +388,10 @@ func publishActivityEvent(bus *events.Bus, original events.Event, activity db.Ac
"actor_type": actorType,
"actor_id": util.UUIDToString(activity.ActorID),
"action": action,
- "details": json.RawMessage(activity.Details),
+ // Realtime fans out by this issue's audience, which need not
+ // see an issue the details name; clients refetch the timeline,
+ // where the reference is redacted per reader.
+ "details": json.RawMessage(handler.StripActivityIssueRef(action, activity.Details)),
"created_at": util.TimestampToString(activity.CreatedAt),
},
},
diff --git a/server/internal/handler/activity.go b/server/internal/handler/activity.go
index f38f20b00e..ad9436e943 100644
--- a/server/internal/handler/activity.go
+++ b/server/internal/handler/activity.go
@@ -221,6 +221,25 @@ func (h *Handler) ListTimeline(w http.ResponseWriter, r *http.Request) {
w.Header().Set(HeaderTimelineTruncated, kinds)
}
+ // Reading this issue does not mean reading every issue its activity names:
+ // a duplicate mark points at an issue that may sit in a private project.
+ hidden, ok := h.requestHiddenProjects(w, r, uuidToString(issue.WorkspaceID))
+ if !ok {
+ return
+ }
+ actions := make([]string, len(activities))
+ details := make([][]byte, len(activities))
+ for i, a := range activities {
+ actions[i], details[i] = a.Action, a.Details
+ }
+ if err := h.redactHiddenActivityRefs(r, hidden, actions, details); err != nil {
+ writeError(w, http.StatusInternalServerError, "failed to list activities")
+ return
+ }
+ for i := range activities {
+ activities[i].Details = details[i]
+ }
+
entries := h.mergeTimeline(r, comments, activities, !wantWrapped)
// The current-member directory deliberately excludes departed members, but
// timeline attribution must remain readable after they leave. Hydrate only
diff --git a/server/internal/handler/activity_refs.go b/server/internal/handler/activity_refs.go
new file mode 100644
index 0000000000..dfdd1c3e04
--- /dev/null
+++ b/server/internal/handler/activity_refs.go
@@ -0,0 +1,112 @@
+package handler
+
+import (
+ "encoding/json"
+ "net/http"
+
+ "github.com/jackc/pgx/v5/pgtype"
+
+ "github.com/multica-ai/multica/server/internal/projectaccess"
+ "github.com/multica-ai/multica/server/internal/util"
+)
+
+// activityIssueRef names the details keys of an activity that point at a
+// second issue: its id, for linking, and its identifier, for reading.
+type activityIssueRef struct {
+ id string
+ identifier string
+}
+
+// activityIssueRefs lists the activities that name another issue. That issue
+// can sit in a private project the reader of this issue's timeline (or its
+// project's feed) cannot see, so its reference is redacted per reader.
+var activityIssueRefs = map[string]activityIssueRef{
+ "duplicate_marked": {id: "original_id", identifier: "original_identifier"},
+ "duplicate_unmarked": {id: "original_id", identifier: "original_identifier"},
+ "duplicate_added": {id: "duplicate_id", identifier: "duplicate_identifier"},
+ "duplicate_removed": {id: "duplicate_id", identifier: "duplicate_identifier"},
+}
+
+// referencedIssueID returns the other issue an activity names, if any.
+func referencedIssueID(action string, details []byte) (pgtype.UUID, bool) {
+ ref, ok := activityIssueRefs[action]
+ if !ok || len(details) == 0 {
+ return pgtype.UUID{}, false
+ }
+ var fields map[string]json.RawMessage
+ if err := json.Unmarshal(details, &fields); err != nil {
+ return pgtype.UUID{}, false
+ }
+ var id string
+ if err := json.Unmarshal(fields[ref.id], &id); err != nil || id == "" {
+ return pgtype.UUID{}, false
+ }
+ parsed, err := util.ParseUUID(id)
+ if err != nil {
+ return pgtype.UUID{}, false
+ }
+ return parsed, true
+}
+
+// StripActivityIssueRef removes the other issue's id and identifier from an
+// activity's details, keeping every other field. Clients render the row with
+// a placeholder in its place. Activities that name no other issue come back
+// unchanged.
+func StripActivityIssueRef(action string, details []byte) []byte {
+ ref, ok := activityIssueRefs[action]
+ if !ok || len(details) == 0 {
+ return details
+ }
+ var fields map[string]json.RawMessage
+ if err := json.Unmarshal(details, &fields); err != nil {
+ // Unreadable details cannot be redacted key by key; drop them all.
+ return []byte("{}")
+ }
+ if _, hasID := fields[ref.id]; !hasID {
+ if _, hasIdentifier := fields[ref.identifier]; !hasIdentifier {
+ return details
+ }
+ }
+ delete(fields, ref.id)
+ delete(fields, ref.identifier)
+ out, err := json.Marshal(fields)
+ if err != nil {
+ return []byte("{}")
+ }
+ return out
+}
+
+// redactHiddenActivityRefs strips, in place, the reference to another issue
+// from every activity whose referenced issue sits in a project hidden from
+// the reader. actions[i] and details[i] describe the same activity. A
+// referenced issue that no longer exists keeps its reference: activities
+// carry a deleted issue's identifier on purpose so the row still reads.
+func (h *Handler) redactHiddenActivityRefs(r *http.Request, hidden projectaccess.Hidden, actions []string, details [][]byte) error {
+ if hidden.Empty() {
+ return nil
+ }
+ refs := make([]pgtype.UUID, len(actions))
+ var ids []pgtype.UUID
+ for i, action := range actions {
+ if id, ok := referencedIssueID(action, details[i]); ok {
+ refs[i] = id
+ ids = append(ids, id)
+ }
+ }
+ if len(ids) == 0 {
+ return nil
+ }
+ hiddenIssues, err := h.hiddenIssueIDs(r, hidden, ids)
+ if err != nil {
+ return err
+ }
+ for i, id := range refs {
+ if !id.Valid {
+ continue
+ }
+ if _, isHidden := hiddenIssues[id]; isHidden {
+ details[i] = StripActivityIssueRef(actions[i], details[i])
+ }
+ }
+ return nil
+}
diff --git a/server/internal/handler/activity_refs_test.go b/server/internal/handler/activity_refs_test.go
new file mode 100644
index 0000000000..df63189757
--- /dev/null
+++ b/server/internal/handler/activity_refs_test.go
@@ -0,0 +1,126 @@
+package handler
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "github.com/multica-ai/multica/server/internal/testutil"
+)
+
+func TestStripActivityIssueRef(t *testing.T) {
+ cases := []struct {
+ name, action, details, want string
+ }{
+ {"marked keeps the rest", "duplicate_marked", `{"original_id":"a","original_identifier":"MUL-1","to":"done"}`, `{"to":"done"}`},
+ {"added", "duplicate_added", `{"duplicate_id":"a","duplicate_identifier":"MUL-2"}`, `{}`},
+ {"unrelated action untouched", "status_changed", `{"from":"todo","to":"done"}`, `{"from":"todo","to":"done"}`},
+ {"no ref keys untouched", "duplicate_removed", `{"reason":"x"}`, `{"reason":"x"}`},
+ {"unreadable details dropped", "duplicate_marked", `not json`, `{}`},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ if got := string(StripActivityIssueRef(tc.action, []byte(tc.details))); got != tc.want {
+ t.Errorf("StripActivityIssueRef(%s, %s) = %s, want %s", tc.action, tc.details, got, tc.want)
+ }
+ })
+ }
+}
+
+// A duplicate mark names an issue in another project. Readers who can see the
+// project feed or the issue's timeline but not that other project must not
+// learn the other issue's id or identifier; readers who can see both still do.
+func TestActivityRefsToHiddenIssuesAreRedacted(t *testing.T) {
+ if testHandler == nil {
+ t.Skip("database not available")
+ }
+ f := newPrivateProjectFixture(t)
+ openProject := dbfx.Project(t, f.marker+" open project")
+ openIssue := dbfx.Issue(t, f.marker+" open issue", testutil.Cols{"project_id": openProject})
+
+ // The open issue is a duplicate of the secret one, and the secret issue
+ // has the public one as its duplicate.
+ insertActivity := func(issueID, action string, details map[string]string) {
+ t.Helper()
+ body, _ := json.Marshal(details)
+ dbfx.Exec(t, `
+ INSERT INTO activity_log (workspace_id, issue_id, actor_type, actor_id, action, details)
+ VALUES ($1, $2, 'member', $3, $4, $5::jsonb)
+ `, testWorkspaceID, issueID, testUserID, action, string(body))
+ }
+ insertActivity(openIssue, "duplicate_marked", map[string]string{"original_id": f.secretIssue, "original_identifier": "SECRET-1"})
+ insertActivity(f.publicIssue, "duplicate_added", map[string]string{"duplicate_id": f.secretIssue, "duplicate_identifier": "SECRET-1"})
+ insertActivity(f.publicIssue, "duplicate_removed", map[string]string{"duplicate_id": openIssue, "duplicate_identifier": "OPEN-1"})
+
+ projectFeed := func(userID string) map[string]map[string]string {
+ t.Helper()
+ var resp ProjectActivityResponse
+ req := withURLParam(asUser(newRequest(http.MethodGet, "/api/projects/"+openProject+"/activity", nil), userID), "id", openProject)
+ rec := httptest.NewRecorder()
+ testHandler.ListProjectActivity(rec, req)
+ if rec.Code != http.StatusOK {
+ t.Fatalf("project activity as %s: %d %s", userID, rec.Code, rec.Body.String())
+ }
+ if err := json.NewDecoder(rec.Body).Decode(&resp); err != nil {
+ t.Fatalf("decode project activity: %v", err)
+ }
+ out := map[string]map[string]string{}
+ for _, e := range resp.Entries {
+ var d map[string]string
+ _ = json.Unmarshal(e.Details, &d)
+ out[e.Action] = d
+ }
+ return out
+ }
+ timeline := func(userID, issueID string) map[string]map[string]string {
+ t.Helper()
+ var entries []TimelineEntry
+ req := withURLParam(asUser(newRequest(http.MethodGet, "/api/issues/"+issueID+"/timeline", nil), userID), "id", issueID)
+ rec := httptest.NewRecorder()
+ testHandler.ListTimeline(rec, req)
+ if rec.Code != http.StatusOK {
+ t.Fatalf("timeline as %s: %d %s", userID, rec.Code, rec.Body.String())
+ }
+ if err := json.NewDecoder(rec.Body).Decode(&entries); err != nil {
+ t.Fatalf("decode timeline: %v", err)
+ }
+ out := map[string]map[string]string{}
+ for _, e := range entries {
+ if e.Action == nil {
+ continue
+ }
+ var d map[string]string
+ _ = json.Unmarshal(e.Details, &d)
+ out[*e.Action] = d
+ }
+ return out
+ }
+
+ for _, reader := range []struct{ name, id string }{{"outsider", f.outsider}, {"outside admin", f.outsideAdmin}} {
+ t.Run(reader.name, func(t *testing.T) {
+ if d := projectFeed(reader.id)["duplicate_marked"]; d == nil || d["original_id"] != "" || d["original_identifier"] != "" {
+ t.Errorf("project feed duplicate_marked = %v, want the secret original redacted", d)
+ }
+ if d := timeline(reader.id, openIssue)["duplicate_marked"]; d == nil || d["original_id"] != "" || d["original_identifier"] != "" {
+ t.Errorf("timeline duplicate_marked = %v, want the secret original redacted", d)
+ }
+ public := timeline(reader.id, f.publicIssue)
+ if d := public["duplicate_added"]; d == nil || d["duplicate_id"] != "" || d["duplicate_identifier"] != "" {
+ t.Errorf("timeline duplicate_added = %v, want the secret duplicate redacted", d)
+ }
+ if d := public["duplicate_removed"]; d["duplicate_id"] != openIssue || d["duplicate_identifier"] != "OPEN-1" {
+ t.Errorf("timeline duplicate_removed = %v, want the visible duplicate kept", d)
+ }
+ })
+ }
+
+ t.Run("insider", func(t *testing.T) {
+ if d := projectFeed(f.insider)["duplicate_marked"]; d["original_id"] != f.secretIssue || d["original_identifier"] != "SECRET-1" {
+ t.Errorf("project feed duplicate_marked = %v, want the original kept", d)
+ }
+ if d := timeline(f.insider, f.publicIssue)["duplicate_added"]; d["duplicate_id"] != f.secretIssue || d["duplicate_identifier"] != "SECRET-1" {
+ t.Errorf("timeline duplicate_added = %v, want the duplicate kept", d)
+ }
+ })
+}
diff --git a/server/internal/handler/project_activity.go b/server/internal/handler/project_activity.go
index 234ed1aafb..fc4f77bb25 100644
--- a/server/internal/handler/project_activity.go
+++ b/server/internal/handler/project_activity.go
@@ -111,11 +111,27 @@ func (h *Handler) ListProjectActivity(w http.ResponseWriter, r *http.Request) {
resp.NextCursor = &cursor
rows = rows[:limit]
}
+ // Seeing this project does not mean seeing every issue its activity names:
+ // a duplicate mark points at an issue that may sit in another private
+ // project.
+ hidden, ok := h.requestHiddenProjects(w, r, workspaceID)
+ if !ok {
+ return
+ }
+ actions := make([]string, len(rows))
+ details := make([][]byte, len(rows))
+ for i, row := range rows {
+ actions[i], details[i] = row.Action, row.Details
+ }
+ if err := h.redactHiddenActivityRefs(r, hidden, actions, details); err != nil {
+ writeError(w, http.StatusInternalServerError, "failed to load project activity")
+ return
+ }
prefix := h.getIssuePrefix(ctx, wsUUID)
- for _, row := range rows {
- details := json.RawMessage(row.Details)
- if len(details) == 0 {
- details = json.RawMessage("{}")
+ for i, row := range rows {
+ raw := json.RawMessage(details[i])
+ if len(raw) == 0 {
+ raw = json.RawMessage("{}")
}
resp.Entries = append(resp.Entries, ProjectActivityEntry{
ID: uuidToString(row.ID),
@@ -126,7 +142,7 @@ func (h *Handler) ListProjectActivity(w http.ResponseWriter, r *http.Request) {
ActorType: row.ActorType.String,
ActorID: uuidToString(row.ActorID),
Action: row.Action,
- Details: details,
+ Details: raw,
CreatedAt: timestampToString(row.CreatedAt),
})
}