fix: remove account-enumeration oracle in match_users RPC (#1927) - #1933
fix: remove account-enumeration oracle in match_users RPC (#1927)#1933atul-upadhyay-7 wants to merge 1 commit into
Conversation
…5#1927) match_users was GRANTed to authenticated and derived the excluded user from a caller-supplied target_email, letting any logged-in user probe arbitrary emails and dump the user directory. Revoke the authenticated grant (only the service-role backend may call it), require a non-empty target_email, and make the function raise when an authenticated caller supplies an email other than their own.
|
@atul-upadhyay-7 is attempting to deploy a commit to the durdana3105's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
Next review available in: 55 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #1927
Problem
match_usersis a SECURITY DEFINER function GRANTed toauthenticated, and its only notion of "self" is a caller-suppliedtarget_emailargument (WHERE p.email != target_email). Any logged-in user could invoke it directly with an arbitrary email and use the returned profile set as an account-existence oracle, plus dump the user directory (names, skills, interests, teach/learn subjects) without using the app.Changes
New migration
20260805000004_secure_match_users_rpc.sql:REVOKE ALL ... FROM PUBLICand drop theauthenticatedgrant —match_usersis now callable only by the service role (the backend/api/match/recommendationsendpoint, which passes the caller's own email).service_roleneeds no explicit grant for SECURITY DEFINER functions.target_email(otherwise the query silently returns the whole directory),auth.uid()is present (i.e. an authenticated caller somehow reaches it), requiretarget_emailto equal the caller's own email fromauth.users, elseRAISE EXCEPTION,lower(p.email) <> lower(target_email)).Verification
backend/controllers/matchController.js) calls the RPC via the service-role client withreq.user.email;auth.uid()is NULL on that path, so the new guard does not affect it.match_usersdirectly (only the backend endpoint).admin_get_all_profilesremains properly gated — unchanged.