fix: prevent direct client updates to sensitive profile fields (#397)#410
Merged
Merged
Conversation
Contributor
|
@diksha78dev is attempting to deploy a commit to the codersogs-3057's projects Team on Vercel. A member of the Team first needs to authorize it. |
Ayush-Patel-56
approved these changes
Jun 24, 2026
Ayush-Patel-56
left a comment
Collaborator
There was a problem hiding this comment.
renamed the migration to 0024 since 0023 got taken by another PR that merged today, otherwise this is good, the trigger correctly only blocks anon/authenticated writes so service-role jobs still work fine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR prevents authenticated web clients from maliciously modifying sensitive profile stats (
xp,level,role, andaudit_completed) by adding a row-level trigger that intercepts the updates and restores the original values.Type of Change
Related Issue
Closes #397
What was changed?
supabase/migrations/0023_protect_profile_fields.sqlprotect_profile_sensitive_fields()PL/pgSQL function.BEFORE UPDATEtrigger on theprofilestable that checks if the request comes from anauthenticatedoranonrole (web clients).NEW.xp,NEW.level,NEW.role, andNEW.audit_completedto match theOLDvalues, silently ignoring any malicious payload while allowing other harmless fields likebioto be updated.service_role(used by the backend) bypasses this check and can update stats normally.Screenshots
N/A
Checklist
npm run dev)