Skip to content

Harden upsert_version_meta RPC against abuse#1760

Open
riderx wants to merge 4 commits intomainfrom
riderx/fix-version-meta-rpc
Open

Harden upsert_version_meta RPC against abuse#1760
riderx wants to merge 4 commits intomainfrom
riderx/fix-version-meta-rpc

Conversation

@riderx
Copy link
Member

@riderx riderx commented Mar 8, 2026

Summary (AI generated)

  • Restrict public.upsert_version_meta RPC execution to service_role only.
  • Replaced the function body to verify app ownership and version ownership before insert.
  • Added caller authorization for non-service callers via get_identity_org_appid and check_min_rights, while preserving existing dedupe behavior.

Test plan (AI generated)

  • Run bun lint:backend.
  • Manually exercise unauthenticated requests to POST /rest/v1/rpc/upsert_version_meta to confirm inserts are rejected.
  • Verify allowed internal service-role writes continue to record valid metadata.

Screenshots (AI generated)

  • Not applicable (backend-only migration change).

Checklist (AI generated)

  • My code follows the code style of this project and passes bun run lint:backend && bun run lint.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • My change has adequate E2E test coverage.
  • I have tested my code manually, and I have provided steps how to reproduce my tests

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 8, 2026

Warning

Rate limit exceeded

@riderx has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 33 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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 860c2c29-487f-4210-90d7-c67c76c371d3

📥 Commits

Reviewing files that changed from the base of the PR and between 2af3a08 and 2c5ac75.

📒 Files selected for processing (2)
  • supabase/migrations/20260308203341_harden_upsert_version_meta_authz.sql
  • tests/upsert-version-meta-rpc.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch riderx/fix-version-meta-rpc

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: 740755153b

ℹ️ 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".

FROM public.app_versions
WHERE public.app_versions.app_id = p_app_id
AND public.app_versions.id = p_version_id
AND public.app_versions.deleted = false

Choose a reason for hiding this comment

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

P1 Badge Allow metadata upserts for soft-deleted versions

The new public.app_versions.deleted = false predicate prevents the delete path from recording compensating negative metadata entries: deleteIt in supabase/functions/_backend/triggers/on_version_update.ts calls createStatsMeta(..., -data.size) after a soft delete, when the target row is already marked deleted. With this filter, upsert_version_meta returns false and skips the insert, so version_meta no longer captures bundle removals and storage/billing aggregates that depend on it remain overstated.

Useful? React with 👍 / 👎.

@riderx riderx force-pushed the riderx/fix-version-meta-rpc branch from 9398519 to e9bf46a Compare March 8, 2026 23:52
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 9, 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.

1 participant