Skip to content

fix: refuse new comments on the server when comments are turned off - #588

Merged
OXeu merged 1 commit into
openRin:mainfrom
zuhairkhalid229:fix/585-refuse-comments-when-disabled
Nov 15, 2026
Merged

OXeu merged 1 commit into
openRin:mainfrom
zuhairkhalid229:fix/585-refuse-comments-when-disabled

Conversation

@zuhairkhalid229

Copy link
Copy Markdown
Contributor

Part of #585 (the part about turning comments off; the other requests in the issue stay open)

Problem

Turning comments off (comment.enabled in the settings page) only hides the comment form in the client (client/src/page/feed.tsx). POST /comment/:feed never reads the setting, so anything that calls the API directly, such as a spam bot, can still post. Each post is stored and still triggers the comment webhook, which is why the reporter kept getting notification emails after turning comments off.

Fix

server/src/services/comments.ts: the POST handler reads comment.enabled from clientConfig (default true) and answers 403 Comment Disabled when it is off, unless the caller is an admin. The check runs before the body is parsed, the feed lookup, the insert and the webhook, so a refused request changes nothing. It follows the existing friend_apply_enable gate in server/src/services/friends.ts, including the admin exemption.

Tests

New POST /:feed - Comments turned off block in server/src/services/__tests__/comments.test.ts:

  • a guest comment gets 403, no row is stored, and the webhook is not called
  • a signed-in user's comment gets 403 and no row is stored
  • an admin can still comment
  • comments are accepted again once the setting is back on

The two refusal tests fail without the change and pass with it. bun run check in server/ passes. In bun run test:server all comment tests pass. The only failures on my machine are RSS feed tests that hit bun's 5 s timeout on a slow disk; they fail the same way on main, and they all pass with --timeout 30000.

Not in this PR

The issue also asks for a moderation queue, custom spam filters, threaded replies and reply emails to guests. Those are features, so I kept this PR to closing the API when comments are off and did not close the issue. Happy to drop the admin exemption if you'd rather block everyone.

Turning comments off only hid the form in the client. POST /comment/:feed
never read comment.enabled, so bots kept posting through the API and every
post still sent the comment webhook (openRin#585).

The handler now answers 403 when comment.enabled is false, before it reads
the body or touches the database, unless the caller is an admin. This is the
same rule friend applications use (friend_apply_enable).
@OXeu
OXeu merged commit 6a7ce76 into openRin:main Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants