Skip to content

fix: enforce community ownership on earnings withdrawal#832

Merged
grunch merged 1 commit into
mainfrom
fix/withdraw-earnings-ownership
Jun 12, 2026
Merged

fix: enforce community ownership on earnings withdrawal#832
grunch merged 1 commit into
mainfrom
fix/withdraw-earnings-ownership

Conversation

@grunch

@grunch grunch commented Jun 12, 2026

Copy link
Copy Markdown
Member

What

The withdrawEarnings action looked up the target community using only the id taken from the inline-button callback data, without verifying that the caller owns that community. This change scopes the lookup by creator_id as well, so only the community creator can start a withdrawal of its earnings.

Why

Every other community-management handler (deleteCommunity, changeVisibility, updateCommunity) already filters by creator_id: ctx.user._id. The earnings-withdrawal path was the only one missing that ownership check, leaving it inconsistent with the rest of the module. Scoping the query keeps authorization consistent across all community operations.

Change

bot/modules/community/actions.ts — add creator_id: ctx.user._id to the Community.findOne lookup in withdrawEarnings.

Testing

  • npx tsc --noEmit passes.
  • npx eslint bot/modules/community/actions.ts passes.

Summary by CodeRabbit

  • Bug Fixes
    • Earnings withdrawal from communities is now restricted to community creators only, preventing unauthorized withdrawals.

The withdrawEarnings action looked up the community only by the id taken
from the callback data, without checking that the caller actually owns it.
Scope the lookup by creator_id as well, matching the other community
management handlers (deleteCommunity, changeVisibility, updateCommunity),
so only the community creator can start a withdrawal of its earnings.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 54c0b334-1765-4882-a88c-50035f9f3371

📥 Commits

Reviewing files that changed from the base of the PR and between 084c0da and bacfb33.

📒 Files selected for processing (1)
  • bot/modules/community/actions.ts

Walkthrough

The PR adds an authorization check to the withdrawEarnings function in the community actions module. The database lookup for Community now filters by both the community id from callback data and the current user's id as the creator, ensuring only the community creator can withdraw earnings. Inline comments clarify this behavior.

Changes

Community Creator Authorization

Layer / File(s) Summary
withdrawEarnings creator authorization check
bot/modules/community/actions.ts
The withdrawEarnings function now validates that the found community matches both the provided community id and requires creator_id: ctx.user._id, with added comments documenting the authorization rule and callback data source.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A bunny guards the earnings purse,
Only creators reap the rewards in this verse,
With filters tight and checks so true,
Communities safe from withdrawal by you! 🔐

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: enforce community ownership on earnings withdrawal' clearly and concisely summarizes the main change: adding ownership verification to the earnings withdrawal functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/withdraw-earnings-ownership

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed due to a network error.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@grunch grunch requested a review from Luquitasjeffrey June 12, 2026 13:07

@Luquitasjeffrey Luquitasjeffrey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

tACK

@grunch grunch merged commit 5d0cae2 into main Jun 12, 2026
7 checks passed
@grunch grunch deleted the fix/withdraw-earnings-ownership branch June 12, 2026 17:54
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