[Follow-up #159] Fix migration idempotency and step-up security regressions#193
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
Warning Review limit reached
Your plan currently allows 1 review/hour. Refill in 9 minutes and 46 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, a review can be triggered using the 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 trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR hardens Supabase database migrations to be safe to replay across environments (idempotent DDL/policy creation and removal of unsafe hardcoded credentials), and updates step-up auth RPCs to better enforce challenge integrity.
Changes:
- Replaced a hardcoded test-user password reset migration with a no-op placeholder.
- Made several new security-related tables/policies idempotent (
IF NOT EXISTS+ guardedCREATE POLICY). - Updated step-up RPCs to always populate
otp_hashand to validate password attempts before marking a challenge as password-verified; removed a hardcoded organization UUID from orphan backfill.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| supabase/migrations/20260518122107_reset_comercial01_password_test.sql | Removes unsafe hardcoded password reset and replaces with a no-op placeholder. |
| supabase/migrations/20260522113233_lote_a_02_user_known_devices.sql | Makes user_known_devices table/index/policy creation idempotent. |
| supabase/migrations/20260522113250_lote_a_03_password_reset_requests.sql | Makes password_reset_requests table/index/policy creation idempotent. |
| supabase/migrations/20260522113351_lote_a_06_funcoes_step_up.sql | Adjusts step-up RPCs to generate/store otp_hash and validate password attempts. |
| supabase/migrations/20260518121325_backfill_user_organizations_orphans.sql | Removes hardcoded org UUID; selects an existing organization dynamically. |
| supabase/migrations/20260522113832_lote_b_01_edge_rate_limits.sql | Makes edge_rate_limits table/index/policy creation idempotent. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| SELECT * | ||
| INTO v_user | ||
| FROM auth.users | ||
| WHERE id = auth.uid(); | ||
|
|
||
| IF NOT FOUND OR crypt(_password_attempt, v_user.encrypted_password) <> v_user.encrypted_password THEN | ||
| RETURN false; | ||
| END IF; |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Motivation
Description
supabase/migrations/20260518122107_reset_comercial01_password_test.sqlwith a no-op placeholder and explanatory comment to avoid overwriting real accounts.supabase/migrations/20260522113233_lote_a_02_user_known_devices.sqlidempotent by switching toCREATE TABLE IF NOT EXISTS,CREATE INDEX IF NOT EXISTS, and guarding policy creation withpg_policieschecks.supabase/migrations/20260522113250_lote_a_03_password_reset_requests.sqlidempotent by usingCREATE TABLE IF NOT EXISTS,CREATE INDEX IF NOT EXISTS, and wrapping policy creation inDO $$ ... END $$checks againstpg_policies.supabase/migrations/20260522113832_lote_b_01_edge_rate_limits.sqlidempotent by usingCREATE TABLE IF NOT EXISTS,CREATE INDEX IF NOT EXISTS, and guarded policy creation.supabase/migrations/20260518121325_backfill_user_organizations_orphans.sqland changed it to select an existing organization dynamically to avoid FK failures in other environments.supabase/migrations/20260522113351_lote_a_06_funcoes_step_up.sqlsostart_step_up_challengeinserts a generatedotp_hashandverify_step_up_passwordvalidates_password_attemptagainstauth.users.encrypted_password, rejects empty attempts and unauthenticated calls before settingpassword_verified=true.Testing
git diffand confirmed changes were staged and committed successfully with the messagefix: harden migrations and step-up rpcs from review findings.rgto verify the hardcoded password literal was removed and thatCREATE TABLE/CREATE INDEXusages were changed toIF NOT EXISTSand policy creation was guarded, and the queries returned the expected updated lines.nland visually inspected the modified functions and migration statements to ensureotp_hashis written and password checks were added.Codex Task
Summary by cubic
Makes migrations idempotent and removes unsafe hardcoded credentials. Repairs step-up RPCs to store an
otp_hashand verify passwords securely before marking challenges verified. Follow-up to #159.Bug Fixes
pg_policiesand usedIF NOT EXISTSfor tables/indexes inuser_known_devices,password_reset_requests, andedge_rate_limits.NOT EXISTS.otp_hash, require auth, reject empty attempts, fetch user, validate againstauth.users.encrypted_password, and setpassword_verified=trueonly for active (unconsumed, unexpired) challenges.Migration
Written for commit c4ea35d. Summary will update on new commits. Review in cubic