Skip to content

Commit 16bb9fd

Browse files
authored
fix(api): reject posts to archived channels (#326)
Reject new posts and replies to archived channels in both stores, preserve authorization checks and historical reads, and document restoring the existing channel ID. Add SQLite, PostgreSQL, and HTTP regression coverage. Use Go 1.27.4 and matching pinned build images to fix reachable GO-2026-6859 without raising the Go 1.26.6 module minimum. The full local gate, focused archive tests, vulnerability scan, and exact-head CI passed. The pre-fix HTTP regression returned 201 instead of 409. Fixes #325. Co-authored-by: tre1d / digitalnav <tre1d@proton.me>
1 parent 1f1b177 commit 16bb9fd

14 files changed

Lines changed: 137 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
- Build with Go 1.27.4 to fix the reachable HTTP/1 header race (GO-2026-6859), retaining the Go 1.26.6 module minimum.
6+
7+
- Reject new posts and thread replies to archived channels with a clear HTTP 409 error, and document restoring a channel without changing its ID. Thanks @tre1d.
8+
59
- List the commands in `clickclack help`, `-h`, and `--help` instead of only the client flags; `clickclack help` no longer fails with `unknown command "help"`. Thanks @KrasimirKralev.
610

711
## 0.9.4 - 2026-11-05

‎Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ COPY packages packages
1616
COPY scripts scripts
1717
RUN pnpm build
1818

19-
FROM golang:1.27.3-alpine@sha256:f2c872bcee949b7be9c490efd02b48a8a2fbf947cdf533f1c58525ec9d8170fd AS api
19+
FROM golang:1.27.4-alpine@sha256:0a5f7fe796599ff487605987432e7619ae45beeb2fba4c2ce0b907879932aebf AS api
2020
RUN apk add --no-cache --upgrade ca-certificates=20261020-r0 ca-certificates-bundle=20261020-r0
2121
WORKDIR /src
2222
COPY go.mod go.sum ./

‎Dockerfile.cloudflare‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ COPY packages packages
1616
COPY scripts scripts
1717
RUN pnpm build
1818

19-
FROM golang:1.27.3-alpine@sha256:f2c872bcee949b7be9c490efd02b48a8a2fbf947cdf533f1c58525ec9d8170fd AS api
19+
FROM golang:1.27.4-alpine@sha256:0a5f7fe796599ff487605987432e7619ae45beeb2fba4c2ce0b907879932aebf AS api
2020
RUN apk add --no-cache --upgrade ca-certificates=20261020-r0 ca-certificates-bundle=20261020-r0
2121
WORKDIR /src
2222
COPY go.mod go.sum ./

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ The complete documentation is at **[docs.clickclack.chat](https://docs.clickclac
6363

6464
## Development
6565

66-
Source builds use Go 1.27.3, Node.js 24 or newer, and pnpm 12.15.0. The module minimum remains Go 1.26.6 so managed CodeQL can build with its preinstalled compiler; the `toolchain` directive selects Go 1.27.3 for normal builds.
66+
Source builds use Go 1.27.4, Node.js 24 or newer, and pnpm 12.15.0. The module minimum remains Go 1.26.6 so managed CodeQL can build with its preinstalled compiler; the `toolchain` directive selects Go 1.27.4 for normal builds.
6767

6868
```sh
6969
pnpm install --frozen-lockfile

‎apps/api/internal/httpapi/message_routes_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"net/http/httptest"
88
"path/filepath"
9+
"strings"
910
"testing"
1011

1112
"github.com/openclaw/clickclack/apps/api/internal/realtime"
@@ -132,6 +133,7 @@ func TestEnsureMessageRouteEndpointIsLazyBoundedAndPermissionChecked(t *testing.
132133
patchJSON[struct {
133134
Channel store.Channel `json:"channel"`
134135
}](t, server.URL+"/api/channels/"+channel.ID, map[string]bool{"archived": true})
136+
expectStatusAsUser(t, member.ID, http.MethodPost, server.URL+"/api/channels/"+channel.ID+"/messages", strings.NewReader(`{"body":"archived"}`), http.StatusConflict)
135137
archived := postJSONAsUser[struct {
136138
Message store.Message `json:"message"`
137139
}](t, member.ID, server.URL+"/api/messages/"+archivedRoot.ID+"/route", struct{}{})

‎apps/api/internal/httpapi/responses.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ func writeStoreError(w http.ResponseWriter, err error) {
122122
writeError(w, http.StatusNotFound, err)
123123
case errors.Is(err, store.ErrModerationRestricted):
124124
writeError(w, http.StatusForbidden, err)
125+
case errors.Is(err, store.ErrChannelArchived):
126+
writeError(w, http.StatusConflict, err)
125127
case errors.Is(err, store.ErrNotWorkspaceManager):
126128
writeError(w, http.StatusForbidden, err)
127129
case errors.Is(err, store.ErrNotWorkspaceMember):

‎apps/api/internal/store/postgres/moderation.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ func requireCanPostTx(ctx context.Context, tx *sql.Tx, workspaceID, channelID, u
155155
if err := requireNoModerationBlockTx(ctx, tx, workspaceID, userID); err != nil {
156156
return err
157157
}
158+
channel, err := storedb.New(tx).GetChannel(ctx, channelID)
159+
if err != nil {
160+
return err
161+
}
162+
if channel.ArchivedAt.Valid {
163+
return store.ErrChannelArchived
164+
}
158165
if role != store.WorkspaceRoleGuest {
159166
return nil
160167
}

‎apps/api/internal/store/postgres/moderation_test.go‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,53 @@ func TestModerationHydrationFailureRollsBack(t *testing.T) {
155155
t.Fatalf("failed moderation committed an event: before=%s after=%s error=%v", before, after, err)
156156
}
157157
}
158+
159+
func TestCreateMessageRejectsArchivedChannel(t *testing.T) {
160+
ctx := t.Context()
161+
st := newIsolatedPostgresTestStore(t)
162+
if err := st.Migrate(ctx); err != nil {
163+
t.Fatal(err)
164+
}
165+
owner, err := st.EnsureBootstrap(ctx, "Owner", "archived-owner@example.com")
166+
if err != nil {
167+
t.Fatal(err)
168+
}
169+
workspaces, err := st.ListWorkspaces(ctx, owner.ID)
170+
if err != nil {
171+
t.Fatal(err)
172+
}
173+
if len(workspaces) == 0 {
174+
t.Fatal("expected a workspace")
175+
}
176+
workspace := workspaces[0]
177+
channels, err := st.ListChannels(ctx, workspace.ID, owner.ID)
178+
if err != nil {
179+
t.Fatal(err)
180+
}
181+
if len(channels) == 0 {
182+
t.Fatal("expected a channel")
183+
}
184+
channel := channels[0]
185+
root, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "before archive"})
186+
if err != nil {
187+
t.Fatal(err)
188+
}
189+
archived := true
190+
if _, _, err := st.UpdateChannel(ctx, store.UpdateChannelInput{ChannelID: channel.ID, UserID: owner.ID, Archived: &archived}); err != nil {
191+
t.Fatal(err)
192+
}
193+
if _, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "blocked"}); !errors.Is(err, store.ErrChannelArchived) {
194+
t.Fatalf("expected ErrChannelArchived, got %v", err)
195+
}
196+
if _, _, _, err := st.CreateThreadReply(ctx, store.CreateThreadReplyInput{RootMessageID: root.ID, AuthorID: owner.ID, Body: "blocked reply"}); !errors.Is(err, store.ErrChannelArchived) {
197+
t.Fatalf("expected archived reply rejection, got %v", err)
198+
}
199+
archived = false
200+
restored, _, err := st.UpdateChannel(ctx, store.UpdateChannelInput{ChannelID: channel.ID, UserID: owner.ID, Archived: &archived})
201+
if err != nil || restored.ID != channel.ID {
202+
t.Fatalf("restore must preserve channel ID: channel=%+v err=%v", restored, err)
203+
}
204+
if _, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "restored"}); err != nil {
205+
t.Fatalf("restored channel must accept messages: %v", err)
206+
}
207+
}

‎apps/api/internal/store/sqlite/moderation.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ func requireCanPostTx(ctx context.Context, tx *sql.Tx, workspaceID, channelID, u
155155
if err := requireNoModerationBlockTx(ctx, tx, workspaceID, userID); err != nil {
156156
return err
157157
}
158+
channel, err := storedb.New(tx).GetChannel(ctx, channelID)
159+
if err != nil {
160+
return err
161+
}
162+
if channel.ArchivedAt.Valid {
163+
return store.ErrChannelArchived
164+
}
158165
if role != store.WorkspaceRoleGuest {
159166
return nil
160167
}

‎apps/api/internal/store/sqlite/moderation_test.go‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,3 +666,53 @@ func TestModerationHydrationFailureRollsBack(t *testing.T) {
666666
t.Fatalf("failed moderation committed an event: before=%s after=%s error=%v", before, after, err)
667667
}
668668
}
669+
670+
func TestCreateMessageRejectsArchivedChannel(t *testing.T) {
671+
ctx := t.Context()
672+
st := newTestStore(t)
673+
if err := st.Migrate(ctx); err != nil {
674+
t.Fatal(err)
675+
}
676+
owner, err := st.EnsureBootstrap(ctx, "Owner", "archived-owner@example.com")
677+
if err != nil {
678+
t.Fatal(err)
679+
}
680+
workspaces, err := st.ListWorkspaces(ctx, owner.ID)
681+
if err != nil {
682+
t.Fatal(err)
683+
}
684+
if len(workspaces) == 0 {
685+
t.Fatal("expected a workspace")
686+
}
687+
workspace := workspaces[0]
688+
channels, err := st.ListChannels(ctx, workspace.ID, owner.ID)
689+
if err != nil {
690+
t.Fatal(err)
691+
}
692+
if len(channels) == 0 {
693+
t.Fatal("expected a channel")
694+
}
695+
channel := channels[0]
696+
root, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "before archive"})
697+
if err != nil {
698+
t.Fatal(err)
699+
}
700+
archived := true
701+
if _, _, err := st.UpdateChannel(ctx, store.UpdateChannelInput{ChannelID: channel.ID, UserID: owner.ID, Archived: &archived}); err != nil {
702+
t.Fatal(err)
703+
}
704+
if _, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "blocked"}); !errors.Is(err, store.ErrChannelArchived) {
705+
t.Fatalf("expected ErrChannelArchived, got %v", err)
706+
}
707+
if _, _, _, err := st.CreateThreadReply(ctx, store.CreateThreadReplyInput{RootMessageID: root.ID, AuthorID: owner.ID, Body: "blocked reply"}); !errors.Is(err, store.ErrChannelArchived) {
708+
t.Fatalf("expected archived reply rejection, got %v", err)
709+
}
710+
archived = false
711+
restored, _, err := st.UpdateChannel(ctx, store.UpdateChannelInput{ChannelID: channel.ID, UserID: owner.ID, Archived: &archived})
712+
if err != nil || restored.ID != channel.ID {
713+
t.Fatalf("restore must preserve channel ID: channel=%+v err=%v", restored, err)
714+
}
715+
if _, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "restored"}); err != nil {
716+
t.Fatalf("restored channel must accept messages: %v", err)
717+
}
718+
}

0 commit comments

Comments
 (0)