Harden billing and generation workflow#33
Conversation
✅ Deploy Preview for launchpix ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e25e595e20
ℹ️ 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".
| ) | ||
| returns boolean | ||
| language plpgsql | ||
| security definer |
There was a problem hiding this comment.
Restrict execution of grant_credit_pack_atomic
This function is declared security definer and takes caller-controlled p_user_id/p_credits, but the migration does not enforce any caller check or lock down EXECUTE privileges. In a Supabase setup where public RPCs are reachable, an authenticated user can call this function directly (with fresh p_provider_reference values) to grant arbitrary credits without a real payment event, bypassing the webhook path entirely.
Useful? React with 👍 / 👎.
| last_payment_at: new Date().toISOString() | ||
| }) | ||
| .eq("id", current.id); | ||
| .update({ credits_remaining: current.credits_remaining + 1 }) |
There was a problem hiding this comment.
Make refund credit update atomic
The refund path writes credits_remaining from a stale in-memory value (current.credits_remaining + 1) instead of incrementing in-database. If another balance mutation happens between the read and this update (for example, a concurrent refund or a webhook credit grant), this update can overwrite the newer total and lose purchased/refunded credits. The refund should use an atomic increment strategy rather than read-modify-write from application code.
Useful? React with 👍 / 👎.
Summary
Verification