Skip to content

fix(security): apply UserVisibilityFilter to briefing + cortex endpoints#221

Merged
br-raia merged 2 commits into
mainfrom
fix/briefing-visibility-filtering
May 29, 2026
Merged

fix(security): apply UserVisibilityFilter to briefing + cortex endpoints#221
br-raia merged 2 commits into
mainfrom
fix/briefing-visibility-filtering

Conversation

@br-raia

@br-raia br-raia commented May 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixesthe briefing endpoint cross-user data that amfs_read then couldn't access.

  • GET /api/v1/briefing -- now applies UserVisibilityFilter to filter digests and hot_context entries
  • GET /api/v1/cortex/status -- now applies visibility to digest counts
  • GET /api/v1/cortex/digests -- now applies visibility to digest listing

Key implementation details

  • New _is_agent_visible_for_entity(agent_id, entity_path, user_agents, room_map) helper mirrors is_entry_visible logic but works with raw IDs (no full entry object needed)
  • New _filter_briefing_digests(vis, digests) handles digest-level filtering AND hot_context entry filtering within digests
  • Handles the hot_context dict shape ({"agent": "..."}) without modifying amfs-internal/amfs_rooms/visibility.py -- normalization is done in the HTTP handler
  • For synthesized digests (empty source_agents), keeps the digest only if user has room access to the entity_path or there are surviving hot_context entries
  • Admin users bypass filtering entirely (should_filter=False)
  • OSS deployments are completely unaffected (no UserVisibilityFilter present)
  • Zero additional DB queries -- reuses cached user_agents/room_map from the per-request visibility filter

Not in scope (follow-up)

A full endpoint audit found ~35 additional endpoints that may need visibility filtering (SSE stream, consolidation endpoints, history, traces, etc.). These are documented in the plan and will be addressed in a separate PR.

The briefing endpoint (GET /api/v1/briefing) and related cortex endpoints
bypassed UserVisibilityFilter, leaking cross-user data in multi-tenant
Pro deployments. An agent could receive briefing digests and hot_context
entries from other users' agents, but then fail to read those same
entries via amfs_read (which correctly applies visibility filtering).

This caused a broken UX where briefing promised data that read/search
could not deliver, and a tenant isolation gap where compiled knowledge
from other users' agents was exposed.

Changes:
- Add _is_agent_visible_for_entity() helper for entity-path-scoped
  agent visibility checks (mirrors is_entry_visible logic)
- Add _filter_briefing_digests() to filter both digest-level visibility
  and hot_context entries within digests
- Apply visibility filtering to GET /api/v1/briefing
- Apply visibility filtering to GET /api/v1/cortex/status
- Apply visibility filtering to GET /api/v1/cortex/digests
- Handle hot_context dict shape (uses "agent" key, not provenance)
  without modifying amfs-internal visibility module
- 19 new unit tests covering own-agent, room co-member, system agent,
  foreign agent, synthesized digest, and admin bypass scenarios

Admin users and OSS deployments are unaffected (should_filter=False
or no visibility filter present).
@br-raia br-raia self-assigned this May 29, 2026
@br-raia br-raia added bug Something isn't working enhancement New feature or request labels May 29, 2026
…-server

The CI workflow only installs core, adapters, sdk-python, mcp-server,
and cortex. The http-server package is not in the test matrix, so
tests importing from amfs_http fail with ModuleNotFoundError. Use
pytest.importorskip to gracefully skip when not available.
@br-raia br-raia moved this from Todo to In Progress in AMFS Roadmap May 29, 2026
@br-raia br-raia merged commit 1df99f6 into main May 29, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in AMFS Roadmap May 29, 2026
@br-raia br-raia deleted the fix/briefing-visibility-filtering branch May 29, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant