mirror of
https://github.com/mattermost/mattermost.git
synced 2026-11-28 15:38:27 +08:00
* Add access channel action (#38362)
* Added View Channel as an action to ABAC permission policies
* Enabled feature flag in Playwright tests
* Updated playwright test
* Changed from View Channel to Access Channel
* Updated modal text
* Renamed access_channel to channel_read_access
* Renamed the feature flag
* Remove the ChannelAccessABACPermission feature flag
The channel-access ABAC actions (channel_read_access) are now always
available; the sub-flag and every gate behind it are gone.
Server:
- Drop the flag, its default and IsChannelAccessABACPermissionEnabled().
- Drop the POST /access_control_policies gate and its i18n string. A
channel policy carrying channel_read_access still has to clear the
ChannelPermissionPolicies gate, since it is a permission action.
- Drop AccessControlPolicy.HasChannelReadAccessAction(), which only
existed to drive that gate.
- Drop the now-unused Enabled hook on the renderable-action registry, so
discovery mode always lists channel_read_access.
Webapp:
- Drop FeatureFlagChannelAccessABACPermission and the
isChannelAccessABACPermissionEnabled selector. The Channel Read Access
row is always offered in both policy authoring pickers, and the save
confirmation now fires whenever the action is selected.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* i18n fix
* Enforce access channel action (#38374)
* Enforce ABAC access_channel in the channel permission gates
ABAC could say who may belong to a channel and what may be done with its
attachments, but not whether a session may read the channel right now. This
wires the access_channel action into the gates every channel surface already
goes through, so one evaluation covers them all rather than N call sites.
HasPermissionToAccessChannel is ANDed into SessionHasPermissionToChannel,
SessionHasPermissionToChannels, SessionHasPermissionToChannelByPost,
HasPermissionToChannel, SessionHasPermissionToReadChannel,
HasPermissionToReadChannel, HasPermissionToResolveChannelMention,
HasPermissionToChannelMemberCount and GetPostIfAuthorized. Each gate's role
logic moves into an RBACOnly sibling and the exported name becomes a thin
wrapper, so there is one AND site per gate instead of one per early return —
and the exemptions the plugin API and the policy-administration endpoints need
fall out for free, visible at the call site rather than hidden in a flag.
It gates every permission, not just the read-shaped ones: access_channel is a
prerequisite for interacting with a channel at all, so scoping it to reads
would leave the write paths reachable for a session that cannot see it. System
admins and local-mode sessions are evaluated too, matching the file actions,
which have no such bypass either. DMs and GMs are exempt. Nothing is evaluated
until the flag, the ABAC config switch, an Enterprise Advanced licence and a
policy that actually declares the action are all in place; subject-build and
evaluation failures deny.
Two permissive fallbacks had no channel to evaluate against and would have been
holes: SessionHasPermissionToReadPost and SessionHasPermissionToChannelByPost
both fell through to a system-wide permission when the post's channel could not
be resolved. Both now fail closed while the policy is being enforced.
A per-request memo collapses the repeat evaluations — the gates nest, so one
getPost would otherwise cost four PDP round trips — and carries the denial fact
so SetChannelPermissionError can return a distinct error id. Clients need "you
cannot view this channel right now" apart from "you were removed from this
channel"; only the first can resolve itself.
HasPermissionToChannelByPost is deleted: no non-test callers, and leaving an
ungated gate around invites the next one.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Close the access_channel enforcement points outside the gates
The gates cover most surfaces, but a handful grant channel access by other
means and never reach them. Each is now checked explicitly:
- Channel fetch by id/name/name-for-team granted on a team-level
read_public_channel or manage_team, so a denied session could read any open
channel on its team and team admins could read any private one.
- The discoverable non-member view is reached *because* the gate denied, and
IsDiscoverableJoinAllowed only evaluates membership. A denied session was
handed the channel's name, header and purpose plus a way to join.
- getPostInfo re-grants to anyone who could join the channel. The check is
applied on its own rather than through the read gate, and the 404 is kept so
a denial stays indistinguishable from a missing post.
- Post create, draft upsert and their app-layer twin fall back to a team-level
create_post_public.
- addChannelMember's self-join and the join-request queue would otherwise be
the way around the policy. Joining is a write, so these are genuine blocks
rather than suppression; who may be added is still membership's question.
- The uploader of a file proceeds through getFile and its four siblings with
the channel permission already false.
- channelMembersMinusGroupMembers returns channel members behind a sysconsole
permission alone. Its moderation neighbours are left policy-blind on purpose,
and say so: they are permission-scheme configuration, not channel content.
- Both flagged-post reports had never been gated on the channel at all, only on
team reviewer status, so a reviewer could pull a full report — file bytes
included — for a channel the policy hides from them. Reviewers are not exempt.
The read marker (viewChannel, readMultipleChannels, readAllInTeam) had no
channel check of any kind. viewChannel now reports the denial before ViewChannel
runs, so nothing moves the read marker or the active channel; it is the client's
detection point. The channel being left behind is dropped rather than reported,
so navigating away from a channel you just lost does not fail. The batch and
team-wide variants suppress per channel and mark the rest, leaving the hidden
channels' unread and mention counts intact for when access returns.
Exempted through the RBACOnly siblings: the plugin API, whose surfaces are out
of scope and must not shift under plugin authors; the policy-administration
endpoints, so a mis-scoped policy stays repairable; and the render-decision
endpoint, which is how the client learns it has been denied at all.
Denials now carry api.channel.access_channel.abac_denied.app_error instead of
the generic permission error, across ~80 call sites, taking the channel from the
gate call so the two cannot drift.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Filter denied channels out of the discovery and list surfaces
A 403 stops a session opening a channel, but the channel is still visible until
it is gone from the lists. A name in Browse Channels or an autocomplete hit is
itself the disclosure: it tells a session that a channel it cannot read exists.
Sidebar and channel-member streams are filtered in the handler, not the app
layer. Both write JSON incrementally and stop on `len(page) < pageSize`, so a
page containing one denied channel would look like the last page and silently
truncate the entire remaining list. The cursor advance and the termination test
now run against the raw page, and the comma logic tracks whether anything has
been written rather than assuming a full page.
Post search, saved posts and file search needed nothing: they already dedupe per
channel through HasPermissionToReadChannel, which is now policy-aware.
The threads list had no channel-permission filter of any kind — the store scopes
it by ChannelMembers, and a denied user keeps their membership, so threads from
hidden channels surfaced. It gets the new utils.FetchUntil, which re-reads from
the cursor until a page is full, because filtering after the database has already
paginated would otherwise hand the client a short page and stop its scrolling.
The helper is capped and reports when it gave up, so a user denied nearly every
channel cannot drive unbounded round trips.
Thread unread totals and channel unread aggregates are deliberately left as the
store computed them, so a hidden channel can still contribute a badge. Making
them agree with what is visible is a larger change than this one.
SearchAllChannels stays unfiltered: its callers are the System Console channel
list, the data-retention picker and the policy channel search, all of which exist
to administer channels an admin may not be a member of.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Drop denied channels from websocket fan-out and push notifications
The gates decide what a session can fetch, but a post arriving over the
websocket was never fetched, and a push notification carries the body without
the recipient asking. Both deliver content past the enforcement points.
accessChannelBroadcastHook rejects a channel-scoped event per recipient. The
platform honours Reject() before the event burns a sequence number or enters the
reconnect replay queue, so a dropped event leaves no gap. It is registered from
publishWebsocketEventForPost — which covers posted and every post_edited that
routes through it, including the acknowledgement, content-flagging and
shared-channel paths — plus post_deleted, which publishes its sanitized and
sensitive copies directly and carried no hooks at all. It fails closed on a
connection with no session: a rule may reference the session, so there is
nothing to evaluate and nothing justifying delivery.
The two ephemeral publishers are deliberately left alone. They are
server-generated, addressed to a single user, and not channel content; the
delete variant has no channel to evaluate against.
Push notifications downgrade to id-only for a denied recipient instead of being
suppressed, so the notification still arrives and the device fetches the message
by id — a fetch that re-runs the gate live. A recipient with no cached session
attributes is treated as denied, because a notification is content leaving the
server rather than a request to authorize.
No change was needed for the policy-change fan-out: permission_policy_updated
already reaches every connected client and channel_access_control_updated every
channel member, and both fire on policy type rather than on the actions a policy
carries, so a policy with only access_channel already broadcasts. Reacting to
them by refreshing the channel list is client work.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* webapp: make a channel disappear when access is lost, and say so
The server suppresses a denied channel rather than removing the user from it, so
the client is left holding data for a channel it can no longer show. Nothing in
the existing flow prunes: RECEIVED_CHANNELS is additive, so a filtered response
adds what is visible and never drops what stopped being.
reconcileChannelAccess diffs the known memberships against what the refreshed
list still returns and dispatches LEAVE_CHANNEL for the difference. That action
is local only — no request is made, and the membership, followed threads, saved
posts and unread counts all survive on the server, which is what lets a channel
come back intact with its accumulated mentions once access returns. DMs and GMs
are never dropped: they are exempt server-side, so their absence never means
denied. A failed refresh drops nothing, since reading a network error as "all
channels denied" would hide channels the policy still allows.
Losing the channel in view is the one case worth interrupting for, and it gets
its own dialog rather than reusing RemovedFromChannelModal — the user has not
been removed and has lost nothing, and telling them otherwise would be both
wrong and unactionable.
Reconciliation runs on websocket reconnect (where a session may have moved to a
network the policy judges differently), on team switch, on both policy-change
events, and on a 15-minute timer. The timer is the only thing that would ever
notice a rule keyed on the session's device or network going stale, since
nothing changes server-side for it to broadcast.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Evaluate RBAC before the policy in the mention and member-count gates
Both put the access_channel evaluation ahead of the role check, so a channel RBAC
already denied still paid a PDP round trip. Reordering makes && short-circuit the
way it does in the other six gates, which matters most on the mention path: it
runs per recipient per mention inside websocket fan-out.
Also pins the invariant the render-decision registry's doc comment asserts — that
a render "allowed" can never disagree with enforcement — for access_channel, the
way it was already pinned for the file actions. The client lays out affordances
from the render decision; drift would mean offering a channel the gate then
refuses.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Key the per-request access_channel memo by user, not just channel
One request can ask about more than one user: a webhook evaluates its owner, a
notification decision evaluates the recipient, and neither is the requesting
session. Keyed by channel alone, the first answer was reused for everybody —
handing one user another user's decision, in either direction.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Fix flaky ConvertGmToChannelModal tests
The modal gates its content behind a hardcoded 1200ms loading animation,
but the tests only allowed 1500ms to wait for that content. That left
~150ms of slack -- the tests take 1220-1350ms even on an idle machine --
so they timed out on loaded CI runners (channels shard 2/4).
Raise the wait to 5000ms, matching the convention used elsewhere in the
suite, and lift the per-test budget above jest's 5s default so the
interactions that follow the wait still have room.
Also reset the shared convertGroupMessageToPrivateChannel mock between
tests. Its `mockResolvedValueOnce` queue is not consumed when a test
fails before clicking Confirm, so the queued response leaked into the
next test and turned one timeout into two failures, obscuring the cause.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Lot of cleanup and code minimisation
* Comment cleanup and some optimisations
* Paginated channel APIsls
* Removed automatic periodic channel reconciliation
* Minor cleanup
* Address CodeRabbit review findings
Six of the eight findings held up against the code:
evaluateAccessChannel failed open when the governance check errored. governed
stayed false, so any channel without its own PolicyEnforced flag was allowed
without ever reaching the PDP — while the log said "evaluating anyway". A
transient store failure could therefore bypass every system-scoped policy. It
now evaluates, matching the log and the fail-secure posture of the other error
paths in that function.
channelMembersMinusGroupMembers applied the access_channel gate behind a
sysconsole permission, which contradicts the exemption the policy-administration
surfaces rely on and diverges from teamMembersMinusGroupMembers. Removed.
A denied push recipient fell back to GenericNotification when the notification
interface is absent or unlicensed, and that form still carries the channel name.
Denied recipients now fall back to GenericNoChannelNotification.
threadsForUserPage read a zero PageSize as "no results" where the store reads it
as 30, so per_page=0 returned nothing once the feature was active. It now uses
the store's default.
GetChannelsUserNotIn filtered after the store had paginated. It goes through
fillChannelPage like its siblings. The function has no callers today; this keeps
it correct if one returns.
reconcileChannelAccess treated an archived channel as denied, because the channel
list omits archived channels whatever the policy says — dropping local state and
potentially showing the access-denied modal. Archived channels are now excluded
from the comparison, like DMs and GMs.
Two findings were left alone. The unrestricted-session bypass in
GetPostIfAuthorized is the documented decision that local mode and system admins
are not exempt from access_channel, matching HasPermissionToFileAction. Filtering
getChannelMembersForUser by the requester rather than the queried user would give
an admin a wrong answer about another user's memberships, and would diverge from
getChannelsForUser, which filters by the queried user for the same reason.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Filter channel memberships for the session, not the queried user
getChannelMembersForUser is gated on SessionHasPermissionToUser, which grants on
manage_system or edit_other_users — the latter delegatable to a non-admin. Both
branches evaluated access_channel for c.Params.UserId, so a requester asking
about someone else was handed channel IDs their own policy denies. That also sits
badly with system admins deliberately not being exempt from access_channel.
Both branches now evaluate for the session user. Every first-party caller passes
its own user id, so this only changes the third-party API path.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Prevented self lockout
* Lint fix
* WIP
* Accounted for change of feature flag name
* Filled filtered page
* Used session user ID instead of queried user
* Avoided duplicate channel fetch on websocket reconnect
reconcileChannelReadAccess() already fetches all-teams channels for
ABAC-enabled users, so the unconditional fetchAllMyTeamsChannels()
right after it started a second, overlapping request on every
reconnect. Only fetch directly when ABAC channel access is disabled.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* test fixes
* Finish the ChannelAccessABACPermission flag removal on this branch
Merging add_access_channel_action brought in the removal of the
ChannelAccessABACPermission flag, but the enforcement work on this branch
still read it, so server and webapp both stopped building.
Server: channelReadAccessEnforcementActive() drops the flag term. The
PermissionPolicies half of the old IsChannelAccessABACPermissionEnabled()
is already covered by attributeBasedAccessControlEnabled(), so the gate is
unchanged apart from the sub-flag that no longer exists. Tests drop the
flag from SetupConfig, and the two cases that only asserted what the
flag-off path costs are gone with it.
Webapp: reconcileChannelReadAccess() no longer gates itself, so the
reconnect path calls it instead of choosing between it and a plain
fetchAllMyTeamsChannels() -- reconcile does that fetch itself.
websocket_actions.test.ts now stands the reconciliation in as a single
action, since channel_read_access.test.ts covers its internals.
The merge also left channel_settings_permissions_policy_tab.tsx reading
channelReadAccessEnabled in the self-lockout check this branch added, and
without the getCurrentUserId import that check needs. The save
confirmation now fires whenever a rule carries channel_read_access.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019rKsgkMi9SKwSMWugD2owY
* Answer the read-access gate in TestGetUsersNotInChannelAbacMatchOnly
Removing the feature flag made channel_read_access enforcement active on
every fixture that enables ABAC and holds an Enterprise Advanced license.
This test installs a mock access-control service with only a
QueryUsersForResource expectation and saves a channel policy, so reading
the target channel now reaches the PDP and testify panics on the
unexpected ActionHasPermissionPolicy call.
The gate has its own coverage; answer it permissively here so the test
keeps asserting the getUsers dispatcher rather than the gate. Verified
against a local Postgres: the test fails without the two expectations and
passes with them.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019rKsgkMi9SKwSMWugD2owY
* Answer the read-access gate in the flagged-post report tests
Same fallout as the getUsers dispatcher test: with channel_read_access no
longer behind a feature flag, generating a flagged-post report passes
through the gate before the file decision under test is reached, and these
fixtures' mock access-control service has no expectation for
ActionHasPermissionPolicy, so the handler panicked and the request died with
an EOF.
Report "not governed" for the channel-access actions in all three fixtures,
leaving the download decision the only thing that can omit the attachments.
Verified against a local Postgres: all three tests fail without it and pass
with it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019rKsgkMi9SKwSMWugD2owY
* Handled bookmark events
* Filtered other WS message broadcasts as well
* i18n fix
* i18n fix
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
* fixes
* Address review feedback on channel read access
- Reject broadcast events per connection, and record a post delivery only
for events actually sent
- Hook thread_updated and the shared-channel channel_updated to
channel_read_access
- Keep a channel's access policy when it is archived; only a permanent
delete removes it
- Redact the bookmark sort, view sort, channel patch and post patch
responses for read-denied sessions
- Filter recommended channels by read access, and send
channel_access_control_updated to denied members without the channel
- Send the touched actions with permission_policy_updated; the webapp
reconciles only for channel_read_access, one call at a time with jitter,
and no longer on every team switch
- Check read access after RBAC in GetPostIfAuthorized, and drop the event
when the read hook gets a malformed argument
- Run the membership-post filter on every search page, and document how
FetchUntil pages
- Answer channel_read_access render decisions through the enforcement gate
- Test fixes from review
- Restore the govet testdata, agents submodule and Playwright env baseline
from the base branch
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Scrubbed email notification content
* Stub ActionHasPermissionPolicy in team ABAC test helper
Notification emails now check channel read access in a background
goroutine. enableTeamABAC installed a bare AccessControl mock, so the
email path hit an unexpected mock call and panicked the api4 test binary.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UDPG2BQzkJromdKj8YhTWY
* Added a central channel WS event filtering
* Stub channel read-access check in ABAC test mocks
The central channel WS event filter asks AccessControl.ActionHasPermissionPolicy
on every published post once ABAC is on. Access-control tests installed bare
mocks, and a mock left by one subtest is still in place while the next
subtest's setup posts join messages, so the unexpected call panicked the test
binary (TestCreateAccessControlPolicyPreservesSystemManagedFields in CI).
api4 access-control tests now build mocks through newMockAccessControlService,
which answers that check; setMockACS in app gets the same stub.
Also shield the masking-off api4 tests from MM_FEATUREFLAGS_* variables in the
developer's shell: env overrides beat config, so an exported
AttributeValueMasking=true cancelled maskingOffTestConfig in the IDE.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Restore agents docs submodule pointer to match base branch
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* CI
* Stub channel read-access governance in api4 ABAC test mocks
Publish now asks whether channel_read_access governs a channel before
attaching the read-access hook, so mocks without that answer panicked in
the burn-on-read and team-directory ABAC tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* merge fixes
* Filter channel-wide plugin websocket events by channel_read_access
attachChannelReadAccessHook skipped every custom_* event, so a plugin
event broadcast to a channel reached members the channel's read rules
deny. The Agents plugin streams bot replies this way
(custom_mattermost-ai_postupdate with the text in "next"), so a denied
member received the reply text even though its posted event was dropped.
Plugin events with a channel broadcast now get the read-access hook like
any other channel event. Plugin events addressed to a single user carry
no channel to evaluate and are unchanged.
* Exclude read-access-denied channels from unread counts
The threads list already dropped threads in channels the
channel_read_access policy denies, but every count beside it was summed
in the store over all memberships: the Threads totals, teams/unread
(channel and thread counts), the single-team unread and the mobile push
badge. A denied user saw a badge for content they couldn't open, and
could never clear it, since clearing it means opening the channel.
channelReadAccessDeniedChannelIDs works out the user's denied channels
once per request. The thread count queries take them through a new
GetUserThreadsOpts.ExcludeChannelIds, Thread().GetTeamsUnreadForUser and
User().GetUnreadCount take them as a parameter, and the per-channel
unread rows behind the team counts are filtered in the app.
GetTeamsUnreadForUser, GetTeamUnread and getUserBadgeCount now take a
request.CTX. BuildPushNotificationMessage shares one memo between its
content gate and the badge, so the post's channel is evaluated once.
GetUnreadCount now uses COALESCE(SUM(...), 0): with every channel
excluded, SUM over no rows returned NULL and the scan failed.
* Gate channel_read_access behind the ChannelPermissionActions feature flag
The flag is off by default. While it is off, saving a policy that uses
channel_read_access is rejected, the policy editors don't offer the action,
and stored rules aren't enforced. Tests that exercise read-access
enforcement turn the flag on.
Also stops TestNotificationEmailWithholdsContentsUnderReadAccessPolicy from
panicking: posts it creates sent background push notifications whose badge
count asked the mock ACS an unanswered question.
* Fix permission policy details imports broken by merge
* Added feature flag to playwright
* Add ChannelPermissionActions to the support packet golden config
* restored go files
* Count denied channels in the push badge again
The push badge is built on the push hub's goroutine, which has no session
for the recipient: not for a new post, and not for a clear or badge update
either, since those go to the user's other devices. A channel_read_access
rule on session attributes always denied there, so the badge dropped
channels the device could read, and every push evaluated each of the
recipient's channels with no decision cache.
getUserBadgeCount goes back to summing every membership without asking
the PDP, and BuildPushNotificationMessage no longer shares a memo with it.
User().GetUnreadCount loses its excludeChannelIDs parameter, which only
the badge used; the COALESCE fix stays. The in-app counts (Threads totals,
teams/unread, team unread) still leave denied channels out.
* Add and enforce the Channel Write Access action (#38541)
* Enforce ABAC access_channel in the channel permission gates
ABAC could say who may belong to a channel and what may be done with its
attachments, but not whether a session may read the channel right now. This
wires the access_channel action into the gates every channel surface already
goes through, so one evaluation covers them all rather than N call sites.
HasPermissionToAccessChannel is ANDed into SessionHasPermissionToChannel,
SessionHasPermissionToChannels, SessionHasPermissionToChannelByPost,
HasPermissionToChannel, SessionHasPermissionToReadChannel,
HasPermissionToReadChannel, HasPermissionToResolveChannelMention,
HasPermissionToChannelMemberCount and GetPostIfAuthorized. Each gate's role
logic moves into an RBACOnly sibling and the exported name becomes a thin
wrapper, so there is one AND site per gate instead of one per early return —
and the exemptions the plugin API and the policy-administration endpoints need
fall out for free, visible at the call site rather than hidden in a flag.
It gates every permission, not just the read-shaped ones: access_channel is a
prerequisite for interacting with a channel at all, so scoping it to reads
would leave the write paths reachable for a session that cannot see it. System
admins and local-mode sessions are evaluated too, matching the file actions,
which have no such bypass either. DMs and GMs are exempt. Nothing is evaluated
until the flag, the ABAC config switch, an Enterprise Advanced licence and a
policy that actually declares the action are all in place; subject-build and
evaluation failures deny.
Two permissive fallbacks had no channel to evaluate against and would have been
holes: SessionHasPermissionToReadPost and SessionHasPermissionToChannelByPost
both fell through to a system-wide permission when the post's channel could not
be resolved. Both now fail closed while the policy is being enforced.
A per-request memo collapses the repeat evaluations — the gates nest, so one
getPost would otherwise cost four PDP round trips — and carries the denial fact
so SetChannelPermissionError can return a distinct error id. Clients need "you
cannot view this channel right now" apart from "you were removed from this
channel"; only the first can resolve itself.
HasPermissionToChannelByPost is deleted: no non-test callers, and leaving an
ungated gate around invites the next one.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Close the access_channel enforcement points outside the gates
The gates cover most surfaces, but a handful grant channel access by other
means and never reach them. Each is now checked explicitly:
- Channel fetch by id/name/name-for-team granted on a team-level
read_public_channel or manage_team, so a denied session could read any open
channel on its team and team admins could read any private one.
- The discoverable non-member view is reached *because* the gate denied, and
IsDiscoverableJoinAllowed only evaluates membership. A denied session was
handed the channel's name, header and purpose plus a way to join.
- getPostInfo re-grants to anyone who could join the channel. The check is
applied on its own rather than through the read gate, and the 404 is kept so
a denial stays indistinguishable from a missing post.
- Post create, draft upsert and their app-layer twin fall back to a team-level
create_post_public.
- addChannelMember's self-join and the join-request queue would otherwise be
the way around the policy. Joining is a write, so these are genuine blocks
rather than suppression; who may be added is still membership's question.
- The uploader of a file proceeds through getFile and its four siblings with
the channel permission already false.
- channelMembersMinusGroupMembers returns channel members behind a sysconsole
permission alone. Its moderation neighbours are left policy-blind on purpose,
and say so: they are permission-scheme configuration, not channel content.
- Both flagged-post reports had never been gated on the channel at all, only on
team reviewer status, so a reviewer could pull a full report — file bytes
included — for a channel the policy hides from them. Reviewers are not exempt.
The read marker (viewChannel, readMultipleChannels, readAllInTeam) had no
channel check of any kind. viewChannel now reports the denial before ViewChannel
runs, so nothing moves the read marker or the active channel; it is the client's
detection point. The channel being left behind is dropped rather than reported,
so navigating away from a channel you just lost does not fail. The batch and
team-wide variants suppress per channel and mark the rest, leaving the hidden
channels' unread and mention counts intact for when access returns.
Exempted through the RBACOnly siblings: the plugin API, whose surfaces are out
of scope and must not shift under plugin authors; the policy-administration
endpoints, so a mis-scoped policy stays repairable; and the render-decision
endpoint, which is how the client learns it has been denied at all.
Denials now carry api.channel.access_channel.abac_denied.app_error instead of
the generic permission error, across ~80 call sites, taking the channel from the
gate call so the two cannot drift.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Filter denied channels out of the discovery and list surfaces
A 403 stops a session opening a channel, but the channel is still visible until
it is gone from the lists. A name in Browse Channels or an autocomplete hit is
itself the disclosure: it tells a session that a channel it cannot read exists.
Sidebar and channel-member streams are filtered in the handler, not the app
layer. Both write JSON incrementally and stop on `len(page) < pageSize`, so a
page containing one denied channel would look like the last page and silently
truncate the entire remaining list. The cursor advance and the termination test
now run against the raw page, and the comma logic tracks whether anything has
been written rather than assuming a full page.
Post search, saved posts and file search needed nothing: they already dedupe per
channel through HasPermissionToReadChannel, which is now policy-aware.
The threads list had no channel-permission filter of any kind — the store scopes
it by ChannelMembers, and a denied user keeps their membership, so threads from
hidden channels surfaced. It gets the new utils.FetchUntil, which re-reads from
the cursor until a page is full, because filtering after the database has already
paginated would otherwise hand the client a short page and stop its scrolling.
The helper is capped and reports when it gave up, so a user denied nearly every
channel cannot drive unbounded round trips.
Thread unread totals and channel unread aggregates are deliberately left as the
store computed them, so a hidden channel can still contribute a badge. Making
them agree with what is visible is a larger change than this one.
SearchAllChannels stays unfiltered: its callers are the System Console channel
list, the data-retention picker and the policy channel search, all of which exist
to administer channels an admin may not be a member of.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Drop denied channels from websocket fan-out and push notifications
The gates decide what a session can fetch, but a post arriving over the
websocket was never fetched, and a push notification carries the body without
the recipient asking. Both deliver content past the enforcement points.
accessChannelBroadcastHook rejects a channel-scoped event per recipient. The
platform honours Reject() before the event burns a sequence number or enters the
reconnect replay queue, so a dropped event leaves no gap. It is registered from
publishWebsocketEventForPost — which covers posted and every post_edited that
routes through it, including the acknowledgement, content-flagging and
shared-channel paths — plus post_deleted, which publishes its sanitized and
sensitive copies directly and carried no hooks at all. It fails closed on a
connection with no session: a rule may reference the session, so there is
nothing to evaluate and nothing justifying delivery.
The two ephemeral publishers are deliberately left alone. They are
server-generated, addressed to a single user, and not channel content; the
delete variant has no channel to evaluate against.
Push notifications downgrade to id-only for a denied recipient instead of being
suppressed, so the notification still arrives and the device fetches the message
by id — a fetch that re-runs the gate live. A recipient with no cached session
attributes is treated as denied, because a notification is content leaving the
server rather than a request to authorize.
No change was needed for the policy-change fan-out: permission_policy_updated
already reaches every connected client and channel_access_control_updated every
channel member, and both fire on policy type rather than on the actions a policy
carries, so a policy with only access_channel already broadcasts. Reacting to
them by refreshing the channel list is client work.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* webapp: make a channel disappear when access is lost, and say so
The server suppresses a denied channel rather than removing the user from it, so
the client is left holding data for a channel it can no longer show. Nothing in
the existing flow prunes: RECEIVED_CHANNELS is additive, so a filtered response
adds what is visible and never drops what stopped being.
reconcileChannelAccess diffs the known memberships against what the refreshed
list still returns and dispatches LEAVE_CHANNEL for the difference. That action
is local only — no request is made, and the membership, followed threads, saved
posts and unread counts all survive on the server, which is what lets a channel
come back intact with its accumulated mentions once access returns. DMs and GMs
are never dropped: they are exempt server-side, so their absence never means
denied. A failed refresh drops nothing, since reading a network error as "all
channels denied" would hide channels the policy still allows.
Losing the channel in view is the one case worth interrupting for, and it gets
its own dialog rather than reusing RemovedFromChannelModal — the user has not
been removed and has lost nothing, and telling them otherwise would be both
wrong and unactionable.
Reconciliation runs on websocket reconnect (where a session may have moved to a
network the policy judges differently), on team switch, on both policy-change
events, and on a 15-minute timer. The timer is the only thing that would ever
notice a rule keyed on the session's device or network going stale, since
nothing changes server-side for it to broadcast.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Evaluate RBAC before the policy in the mention and member-count gates
Both put the access_channel evaluation ahead of the role check, so a channel RBAC
already denied still paid a PDP round trip. Reordering makes && short-circuit the
way it does in the other six gates, which matters most on the mention path: it
runs per recipient per mention inside websocket fan-out.
Also pins the invariant the render-decision registry's doc comment asserts — that
a render "allowed" can never disagree with enforcement — for access_channel, the
way it was already pinned for the file actions. The client lays out affordances
from the render decision; drift would mean offering a channel the gate then
refuses.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Key the per-request access_channel memo by user, not just channel
One request can ask about more than one user: a webhook evaluates its owner, a
notification decision evaluates the recipient, and neither is the requesting
session. Keyed by channel alone, the first answer was reused for everybody —
handing one user another user's decision, in either direction.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Fix flaky ConvertGmToChannelModal tests
The modal gates its content behind a hardcoded 1200ms loading animation,
but the tests only allowed 1500ms to wait for that content. That left
~150ms of slack -- the tests take 1220-1350ms even on an idle machine --
so they timed out on loaded CI runners (channels shard 2/4).
Raise the wait to 5000ms, matching the convention used elsewhere in the
suite, and lift the per-test budget above jest's 5s default so the
interactions that follow the wait still have room.
Also reset the shared convertGroupMessageToPrivateChannel mock between
tests. Its `mockResolvedValueOnce` queue is not consumed when a test
fails before clicking Confirm, so the queued response leaked into the
next test and turned one timeout into two failures, obscuring the cause.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Lot of cleanup and code minimisation
* Comment cleanup and some optimisations
* Paginated channel APIsls
* Removed automatic periodic channel reconciliation
* Minor cleanup
* Address CodeRabbit review findings
Six of the eight findings held up against the code:
evaluateAccessChannel failed open when the governance check errored. governed
stayed false, so any channel without its own PolicyEnforced flag was allowed
without ever reaching the PDP — while the log said "evaluating anyway". A
transient store failure could therefore bypass every system-scoped policy. It
now evaluates, matching the log and the fail-secure posture of the other error
paths in that function.
channelMembersMinusGroupMembers applied the access_channel gate behind a
sysconsole permission, which contradicts the exemption the policy-administration
surfaces rely on and diverges from teamMembersMinusGroupMembers. Removed.
A denied push recipient fell back to GenericNotification when the notification
interface is absent or unlicensed, and that form still carries the channel name.
Denied recipients now fall back to GenericNoChannelNotification.
threadsForUserPage read a zero PageSize as "no results" where the store reads it
as 30, so per_page=0 returned nothing once the feature was active. It now uses
the store's default.
GetChannelsUserNotIn filtered after the store had paginated. It goes through
fillChannelPage like its siblings. The function has no callers today; this keeps
it correct if one returns.
reconcileChannelAccess treated an archived channel as denied, because the channel
list omits archived channels whatever the policy says — dropping local state and
potentially showing the access-denied modal. Archived channels are now excluded
from the comparison, like DMs and GMs.
Two findings were left alone. The unrestricted-session bypass in
GetPostIfAuthorized is the documented decision that local mode and system admins
are not exempt from access_channel, matching HasPermissionToFileAction. Filtering
getChannelMembersForUser by the requester rather than the queried user would give
an admin a wrong answer about another user's memberships, and would diverge from
getChannelsForUser, which filters by the queried user for the same reason.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Filter channel memberships for the session, not the queried user
getChannelMembersForUser is gated on SessionHasPermissionToUser, which grants on
manage_system or edit_other_users — the latter delegatable to a non-admin. Both
branches evaluated access_channel for c.Params.UserId, so a requester asking
about someone else was handed channel IDs their own policy denies. That also sits
badly with system admins deliberately not being exempt from access_channel.
Both branches now evaluate for the session user. Every first-party caller passes
its own user id, so this only changes the third-party API path.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Prevented self lockout
* Lint fix
* WIP
* Accounted for change of feature flag name
* Filled filtered page
* Add and enforce the channel_write_access ABAC action
Adds channel_write_access to permission policies and enforces it on every
write to a channel and its content.
The read gate is generalised rather than copied: channel_read_access.go
becomes channel_access.go, with the memo, subject builder and evaluator
parameterised by action, and thin read/write wrappers over them.
Writes stay ungated unless a channel_write_access policy governs the channel
— a deployment that only restricts reading must not start refusing posts.
Once one does govern, both channel-access policies must allow, and a denial
reports which one refused so clients can tell them apart.
Enforcement rides the existing choke points (SessionHasPermissionToChannel,
SessionHasPermissionToChannels, SessionHasPermissionToChannelByPost,
HasPermissionToChannel) via a new isChannelWritePermission allowlist, plus
explicit gates on the surfaces that reach none of them: the create_post_public
fallbacks, drafts, content flagging, setChannelMembers, addChannelMember,
requestJoinChannel, burnPost and moveThread's destination.
Bot sessions, incoming webhooks and plugin writes are exempt: they carry no
interactive session, so a rule over user.session.* has nothing to evaluate.
The typing indicator drops to the RBAC-only check for the same reason.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rcr34QjQnRGs87RxJyUASJ
* Surface Channel Write Access in the clients
Adds the action to both policy editors and disables the composer for a
session the policy denies.
The composer resolves its decision through the existing useRenderPermission
hook, the same path the file-upload button already uses, so switching
channels re-keys the fetch and the existing websocket handlers invalidate it
on a policy change. It fails open while the decision is in flight: every
write endpoint enforces the policy itself, and failing closed would grey the
composer out on the first visit to every channel.
A denial gets its own placeholder rather than reusing the read-only one, so
the cause is not confused with an RBAC read-only channel.
No confirmation dialog and no self-lockout guard: unlike losing sight of a
channel, losing the ability to post is visible and recoverable.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rcr34QjQnRGs87RxJyUASJ
* Test channel_write_access enforcement and the governing rule
Adds api4 surface tests (every gated write denies with the write error id;
the read marker, pin, thread follow and leaving a channel still work) and
app-layer gate tests covering the truth table, the DM/GM and bot exemptions,
memoisation, fail-closed evaluation, and the three preconditions that keep
the gate inert.
Two of these pin the rule that a write policy has to be in play before either
policy can refuse: TestChannelWriteAccessRequiresReadAccess for the case where
one is, TestChannelWriteAccessInertWithoutAWritePolicy for the case where none
is. The latter is why TestChannelReadAccessDoesNotGateWrites is still true —
its fixture now leaves channel_write_access ungoverned, which is exactly the
condition the test was always describing.
The permission classification test now requires every channel-scoped
permission to be a read, a write, or explicitly neither, so a new one cannot
silently escape both gates.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rcr34QjQnRGs87RxJyUASJ
* Keep policy administration outside the write gate
manage_channel_access_rules is now classified as neither a read nor a write.
Gating it would make a policy that denies its own author unfixable, because
the gate binds system admins too. Every call site already asks RBAC-only;
this records why that has to stay true.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rcr34QjQnRGs87RxJyUASJ
* Used session user ID instead of queried user
* Fix check-i18n on both the server and the webapp
Two separate causes, both in en.json handling.
The server key was invisible to the extractor. mmgotool i18n extract only
collects string literals passed to NewAppError, and SetPermissionError was
computing the id through ChannelAccessDeniedErrorID, so
api.channel.channel_write_access.abac_denied.app_error never appeared as a
literal anywhere and the check wanted it deleted. Its read counterpart
survived only because app/post.go still spells that one out.
Both ids are now written out inline at the one place that raises them, and
the helper is gone rather than left alongside them — a mapping in two places
is a mapping that drifts. The audit-level check goes back to comparing the
literals too.
The webapp key was two entries too early: create_post.write_access_denied
sorts after create_post.write, not after create_post.read_only.
Verified with the commands CI runs: `make i18n-extract` now leaves
server/i18n/en.json unchanged, and `npm run i18n-extract:check` passes.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rcr34QjQnRGs87RxJyUASJ
* cleanupo
* cleanup
* Blocked UI elements when nuser doesn't have write permission
* Avoided duplicate channel fetch on websocket reconnect
reconcileChannelReadAccess() already fetches all-teams channels for
ABAC-enabled users, so the unconditional fetchAllMyTeamsChannels()
right after it started a second, overlapping request on every
reconnect. Only fetch directly when ABAC channel access is disabled.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* Fix channel write-access gaps found by CodeRabbit review
- Typing indicator used the RBAC-only permission check, so a session
denied channel_write_access by policy could still emit user_typing
events. Route it through the full SessionHasPermissionToChannel check
like every other write action.
- moveThread only required write access to the destination channel;
moving a thread also removes it from the source channel, so require
write access there too.
- userCreatePostPermissionCheckWithApp used the non-recording
HasChannelWriteAccessByID, so this path's denial never recorded which
policy refused, leaving clients unable to distinguish a write denial
from a generic permission error. Use EnforceChannelWriteAccessByID
like the other write gates.
- The composer could still submit an edit after policy evaluation denied
write access, since handleSubmitWrapper/handleSubmitWithEvent didn't
check readOnlyChannel and EditPostFooter's Save button was never
disabled.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MtYcqngRsmYpbYKBL1rqFf
* Add test coverage for the edit-mode write-access denial guard
CodeRabbit asked for a regression test on the composer fix in
01f0f988e: cover that the edit Save button is disabled when
channel_write_access denies, and enabled when it allows.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MtYcqngRsmYpbYKBL1rqFf
* Avoid duplicate channel query in SessionHasPermissionToChannelByPost
sessionHasPermissionToChannelByPostRBAC already loads the channel to
check the team-permission fallback; SessionHasPermissionToChannelByPost
was loading it again for write-access enforcement. Return the channel
from the RBAC helper and reuse it instead of querying twice.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MtYcqngRsmYpbYKBL1rqFf
* Prevented managing channel policies when user doesn't have write permission
* removed ABAC chec from scheduled post job
* Moved leftover abac checks from app to API
* Permitted join channel action
* test fixes
* fixed playwright lint error
* Finish the ChannelAccessABACPermission flag removal on this branch
Merging add_access_channel_action brought in the removal of the
ChannelAccessABACPermission flag, but the enforcement work on this branch
still read it, so server and webapp both stopped building.
Server: channelReadAccessEnforcementActive() drops the flag term. The
PermissionPolicies half of the old IsChannelAccessABACPermissionEnabled()
is already covered by attributeBasedAccessControlEnabled(), so the gate is
unchanged apart from the sub-flag that no longer exists. Tests drop the
flag from SetupConfig, and the two cases that only asserted what the
flag-off path costs are gone with it.
Webapp: reconcileChannelReadAccess() no longer gates itself, so the
reconnect path calls it instead of choosing between it and a plain
fetchAllMyTeamsChannels() -- reconcile does that fetch itself.
websocket_actions.test.ts now stands the reconciliation in as a single
action, since channel_read_access.test.ts covers its internals.
The merge also left channel_settings_permissions_policy_tab.tsx reading
channelReadAccessEnabled in the self-lockout check this branch added, and
without the getCurrentUserId import that check needs. The save
confirmation now fires whenever a rule carries channel_read_access.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019rKsgkMi9SKwSMWugD2owY
* Answer the read-access gate in TestGetUsersNotInChannelAbacMatchOnly
Removing the feature flag made channel_read_access enforcement active on
every fixture that enables ABAC and holds an Enterprise Advanced license.
This test installs a mock access-control service with only a
QueryUsersForResource expectation and saves a channel policy, so reading
the target channel now reaches the PDP and testify panics on the
unexpected ActionHasPermissionPolicy call.
The gate has its own coverage; answer it permissively here so the test
keeps asserting the getUsers dispatcher rather than the gate. Verified
against a local Postgres: the test fails without the two expectations and
passes with them.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019rKsgkMi9SKwSMWugD2owY
* Answer the read-access gate in the flagged-post report tests
Same fallout as the getUsers dispatcher test: with channel_read_access no
longer behind a feature flag, generating a flagged-post report passes
through the gate before the file decision under test is reached, and these
fixtures' mock access-control service has no expectation for
ActionHasPermissionPolicy, so the handler panicked and the request died with
an EOF.
Report "not governed" for the channel-access actions in all three fixtures,
leaving the download decision the only thing that can omit the attachments.
Verified against a local Postgres: all three tests fail without it and pass
with it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019rKsgkMi9SKwSMWugD2owY
* Answer the channel-access gate in the api4 access-control tests
Carrying the flag removal through the write-access work made
channel_write_access enforcement active in every fixture that enables ABAC
and holds an Enterprise Advanced licence. Channel-scoped policy
administration passes through that gate before the handler is reached, and
these fixtures' mock access-control service has no expectation for
ActionHasPermissionPolicy, so twelve subtests died with the handler
panicking and the request returning EOF.
ungovernedChannelAccess reports "not governed" for the channel-access
actions, sitting alongside the file allowSelfInclusion helper. The
policy-administration gate keeps its own coverage in
channel_write_access_test.go.
Discovery mode also lists one more action now that channel_write_access is
always registered, so both discovery-mode counts move from three to four.
Verified against a local Postgres: every one of these fails before the
change and passes after it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019rKsgkMi9SKwSMWugD2owY
* Restore the i18n string the OSS-only extraction dropped
Editing server/i18n/en.json means running `make i18n-extract` per
server/AGENTS.md, but I ran it without the enterprise module in the go
workspace. The extractor therefore only saw OSS sources, judged
app.pdp.action_has_permission_policy.app_error orphaned and removed it.
It is not orphaned: enterprise's access_control/decision.go raises it
twice and decision_test.go asserts on its ID, so the enterprise
Check i18n job — which extracts across both trees — asked for it back.
Re-running the extraction with the paired enterprise commit in the
workspace reproduces this file exactly, and the OSS side stays happy
(the key is present on the base branch, whose CI is green).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019rKsgkMi9SKwSMWugD2owY
* Removed an invalid comment
* Fixed a playwright test
* Handled bookmark events
* Filtered other WS message broadcasts as well
* Fixed a couple of bugs
* fixed bad marge
* Added policy metrics for testing
* Handled recaps
* Security fixes
* No abac in user typing indicator
* UIsed cache based function
* Added ceched store function used extensively in ABAC policy evaluation
* Attaching hoook only when needed
* Added channel management channel permission action
* Some improvements
* lint fix
* i18n fix
* i18n fix
* Fixed tests
* Stub channel-access governance in the burn-on-read ABAC tests
Posting now passes the channel_write_access gate, which asks the ACS whether a
policy governs the action. The burn-on-read mocks only stubbed AccessEvaluation,
so the handler panicked on the unexpected call and the client saw EOF.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Check channel read access in the recap job and /join
HasPermissionToChannel is RBAC only, so its sessionless callers lost the
channel_read_access check. The recap job now evaluates the user's read
rules before summarizing a channel (on user attributes alone, so a rule
needing session attributes denies), and /join gates joining on read
access as the REST self-join does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Gate pinning and acknowledging on channel write access
Both change what every member of the channel sees, like a reaction, so
channel_write_access now governs pin/unpin and acknowledge/unacknowledge.
The webapp hides Pin and disables the Acknowledge button when the
channel's write rules deny the user.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Gate channel property field definitions on management access
A channel-scoped field definition is the channel's schema, like its
options, so creating, patching and deleting one now goes through
channel_management_access instead of channel_write_access.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Collapse the per-action channel-access tests
TestChannelWriteAccessAction and TestChannelManagementAccessAction become
one table over both actions. The api4 DoesNotGate tests and
TestChannelAccessActionsIgnoreReadAccess repeated the matrix the app-level
truth tables already cover, so they are dropped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Use ensureFeatureFlag in the channel access policy admin spec
skipIfFeatureFlagNotSet no longer exists, so the Playwright type check
failed. Both tests request the same flag combination, so the server
restarts at most once for the file.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Gate incoming webhook setup on channel write access
A hook posts into its channel with no session to evaluate later, so a
user the channel's write rules deny could set one up and post through
it. Creating a hook, and moving an existing hook into a channel, now go
through the write gate.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Check a scheduled post update against its stored channel
The update is saved to the channel the post was scheduled in, but the
create-post and write-access checks ran against the channel_id in the
request body. A user denied writing to that channel could keep editing
the post by naming a channel they can write to. The handler now pins the
channel and thread to the stored values before the checks, as it already
does for the type.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Gate each permission_policy_updated step on the actions it touched
The webapp cleared every render decision and refetched posts on every
permission policy change, even an auto-add toggle that changes no rule.
Each step now runs only when an action it depends on changed:
- render decisions (which the channel write and management gates read)
clear when any permission action changed
- loaded posts refresh for download_file_attachment or channel_read_access
- the channel list reconciles for channel_read_access
A server that predates the action list is treated as having changed
every action.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FvkCrND4n9oyehQUa9V5QH
* Remove the test-only access control decisions metric
decisions_total counted every Evaluate call, including UI prefetch,
per-recipient broadcast filtering and list filters, so it did not
reflect enforcement. It was only added to aid local testing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Cache channel member roles per user and channel
The channel_read_access broadcast hook resolves each recipient's channel
role on the websocket hub. The roles were cached per user as a map of
every membership, so each hit decoded the whole map by reflection and
each miss re-read all of the user's memberships with a 4-join query.
GetChannelMemberRoles replaces GetAllChannelMemberRolesForUser. It takes
the channels to resolve, and the cache holds one entry per membership.
The role is decided by the membership row's scheme flags, so only
membership writes invalidate it: per key for updates and removals, a
purge for bulk writes and guest promotion/demotion. Only existing
memberships are cached, so joins need no invalidation.
In a local benchmark of GetSubjectChannelRole for a user in 1,000
channels, a hit drops from ~211µs and 4,020 allocs to ~0.74µs and 14
allocs, and a miss from ~2.5ms to ~0.53ms.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Benchmark the channel role lookup for a user in many channels
Measures GetSubjectChannelRole, which the channel_read_access broadcast
hook calls for every recipient of an event, on a cache hit and a miss.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Drop the unused dispatch in the channel settings modal
Master moved the textbox preview toggles into component state (#39152), so the merge left useDispatch with no callers and lint failed.
* Raise ChannelMemberRoles cache size to 500k entries
One entry per membership means a post in a large governed channel touches
one key per online member, so 50k evicted under a few busy channels and
turned hub lookups into DB queries.
* Benchmark the channel role lookup against a single channel
The roles cache holds one entry per membership, so the user's other
channels no longer affect the lookup; seeding 1,000 only slowed setup.
* Gate channel_write_access and channel_management_access behind ChannelPermissionActions
The three channel-access actions share the one flag, off by default. While
it is off, policies using write or management access are rejected, the
pickers hide them, enforcement doesn't evaluate them, and render decisions
for them fall back to the inactive default so the UI doesn't disagree with
enforcement.
* Turn on ChannelPermissionActions in the channel access tests
Tests that exercise write and management access enforcement, or read access
paths this branch added, now enable the flag. The flag-off picker tests also
check that write and management access are hidden.
* lint fix
* Improved session attribume management performance (#38919)
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
* Address review: tighten channel-access gates and fix rough edges
- Gate GET policy on the policy's own channel; channelId no longer stands in for it
- Require management access to assign/unassign a team policy to a channel
- Gate channel moderation patches on management access
- Answer UI decisions for channel actions inactive without Enterprise Advanced
- Reject channel-access rules on custom-role permission policies or with a rule role
- Redact responses of updatePost, restorePostVersion, updateChannel,
updateChannelPrivacy and restoreChannel for callers who can't read the channel
- Require read access on add-member only when adding yourself
- Treat post actions and dialog submit/execute as channel writes
- Check write access on the channel a slash command response redirects to
- Evaluate slash-command management access without a session too
- Evaluate stand-in sessions (no session ID) on the user's stored roles
- Keep a scheduled recap's existing channels on update; gate only added ones
- Fill empty i18n descriptions; correct the action search OpenAPI text
* Evaluate bots against channel_write_access
channel_write_access skipped evaluation for bot sessions, while
channel_read_access and channel_management_access evaluated them. A bot
could therefore post in a channel it could not read, and a user denied
by a write rule could post through a bot they own.
Bots are now evaluated like any user for all three actions. A rule that
should admit bots can say so, for example with user.isbot.
* Stop applying channel access policies to incoming webhooks
Per the updated Channel Write Access spec, incoming and outgoing webhooks
are not governed by channel access policies.
Creating, updating, fetching and deleting an incoming webhook now runs
the RBAC channel checks alone: the write checks are removed, and the read
checks use SessionHasPermissionToReadChannelRBACOnly, as on master.
Webhook delivery and outgoing webhooks already applied no policy.
* Evaluate channel read rules against the session that receives content
The permalink-preview and channel-mention websocket hooks evaluated the
recipient without the connection's session, and the push builder
evaluated the recipient without any of their device sessions. A read
rule over user.session.* then saw no session attributes: a rule that
requires one hid previews and mention links from allowed sessions until
a reload, and a rule that tolerates a missing one showed a denied
session the linked post and sent full push content to a denied device.
The two hooks now evaluate the connection's own session and withhold
the preview and mention links from a connection without one. A push
from a channel whose read access is governed is now always id-loaded
(generic without the id-loaded path), so each device fetches the post
with its own session.
* Redirect to a readable channel when town-square is hidden
getRedirectChannelNameForTeam returned town-square to anyone who could
join public channels. When a channel read-access policy denies
town-square, the server leaves it out of the user's channels, so every
redirect that fell back to it failed: login and team switches ended at
/select_team, and visiting the team ended on the channel-not-found page,
although the user could still read other channels.
A non-guest can't leave town-square, so having the team's other channels
loaded without it means the server is hiding it. The selector now returns
town-square only when the user's membership in it is loaded, the user's
first channel in the team when other channels are loaded, and
town-square when nothing is loaded for the team yet.
* Reconcile channel read access when the user's role changes
A channel read-access rule can target a system role or a channel role,
so a change to either can hide or reveal channels. The client only
refreshed its channel list on reconnect and on policy changes, so a
channel the user lost stayed in the sidebar and spun when opened.
The current user's system role change (user_role_updated) and channel
role change (channel_member_updated with different roles or scheme
flags) now reconcile the channel list while channel permission actions
are enabled. Member updates that leave the role alone, such as
notification preferences, do not.
* Log a failed channel-access governance check at error level
When the check fails, the action is treated as governed and every
evaluation in that channel fails closed. Logged at debug, the cause of
channels going quiet was invisible at default log levels.
* Address review: follow write denials in the post menu and role changes
- Hide the pin/unpin menu item when canPin is false, matching the P shortcut,
so a write-denied user isn't offered an action the server rejects.
- Invalidate a channel's cached render decisions when the user's channel role
changes, since the role is an input to the write and management decisions.
- Rebuild the Add workspace button when it becomes disabled: disabled was in
the wrong memo's dependency list.
- Expose the acknowledgement button's disabled state with aria-disabled.
* Filter team channel members and sidebar categories by the session
getChannelsForUser and getChannelMembersWithTeamData already evaluate read
access for the requester, so someone acting for another user cannot learn of
channels their own policy denies. The team-scoped channel members endpoint
and the sidebar category endpoints evaluated the queried user instead; they
now follow the session too.
* Shorten the channel settings read-only notice
Drop "These settings are shown for reference only." from the notice shown when an access policy denies channel management.
* CI
* type fixes
* Derive session attribute rewrite test age from TTL defaults
The case hardcoded a 10s seed age, which only crossed half the IP TTL
while that TTL was 15s. Master raised it to 60s (#39733), so the IP was
never rewritten and the test failed every run.
---------
Co-authored-by: Claude <noreply@anthropic.com>