Skip to content

fix(defty): answer only with what everyone in the conversation can see - #629

Open
Maneek21 wants to merge 5 commits into
masterfrom
fix/158-defty-audience
Open

Maneek21 wants to merge 5 commits into
masterfrom
fix/158-defty-audience

Conversation

@Maneek21

@Maneek21 Maneek21 commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

In a public room the owner asked "@defty summarize Launch pilot", and Defty's threaded reply named a restricted task. A member and a guest read that reply, and both get 404 on the task itself. Defty read with the asker's access, but answered to everyone who can read the conversation. That contradicts the site's "agents use only the records their identity is allowed to see". Found live on 157 (RC13B).

Now, in any conversation someone other than the asker can read, Defty uses only records every reader can see. That covers rooms, threads, group DMs and DMs between two people. A 1:1 DM with Defty is unchanged.

Who counts as a reader (lib/defty-audience.ts, worked out once per turn):

  • the conversation's members;
  • for an unarchived public room, also every active non-guest workspace member;
  • agents whose employee is active, with that employee's project scope. Rule to test: an active agent counts as a reader of every public room, because agents read any active public room over MCP (mcp-tools/messages.ts). So a project-limited agent narrows Defty's public-room answers. A paused agent doesn't count. This fails closed (accepted by the orchestrator, 27 Nov);
  • never Defty;
  • an unknown conversation id fails closed.

What changes in a shared conversation

  • Fail-closed allowlist. executeToolCall runs only SHARED_CONVERSATION_TOOLS:

    • the held reads: task tools, projects, messages, notes, canvas, wiki;
    • Defty's housekeeping writes remember and create_plan (wiki_suggest_update is refused: it names the page it looks up).

    Every other tool returns SHARED_CONVERSATION_READ_UNAVAILABLE ("ask me in a direct message"). That covers team and people reports, calendar, GitHub, memory, decisions and knowledge, Modules, Apps and MCP tools.

  • One task gate. taskReadConditions serves every task row, title and count in agent-context.ts. It now also requires that every reader can see the task under task-visibility.ts. An unrestricted task is checked only against guests and agents; a restricted one against every reader.

  • Other reads held the same way:

    • messages come only from rooms every reader can read;
    • notes, canvas and wiki are checked per reader, including the runner's automatic wiki lookup;
    • member match lists and wiki source citations are dropped;
    • Module discovery isn't prefetched.
  • What goes into the answer:

    • the room context pack resolves task keys only for tasks every reader sees;
    • earlier replies are read without run details;
    • durable Module results stay out;
    • approval and draft-compiler text names only tasks every reader sees, and the compiler is offered only projects inside every agent reader's scope;
    • a post_message target is chosen from rooms the asker can read, and a "several rooms match" warning names only rooms every reader can read.
  • "Left out" line. Each held read is compared with the asker's own read, whose result is never returned. The reply ends with "Some items were left out because not everyone here can see them." if they differ, or if the automatic wiki lookup, the room context pack's task keys or the approval text left something out.

