Skip to content

fix(security): gate /channels/discover behind AdminAuth (#250) - #252

Merged
HongmingWang-Rabbit merged 1 commit into
mainfrom
fix/channels-discover-adminauth
Apr 15, 2026
Merged

fix(security): gate /channels/discover behind AdminAuth (#250)#252
HongmingWang-Rabbit merged 1 commit into
mainfrom
fix/channels-discover-adminauth

Conversation

@HongmingWang-Rabbit

Copy link
Copy Markdown
Contributor

Closes #250 (MEDIUM).

Summary

`POST /channels/discover` was on the open router. Any unauthenticated caller could:

  1. Submit an arbitrary Telegram bot token and use a 200/400 response as a token validity oracle
  2. Trigger `tgbotapi.DeleteWebhookConfig` as a side effect — calling this in a loop disables any valid target bot's webhook delivery
  3. Amplify rate-limit cost against the target token (getMe + deleteWebhook + getUpdates per call)

Fix

One-line: wrap the route with `middleware.AdminAuth(db.DB)`. Matches the pattern used on `/admin/liveness`, `/events`, `/bundles/export`, `/templates/import`, etc. from PRs #167/#190/#200.

Why no new test

`AdminAuth` behavior is covered in `platform/internal/middleware/wsauth_middleware_test.go`; this PR only adds an additional route to that already-tested middleware. A full router integration test would require mocking every dependency of `router.Setup` — excessive for a one-line wire-up.

A load-bearing code comment cites #250 so a future reviewer can't revert without an issue citation.

Test plan

🤖 Generated with Claude Code

Closes #250 (MEDIUM). POST /channels/discover was on the open router
and accepted an arbitrary Telegram bot token, turning it into:
 1. A free bot-token validity oracle — attackers can enumerate/probe
    tokens at zero cost
 2. A drive-by deleteWebhook side effect — every call invokes
    tgbotapi.DeleteWebhookConfig against the target bot, breaking
    legitimate webhook delivery
 3. A rate-limit amplifier — getMe + deleteWebhook + getUpdates per call

Fix: one-line addition of middleware.AdminAuth(db.DB) to the route,
matching its actual intent (platform-operator admin helper, not a
per-workspace route). Pattern mirrors /admin/liveness, /events, and
/bundles/export from PR #167.

No new test: AdminAuth behavior is covered by
wsauth_middleware_test.go; this PR only wires it onto an additional
route. The load-bearing code comment references #250 so future
reviewers can't revert without an issue citation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@HongmingWang-Rabbit
HongmingWang-Rabbit merged commit 3f79827 into main Apr 15, 2026
5 of 6 checks passed
@HongmingWang-Rabbit
HongmingWang-Rabbit deleted the fix/channels-discover-adminauth branch April 15, 2026 20:49

@HongmingWang-Rabbit HongmingWang-Rabbit left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post-merge code review — Dev Lead

Fix is correct and minimal. Moving /channels/discover inside middleware.AdminAuth(db.DB) is the exact right approach — consistent with all other channel CRUD routes (wsAuth group at line ~381). The comment explaining why AdminAuth is appropriate (platform-operator helper, not per-workspace route) is a useful addition for future readers.

No concerns. Closes #250 cleanly. ✅

molecule-ai Bot pushed a commit that referenced this pull request Apr 21, 2026
fix(security): gate /channels/discover behind AdminAuth (#250)
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.

security(channels): POST /channels/discover is unauthenticated — bot-token oracle + deleteWebhook side-effect

1 participant