Skip to content

fix(api): enforce rate limits for demo app creation#1679

Merged
riderx merged 2 commits intomainfrom
riderx/limit-demo-app-abuse
Feb 25, 2026
Merged

fix(api): enforce rate limits for demo app creation#1679
riderx merged 2 commits intomainfrom
riderx/limit-demo-app-abuse

Conversation

@riderx
Copy link
Member

@riderx riderx commented Feb 24, 2026

Summary (AI generated)

  • Enforce rate-limiting on /app/demo to prevent abuse by authenticated low-privilege users.
  • Add plan-aware demo app quota handling by checking isPayingOrg(...) before creation.
  • Add hourly and daily sliding-window checks (user + org) with stricter defaults for free-tier orgs.
  • Keep response/error behavior unchanged except for new simpleRateLimit(...) rejections.
  • Run and pass backend linter after changes (bun lint:backend).

Motivation (AI generated)

/app/demo allows many database writes per call and previously lacked strict anti-abuse controls. A single authenticated user with write rights could repeatedly create demo apps and trigger large write amplification across many tables, impacting availability and costs. This PR adds protective limits before writes happen.

Business Impact (AI generated)

  • Reduces availability risk by preventing write storms from demo abuse.
  • Limits infrastructure/storage cost growth from low-cost automated/demo flooding.
  • Improves platform stability for paying and non-paying users by lowering contention and reducing noisy-neighbor load on shared DB resources.

Test Plan (AI generated)

  • Run bun lint:backend
  • Add/update backend endpoint tests for /app/demo per-org/per-user throttle behavior (paid + free paths)
  • Validate free-tier defaults via env overrides and paid path fallback behavior
  • Confirm isPayingOrg errors are handled as expected for edge conditions

Generated with AI

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 2026

Warning

Rate limit exceeded

@riderx has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5cb5da2 and 470b7ce.

📒 Files selected for processing (2)
  • supabase/functions/_backend/public/app/demo.ts
  • supabase/migrations/20260225000100_atomic_demo_app_creation.sql
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch riderx/limit-demo-app-abuse

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.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 01e19fe0d8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 350 to 354
const userDemoAppsCount1h = await countDemoApps(c, supabase, ownerOrg, {
since: hourlyWindowStart,
userId,
})
if (userDemoAppsCount1h >= limits.userPerHour) {

Choose a reason for hiding this comment

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

P1 Badge Make demo-app quota checks atomic

The new limits in assertDemoAppCreationLimits are enforced with separate COUNT queries before the insert, so concurrent POST /app/demo requests for the same org/user can all observe the same pre-insert count and pass, then each create a demo app and exceed the configured hourly/daily caps. This is a classic check-then-act race that undermines the abuse protection this change introduces; the quota decision needs to be enforced atomically with creation (for example via a single DB-side function/lock/transaction).

Useful? React with 👍 / 👎.

@riderx riderx force-pushed the riderx/limit-demo-app-abuse branch from 05207c1 to 470b7ce Compare February 25, 2026 05:51
@riderx riderx merged commit 98f2838 into main Feb 25, 2026
11 of 12 checks passed
@riderx riderx deleted the riderx/limit-demo-app-abuse branch February 25, 2026 05:54
@sonarqubecloud
Copy link

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.

1 participant