Review: a bot can be given access to every channel in one step (PR #829, reviewed head 8ea14e1f5)

From mnema-talk v3.3.13, rendered on this site.

Reviewer: independent agents that did not write the change (Opus, read-only, one fresh agent per round). Three rounds; each round got only the pull request number and the focus (permissions and security). The first two returned CHANGES REQUESTED, the third MERGE. The findings below were fixed in the same pull request, except where a follow-up is named.

CODEOWNERS paths touched: internal/perm/, internal/db/migrations/.

After the third round only three things changed, none touching a rule: the new fields of the access answer became optional in the schema (so the frontend still decodes the answers of older servers), the route was added to the permission matrix test, and tests were added to keep every file above the coverage floor.

Verdict

MERGE (round 3), with the follow-ups named at the end.

What was reviewed

The Access choice for bots: POST /api/admin/bots/install with access: "all", PUT /api/admin/bots/{id}/access, the marker bots.access_all (migration 0107), and the snapshot rule that a bot with the marker does not see a channel or category that @everyone alone cannot view.

Held up in all three rounds:

  • Both endpoints write under the permission lock in one transaction (mutate/Locked; install in LockedCreatingBot), and checkBotGrowth compares the snapshots before and after, so a non-Owner cannot give a bot anything elevated, a permission they lack in any channel it reaches, or a channel they cannot view.
  • Only the six channel permissions a manifest may ask for can be given; none is in Elevated.
  • The snapshot rule agrees with the independently written reference model, including categories and the role preview.
  • The API change is additive.

Findings and their resolution

Round 1:

  • Hierarchy not re-checked under the lock in SetBotAccess: fixed (CanModerate before CanActAs), with a test where the bot outranks the maker.
  • The first form of the rule also took View from @everyone's allow overwrites, so a bot without View, or in a community where @everyone has no View, saw channels it was never given: fixed. The rule now only takes View away, from the plain member's view chain (server-wide, category, channel), and applies to categories and to the role preview. The reference model derives it separately; new unit tests cover a private category, a channel reopened inside it, a bot without View, and @everyone without View.
  • Switching back cleared overwrites in channels the caller cannot see: fixed (Restrict/Within).
  • A bot deleted mid-request answered 500: now 404.
  • Wording: the choice is limited to the six manifest channel permissions, not to one bot's manifest. Docs and API text say so.

Round 2:

  • A Save in the settings panel widened per-channel grants to their union: the answer now carries the intersection and mixed, and the panel says so before saving.
  • Category overwrites of the own role survived "Selected channels": they are replaced too, within categories the caller sees in full.
  • The install refusal for access "all" now names the channel where the installer lacks a permission.
  • A deny of the own role is lifted for a permission that is both given and listed (the explicit choice wins); documented in bots.md and the OpenAPI text.
  • Documented: in a community where @everyone lacks View server-wide every channel counts as private for this choice.

Round 3 (verdict MERGE):

  • "All channels" without View channels is refused with 400 (both endpoints).
  • The audit snapshot of a bot now records access_all and the own role's permissions.
  • Documented caveats: opening a channel to everyone is under the bot invariant while an all-channels bot holds a permission the editor lacks; switching back does not remove View channels that another role of the bot grants.

Follow-ups (not part of this pull request)

  • Channel creation (chat/channels CreateChannel) and duplication do not run under Perms.Locked, so the bot invariant does not see a new public channel. The gap exists for any bot holding server-wide permissions through roles; this feature makes that path easy, so the channel handlers should move under the lock.
  • errBotGrowth could name the bot and the channel.
  • Switching back could warn when another role of the bot keeps it viewing private channels.
  • The reference model's everyoneSeesCategory mirrors the code it checks; derive it from a member with no roles.

Something wrong on this page? Tell us.