Skip to content

fix: prevent direct client updates to sensitive profile fields (#397)#410

Merged
Ayush-Patel-56 merged 3 commits into
Coder-s-OG-s:mainfrom
diksha78dev:fix/issue-397
Jun 24, 2026
Merged

fix: prevent direct client updates to sensitive profile fields (#397)#410
Ayush-Patel-56 merged 3 commits into
Coder-s-OG-s:mainfrom
diksha78dev:fix/issue-397

Conversation

@diksha78dev

Copy link
Copy Markdown
Contributor

Summary

This PR prevents authenticated web clients from maliciously modifying sensitive profile stats (xp, level, role, and audit_completed) by adding a row-level trigger that intercepts the updates and restores the original values.

Type of Change

  • Bug fix
  • New feature
  • UI / UX improvement
  • Refactor
  • Documentation
  • Other

Related Issue

Closes #397

What was changed?

  • Added supabase/migrations/0023_protect_profile_fields.sql
  • Created protect_profile_sensitive_fields() PL/pgSQL function.
  • Added a BEFORE UPDATE trigger on the profiles table that checks if the request comes from an authenticated or anon role (web clients).
  • If it is a web client, the trigger forces NEW.xp, NEW.level, NEW.role, and NEW.audit_completed to match the OLD values, silently ignoring any malicious payload while allowing other harmless fields like bio to be updated.
  • The service_role (used by the backend) bypasses this check and can update stats normally.
  • Note on testing: Since the current test suite mocks the Supabase client and does not run against a live database, an automated database integration test harness for this specific trigger was considered out of scope.

Screenshots

N/A

Checklist

  • My code follows the project structure and conventions
  • I tested this locally (npm run dev)
  • No hardcoded secrets or credentials
  • I have updated documentation if needed

@vercel

vercel Bot commented Jun 24, 2026

Copy link
Copy Markdown
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 Ayush-Patel-56 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

@Ayush-Patel-56 Ayush-Patel-56 added level:intermediate Intermediate level difficulty quality:clean Clean, well-structured contribution type:bug Bug fix gssoc:approved Approved by GSSOC admin mentor:Ayush-Patel-56 Replace Ayush-Patel-56 with mentor's GitHub handle to credit them nsoc26 level2 SSoC26 Medium labels Jun 24, 2026
@Ayush-Patel-56 Ayush-Patel-56 merged commit 4217015 into Coder-s-OG-s:main Jun 24, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved by GSSOC admin level:intermediate Intermediate level difficulty level2 Medium mentor:Ayush-Patel-56 Replace Ayush-Patel-56 with mentor's GitHub handle to credit them nsoc26 quality:clean Clean, well-structured contribution SSoC26 type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

profiles RLS lets a signed in user overwrite their own xp, level, and role directly

2 participants