Tests

  • defty-shared-audience-db:
    • a public room, where a member and a guest read the reply through the API and get 404 on the task;
    • a thread in a room, a private room, a group DM and a DM between two people;
    • a 1:1 DM, unchanged;
    • an agent member with and without a project scope (a paused agent doesn't count);
    • messages, notes, wiki, and refused tools;
    • review round 1: an ambiguous private room name, compiler projects, the left-out line from the automatic wiki lookup and room context, and an agent with no membership row. Each failed before its fix.
  • The failing tests are the first commit.
  • Updated to the new rule:
    • W1-b wiki in a public room another member reads;
    • durable results in a public room;
    • two module tests that passed a made-up conversation id now use a real DM.
  • Local runs (WSL Postgres; push-full ends with the known local stamp error):
    • all 52 API test files that touch the changed code, plus 14 that reach it indirectly, pass;
    • except 6 tests that fail identically on unchanged master here. They are pre-existing and local-only, and CI is the judge:
      • restricted-task-routes-db: "the dashboard, people directory and member detail leave out a restricted task for people it does not name"
      • agent-run-text-audience-db: "an owner or admin cannot run a departed member's plan for them"
      • agent-run-text-audience-db: "W2a4-B1: employee statistics return the channel error text to owners/admins only"
      • customer-content-logs-db: "native writes, agent replies and failed writes never log customer content"
      • guest-people-visibility-db: "GET /api/members/:id and /:id/detail: a guest reaches only people sharing a space"
      • guest-people-visibility-db: "a guest cannot assign a hidden person, or start a conversation with a hidden agent; the agent list follows the rule"
  • No local typecheck (laptop rule): CI checks types.

Known and left alone (scope fixed for 158):

  • Write-action target resolution (resolvePendingActionTargets in agent-reply.ts) still resolves task and decision ids with the asker's access. It puts no task title into the reply. A post target the asker named themselves is echoed back by name.
  • An ambiguous-assignee warning can list names the asker sees.
  • Someone who joins after the answer can read it (same as the docs rule).

Created with Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

Maneek21 and others added 3 commits November 27, 2026 23:09
…s can read

FIX158 (RC13B on 157): in a public room, Defty's threaded reply named a
restricted task. A member and a guest read it, and both get 404 on the
task itself. Defty reads with the asker's access but answers to
everyone who can read the conversation.

These tests reproduce the leak: a public room (member and guest read
the reply through the API), a thread in a room, a private room, a group
DM, a DM between two people, an agent member with its own project
scope, messages, notes and wiki, and the read tools that must be
refused in a shared conversation. A 1:1 DM with Defty keeps today's
behaviour (that test passes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FIX158. Defty read with the asker's access but posted to the
conversation, so a reply in a public room named a restricted task that
the member and guest reading it get 404 on.

lib/defty-audience.ts works out, once per turn, who can read the
conversation: its members and, for an unarchived public room, every
active non-guest workspace member, plus agents whose employee is
active (with the employee's project scope). Defty never counts. A
conversation is shared when anyone but the asker reads it; a 1:1 DM
with Defty is unchanged. An unknown conversation id fails closed.

In a shared conversation:
- executeToolCall runs only SHARED_CONVERSATION_TOOLS. Every other tool
  is refused with SHARED_CONVERSATION_READ_UNAVAILABLE ("ask me in a
  direct message"), so an unchecked tool fails closed.
- The one task-read gate (taskReadConditions, every task row, title and
  count) adds "every reader can see this task" under task-visibility.ts.
  Projects follow agent scopes. Messages come only from rooms every
  reader can read. Notes, canvases and wiki pages (tools and the
  runner's automatic lookup) are checked per reader. Member match lists
  are dropped. Wiki source citations are dropped.
- The room context pack resolves task keys only for tasks every reader
  sees. Earlier replies are read without run details. Durable Module
  results stay out. Approval and draft-compiler text names only tasks
  every reader sees.
- A held read that left something out sets `withheld`, and the reply
  ends with "Some items were left out because not everyone here can see
  them."

Tests: defty-shared-audience-db covers a public room (a member and a
guest read the reply through the API), a thread, a private room, a
group DM, a DM between two people, a 1:1 DM (unchanged), an agent
member with and without a project scope (paused agents don't count),
messages, notes, wiki and refused tools. Three tests updated to the
new rule: W1-b wiki in a shared public room, durable results in a
public room, and two module tests now using a real DM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rsation answers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Maneek21 and others added 2 commits November 28, 2026 00:19
… Defty tool wrapper

FP-004, FP-028 and FP-029 (js/insufficient-password-hash, all reviewed
false positives) keep their sinks and hashed inputs. Their flow
fingerprints changed only because the authenticator-object taint path
now passes through the new executeToolCall wrapper in agent-context.ts.
Checked against raw CodeQL run 46048903117 on 72c342b: the gate passes
29/29.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ders

From the gpt-6.1-sol and Opus reviews of #629:
- wiki_suggest_update no longer runs in a shared conversation: it looks
  a page up by slug with no visibility check and names it (both).
- Room readability for the readers now uses its own aliases
  (roomReadableBySql). readableSpaceSql's inner spaces shadowed the
  outer row in the search_messages room lookup, so private rooms the
  asker reads were listed in SPACE_AMBIGUOUS matches (both).
- The action compiler offers only projects inside every agent reader's
  scope, and drops a default room project outside it (gpt-6.1-sol).
- The left-out line also comes from the automatic wiki lookup, the room
  context pack's task keys and the approval text's tasks (both).
- The runner holds the canonical Defty system employee's runs too
  (answersAsDefty, now in defty-audience.ts) (both).
- An agent is a reader through its active employee, whatever its
  org_members row says, and every active employee reads every public
  room, as MCP lets it (Opus).
- In a shared conversation a post_message target is chosen from rooms
  the asker can read, and a "several rooms match" warning names only
  rooms every reader can read (Opus; pre-existing).
Five regression tests, each failing before this commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant