Skip to content

fix(db): restrict anon/authenticated read on counterfeit_reports to non-PII columns - #4209

Merged
dipexplorer merged 1 commit into
RatLoopz:mainfrom
Kirtan-pc:fix/4200-restrict-reports-pp-read
Aug 8, 2026
Merged

fix(db): restrict anon/authenticated read on counterfeit_reports to non-PII columns#4209
dipexplorer merged 1 commit into
RatLoopz:mainfrom
Kirtan-pc:fix/4200-restrict-reports-pp-read

Conversation

@Kirtan-pc

Copy link
Copy Markdown
Contributor

🛑 STOP: Assignment & File Scope Check

  • I am assigned to this issue.
  • I verified that this PR ONLY touches the required files.

Warning

PRs with unrelated files will not be reviewed and may be closed.

📋 PR Summary & Link

  • Closes [BUG] RLS policy leaks reporter PII (phone, address, GPS) to anonymous users #4200
  • Summary:
    The reports_public_read policy granted anon/authenticated SELECT ... USING (true) across every column of counterfeit_reports. Because the anon key is embedded in the web client (apps/web/lib/supabase.ts), anyone could hit the PostgREST REST API and exfiltrate reporters' phone numbers, full street addresses, pincodes, and exact GPS coordinates—including pending/unverified reports.
    Changes:
    supabase/migrations/20260807000000_restrict_reports_public_read.sql
    Drops reports_public_read.
    Revokes table-level SELECT for anon/authenticated (so column grants take effect).
    Re-adds a row policy and grants SELECT only on non-PII display columns (id, reported_brand_name, manufacturer, description, pharmacy_name, city, state, photo_url, photo_urls, district, status, created_at).
    Blocks reporter_id, reporter_phone, address, pincode, report_location, and internal safety fields.
    supabase/tests/rls/counterfeit_reports_public_read.test.sql — pgtap test asserting anon can read non-PII columns but is denied (42501) reporter_phone, address, pincode, report_location.
    Safety: service_role (API server) bypasses RLS and column grants, so submit, /mine, and admin list flows are unaffected.

🏷️ PR Type

  • 🐛 type: bug
  • type: feature
  • 📖 type: docs
  • 🧪 type: testing
  • 🔒 type: security
  • type: performance
  • 🎨 type: design
  • ♻️ type: refactor
  • 🛠️ type: devops
  • type: accessibility

✅ Checklist

  • My PR has a linked issue (Closes #4200)
  • I have pulled the latest main and resolved any conflicts

…on-PII columns

The reports_public_read policy granted anon/authenticated SELECT USING(true)
over all columns of counterfeit_reports. Since the anon key is embedded in
client-side code, anyone could query PostgREST and exfiltrate reporters'
phone numbers, street addresses, pincodes, and exact GPS coordinates,
including pending/unverified reports (PII breach RatLoopz#4200).

Drop the permissive policy, revoke table-level SELECT for client roles, and
re-grant only the non-PII display columns (brand, manufacturer, district,
status, timestamps, photos, etc.). service_role API flows are unaffected.

Add pgtap RLS test asserting anon can read only non-PII columns and is denied
reporter_phone/address/pincode/report_location.
@github-project-automation github-project-automation Bot moved this to 📥 Backlog in SahiDawa Workflow Aug 7, 2026
@github-actions github-actions Bot added gssoc:approved Approved for gssoc type:bug Something isn't working labels Aug 7, 2026
@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

@dipexplorer dipexplorer added level:critical 80 pts quality:exceptional multiplier x1.5 type:security Auth, rate limiting, security type:testing Unit tests, integration tests labels Aug 8, 2026
@dipexplorer
dipexplorer merged commit 7d0ef9e into RatLoopz:main Aug 8, 2026
25 of 30 checks passed
@github-project-automation github-project-automation Bot moved this from 📥 Backlog to 🎉 Merged in SahiDawa Workflow Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for gssoc level:critical 80 pts quality:exceptional multiplier x1.5 type:bug Something isn't working type:security Auth, rate limiting, security type:testing Unit tests, integration tests

Projects

Status: 🎉 Merged

Development

Successfully merging this pull request may close these issues.

[BUG] RLS policy leaks reporter PII (phone, address, GPS) to anonymous users

2 participants