Skip to content

bug(auth): agent-scoped keys can toggle their own agent's autonomy — PUT /api/agents/{name}/autonomy lacks reject_agent_principal #2996

Closed

Description

@AndriiPasternak31

Summary

PUT /api/agents/{name}/autonomy has no agent-principal rejection, so an agent-scoped MCP key can probably toggle its own agent's autonomy (and therefore whether its schedules fire).

Cause

routers/agent_config.py set_agent_autonomy_status → services/agent_service/autonomy.py set_autonomy_status_logic (~L88-90 on dev) gates only on:

if not db.can_user_share_agent(current_user.username, agent_name):

Per Invariant #8, get_current_user resolves an agent-scoped MCP key to its owner carrying the owner's identity, so can_user_share_agent passes for the agent's own key. There is no reject_agent_principal call and no admin gate.

Toggling autonomy is a grant (it decides whether the agent may run unattended), not a use, so under the grant-vs-use rule it should be human-only.

Why it matters now

The autonomy dial in #2984 relies on this per-agent switch as its "hard off". If the agent can flip it, the hard off isn't one.

Verification status

Confirmed by reading the code only; no live request has been sent with an agent key yet. The first step of the fix is a failing test that calls the endpoint with an agent-scoped principal.

Fix

Add reject_agent_principal(current_user) (or route through a helper that includes it) before the ownership check. Check the GET/other autonomy write paths for the same gap.

Acceptance

An agent-scoped key gets 403 on PUT /api/agents/{name}/autonomy for its own agent; owner and admin JWTs still work. The test fails with the guard removed.

Activity

  1. added
    priority-p1
    type-bug
    theme-security
    complexity-low
    on Sep 23, 2026
  2. added
    status-ready
    on Sep 27, 2026
  3. added
    status-in-progress
    and removed
    status-ready
    on Sep 28, 2026
  4. AndriiPasternak31 commented on Sep 28, 2026

    @AndriiPasternak31
    ContributorAuthor

    /claim. Plan reviewed; building now, together with trinity-enterprise#711 as one PR on a shared human-only check.

  5. github-actions commented on Sep 28, 2026

    @github-actions

    @AndriiPasternak31 This issue is already assigned to AndriiPasternak31. Use /unclaim first if you want to take over.

  6. added
    status-in-dev
    and removed
    status-in-progress
    on Sep 29, 2026
  7. 22 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

complexity-lowpriority-p1theme-securitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions