Skip to content

fix: remove account-enumeration oracle in match_users RPC (#1927) - #1933

Open
atul-upadhyay-7 wants to merge 1 commit into
durdana3105:mainfrom
atul-upadhyay-7:fix/match-users-enumeration-1927
Open

fix: remove account-enumeration oracle in match_users RPC (#1927)#1933
atul-upadhyay-7 wants to merge 1 commit into
durdana3105:mainfrom
atul-upadhyay-7:fix/match-users-enumeration-1927

Conversation

@atul-upadhyay-7

Copy link
Copy Markdown
Contributor

Fixes #1927

Problem

match_users is a SECURITY DEFINER function GRANTed to authenticated, and its only notion of "self" is a caller-supplied target_email argument (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 PUBLIC and drop the authenticated grantmatch_users is now callable only by the service role (the backend /api/match/recommendations endpoint, which passes the caller's own email). service_role needs no explicit grant for SECURITY DEFINER functions.
  • Defense in depth inside the function:
    • require a non-empty target_email (otherwise the query silently returns the whole directory),
    • when auth.uid() is present (i.e. an authenticated caller somehow reaches it), require target_email to equal the caller's own email from auth.users, else RAISE EXCEPTION,
    • exclude the caller's own profile case-insensitively (lower(p.email) <> lower(target_email)).

Verification

  • The backend (backend/controllers/matchController.js) calls the RPC via the service-role client with req.user.email; auth.uid() is NULL on that path, so the new guard does not affect it.
  • The frontend never calls match_users directly (only the backend endpoint).
  • Non-admin admin_get_all_profiles remains properly gated — unchanged.

…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.
@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown

@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.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@atul-upadhyay-7, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 59d2bf26-6fad-45d6-bdd3-659b7278eec4

📥 Commits

Reviewing files that changed from the base of the PR and between 880eed9 and ac3369e.

📒 Files selected for processing (1)
  • supabase/migrations/20260805000004_secure_match_users_rpc.sql

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] match_users RPC lets authenticated users probe arbitrary email addresses (account enumeration)

1 participant