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
This commit is contained in:
Claude committed 2026-09-16 09:57:31 +00:00
1 parent ecfba942af
commit 01f0f988e7
5 files changed
+18 -8

No files matched your search

+4 -4
View File
@@ -1563,10 +1563,6 @@ func moveThread(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !requireChannelWriteAccessByID(c, moveThreadParams.ChannelId) {
return
}
userHasEmailDomain := true
// Only check the user's email domain if a list of allowed domains is configured
if len(c.App.Config().WranglerSettings.AllowedEmailDomain) > 0 {
@@ -1588,6 +1584,10 @@ func moveThread(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !requireChannelWriteAccessByID(c, sourcePost.ChannelId) || !requireChannelWriteAccessByID(c, moveThreadParams.ChannelId) {
return
}
err = c.App.MoveThread(c.AppContext, c.Params.PostId, sourcePost.ChannelId, moveThreadParams.ChannelId, user)
if err != nil {
c.Err = err
+1 -1
View File
@@ -112,7 +112,7 @@ func userCreatePostPermissionCheckWithApp(rctx request.CTX, a *App, userId, chan
return model.MakePermissionErrorForUser(userId, []*model.Permission{model.PermissionCreatePost})
}
if !a.HasChannelWriteAccessByID(rctx, userId, channelId) {
if !a.EnforceChannelWriteAccessByID(rctx, userId, channelId) {
return model.MakePermissionErrorForUser(userId, []*model.Permission{model.PermissionCreatePost})
}
+1 -1
View File
@@ -27,7 +27,7 @@ func (api *API) userTyping(req *model.WebSocketRequest) (map[string]any, *model.
return nil, NewInvalidWebSocketParamError(req.Action, "channel_id")
}
if hasPermission, _ := api.App.SessionHasPermissionToChannelRBACOnly(request.EmptyContext(api.App.Log()), req.Session, channelId, model.PermissionCreatePost); !hasPermission {
if hasPermission, _ := api.App.SessionHasPermissionToChannel(request.EmptyContext(api.App.Log()), req.Session, channelId, model.PermissionCreatePost); !hasPermission {
return nil, NewInvalidWebSocketParamError(req.Action, "channel_id")
}
@@ -534,6 +534,10 @@ const AdvancedTextEditor = ({
}, [draft, handleDraftChange, focusTextbox]);
const handleSubmitWrapper = useCallback(() => {
if (readOnlyChannel) {
return;
}
const isEmptyPost = isPostDraftEmpty(draft);
if (isInEditMode && isEmptyPost) {
@@ -551,7 +555,7 @@ const AdvancedTextEditor = ({
}
handleSubmitWithErrorHandling();
}, [dispatch, draft, handleSubmitWithErrorHandling, isInEditMode, isRHS]);
}, [dispatch, draft, handleSubmitWithErrorHandling, isInEditMode, isRHS, readOnlyChannel]);
const [handleKeyDown, postMsgKeyPress] = useKeyHandler(
draft,
@@ -575,8 +579,11 @@ const AdvancedTextEditor = ({
const handleSubmitWithEvent = useCallback((e: React.FormEvent) => {
e.preventDefault();
if (readOnlyChannel) {
return;
}
handleSubmitWithErrorHandling();
}, [handleSubmitWithErrorHandling]);
}, [handleSubmitWithErrorHandling, readOnlyChannel]);
const handlePostError = useCallback((err: React.ReactNode) => {
setPostError(err);
@@ -1042,6 +1049,7 @@ const AdvancedTextEditor = ({
<EditPostFooter
onSave={handleSubmitWrapper}
onCancel={handleCancel}
disabled={readOnlyChannel}
/>
)}
<div
@@ -13,6 +13,7 @@ import {isSendOnCtrlEnter} from 'selectors/preferences';
type Props = {
onSave: () => void;
onCancel?: () => void;
disabled?: boolean;
};
export default function EditPostFooter(props: Props) {
@@ -31,6 +32,7 @@ export default function EditPostFooter(props: Props) {
<button
onClick={props.onSave}
className='save'
disabled={props.disabled}
>
<FormattedMessage
id='edit_post.action_buttons.save'