Skip to content

fix: enforce permission filter for all users including admins in list_agents#477

Open
Clawiee wants to merge 1 commit intomainfrom
fix/agent-visibility-permission-filter
Open

fix: enforce permission filter for all users including admins in list_agents#477
Clawiee wants to merge 1 commit intomainfrom
fix/agent-visibility-permission-filter

Conversation

@Clawiee
Copy link
Copy Markdown
Collaborator

@Clawiee Clawiee commented Apr 26, 2026

Summary

Fix Issue #476: Admin can see "only me" agents created by other users.

Problem

The list_agents endpoint had a special shortcut for platform_admin and org_admin that returned ALL agents in the tenant without any permission filtering. This meant that agents with "仅自己可见" (scope_type='user', scope_id=creator) were still visible to admins.

Solution

Remove the admin shortcut and enforce the same permission filtering logic for all users:

  1. Agents the user created — Always visible to creator
  2. Agents with company-wide visibility — Visible to all in tenant (scope_type='company')
  3. Agents with user-specific visibility — Only visible to specified users (scope_type='user')

Changes

  • File: backend/app/api/agents.py
  • Function: list_agents()
  • Change: Removed admin shortcut that bypassed permission filtering

Testing

Please verify:

  1. Admin user cannot see agents with "仅自己可见" created by other users
  2. Admin can still see agents they created
  3. Admin can still see agents with "全公司可见"
  4. Regular users still see only their permitted agents

Related Issue

Fixes #476

…_agents

Fix Issue #476: Admin can see "only me" agents created by other users.

The previous code gave platform_admin and org_admin a special shortcut
that returned ALL agents in the tenant without any permission filtering.
Now all users (including admins) must go through the same permission
logic:
- Agents they created
- Agents with company-wide visibility (scope_type='company')
- Agents with user-specific visibility where they are in scope_ids

This ensures that "仅自己可见" agents (scope_type='user', scope_id=creator)
are only visible to the creator, even for admins.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 927cac16ac

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread backend/app/api/agents.py

query = select(Agent).where(
and_(
Agent.tenant_id == user_tenant,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve tenant_id override for platform admins

The new list_agents query now hard-codes tenant scoping to current_user.tenant_id and never reads the tenant_id query parameter, which regresses admin behavior from the previous implementation. In practice, a platform admin can no longer list another tenant’s agents via /agents?tenant_id=..., and a platform admin operating in global mode (no tenant bound in token, which other endpoints explicitly support) will be filtered to tenant_id IS NULL and miss normal tenant agents entirely.

Useful? React with 👍 / 👎.

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.

[BUG] 管理员能看到普通用户的"仅自己可见"数字员工 — 权限设计缺陷

1 participant