Repository navigation
fix: authorize agent conversation reads in the router gate - #743
Conversation
- Updated the GetConversationForAgent method to remove the currentConversationID parameter, simplifying the function signature and its usage across the codebase. - Removed the currentConversationIDFromHeader function as it is no longer needed. - Adjusted the ConversationResource middleware to handle conversation lookups by ID, ensuring proper authorization based on the conversation's project or agent context. - Updated route guards to include conversation authorization, ensuring that conversation access is properly gated. - Modified tests to reflect the changes in method signatures and removed unnecessary checks related to the current conversation ID. - Ensured that all relevant routes and handlers are updated to maintain functionality while adhering to the new structure.
There was a problem hiding this comment.
Caution
This re-opens the confused-deputy leak that the removed authorizeAgentConversationRead existed to prevent: an agent with conversations:read can now read a different human's owner-private chat whenever that chat belongs to the same agent. Every shipped project role already grants conversations:read project-wide, so the project case needs no extra configuration to be exploited. See the inline comment on agent_service.go.
Reviewed changes
- Router gate —
GET /agents/me/conversations/{conversationId}and its/eventssibling now requireconversations:read; the newConversationResourceresolves the target toproject/<P>/conversation/<C>oragent/<A>, and both routes moved from the open-route list to the IAM resource map. - Service —
GetConversationForAgentdropscurrentConversationID, the authorizer andWithAuthorizer, keeping only the deleted-conversation and cross-agent owner-private rules. - New IAM attribute —
conversation.agent_idadded to the schema, the Postgres attribute loader, the scope columns and three authorization docs. - Wiring and tests —
Deps.Conversationsbacked by the agent repository in bootstrap; guard, route-coverage, handler and service tests updated. - E2E — new feature file plus a five-scenario spec covering no-grant, own read, peer owner-private, task-assigned run, and a
conversation.agent_id-conditioned role.
ℹ️ Global agents on the default role lose even their own-conversation reads
Global agents are created with the default USER role (bootstrap/seed_roles.go:74-82), whose policy grants only users:read, and no seed or migration adds conversations:read for them. Because this PR now requires the permission for every read, including the agent's own current conversation, every existing global agent on the default role will start returning 403 for read_conversation after upgrade until an admin creates and attaches a role. The PR description states the rule change, but the repo carries no upgrade note or default-role adjustment for it.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Important
Denying every owner-private read closes the leak from the previous review, but it also denies the run's own current conversation, which two shipped consumers read without ever naming a chat the model picked. Details inline on agent_service.go; the rest of the delta (header removal, docs, e2e rework) looks right.
Reviewed changes
- Denied all owner-private reads —
GetConversationForAgentnow returns 404 for everyowner_privateconversation, the caller's own included, closing the same-agent / different-human leak raised in the prior review. - Removed the soft-deleted-but-running exemption — a soft-deleted conversation is always not found, and the test state the delete path could not produce is gone.
- Retired the dead
X-Conversation-IDplumbing — the MCP conversation client no longer sends the header, thePacaConfig.conversationIddoc and the agent-runner comment no longer claim it authorizes reads, andPACA_CONVERSATION_IDstays forX-Paca-Conversation-Idand the commit trailer. - Clarified
conversation.agent_id— both authorization docs now scope the condition to project conversations and note that global chats are authorized asagent/<id>with no conversation attributes. - Reworked the E2E scenarios around task runs — the own-read and
conversation.agent_idcases assign tasks, and a new case asserts the agent's own chat returns 404.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Important
The owner-mention rewiring is right for ephemeral sandboxes, but PACA_OWNER_MEMBER_ID is conversation-scoped and is not one of the keys static environments reconcile on later attaches, so a reused static environment keeps a stale (or missing) owner. Details inline.
Reviewed changes
- Rewired
ask_user_question's default owner mention to aPACA_OWNER_MEMBER_IDsupplied by agent-runner instead of reading the current (owner-private) conversation. - Forwarded
trigger.ActorMemberIDas that env var in the built-in Paca MCP server's environment, with a unit test pinning both presence and absence. - Corrected the
read_conversationdescription to state that chats, including the current and attached ones, cannot be read. - Dropped the stale
PACA_CONVERSATION_ID-authorization comment fromexecutor_test.go.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Reconciled
PACA_OWNER_MEMBER_IDon static environments — added the key topacaInfraEnvKeysin bothsandbox/dockerandsandbox/k8s, with a test in each package, closing the stale/missing-owner gap raised in the previous review. BothensureEnvironmentInfraEnvimplementations already delete a key whosecfg.Envvalue is empty, so actor-less triggers clear a stale owner. - Removed the now-dead
getCurrentConversation()—PacaAPIConversationClientonly keepsgetConversation, whichread_conversationstill uses. - Tidied the mention helper — renamed to
conversationOwnerMentionand refreshed its doc comment and the related test names to match thePACA_OWNER_MEMBER_IDsource.
I ran go test ./internal/sandbox/... ./internal/executor/ in services/agent-runner and the ask-tools/conversation-client vitest files in apps/mcp; all pass.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Fixes #634
Problem
GET /agents/me/conversations/:id(theread_conversationMCP tool) decided access in the service from the current conversation named by anX-Conversation-IDheader: its project, actor and chat-session member. The agent's own identity, which the API key already proves, was not what the decision rested on. Consequences:PACA_CONVERSATION_ID, so it sends no header and every cross-conversation read returned 404.Change
/agents/me/conversations/{id}and.../eventsnow requireconversations:read, judged on the roles of the agent the API key proves, over the conversation's own resource:project/<P>/conversation/<C>, oragent/<A>for a global chat. NewConversationResourceresolver (middleware/resource_lookup.go) andConversationByIDguard (router/guards.go). A conversation that does not exist resolves to a resource no policy names, so it is refused exactly like one the caller may not read.GetConversationForAgent(conversationID, callerAgentID)no longer takescurrentConversationIDand does no authorization (the authorizer,WithAuthorizerand the header parsing are removed). It keeps only the data rules the gate cannot see: a deleted conversation is not found, and an owner-private chat is never returned (see below).conversation.agent_id(schema, attribute loader, scope columns, docs), so a role can be limited to some conversations, for example an agent's own, with a condition.Deps.Conversations(the agent repository) in bootstrap.Behavior changes
conversations:readnow gets 403 on every read, including its own conversations. Roles that should read their own history need the permission, optionally limited withconversation.agent_id(project conversations only; a global chat is authorized asagent/<id>).X-Conversation-IDheader is removed from the MCP client and agent-runner.PACA_CONVERSATION_IDstays: it still feedsX-Paca-Conversation-Idand thePaca-Run:commit trailer.Tests
apps/e2e/tests/projects/agent-conversation-read.spec.ts, 5 scenarios, run against a rebuilt e2e stack): no grant -> 403; own task run with grant -> 200; owner-private chats (own and a peer's) -> 404; a task-assigned run of another agent -> 200 with the grant, 403 without; a role limited byconversation.agent_id-> own run 200, peer run 403.TestIAMAttributeLoaderscase forconversation.agent_idis skipped without a database; the e2e condition scenario exercises it instead.