3. Findings
F-01 · Any signed-in user can read every booking
Critical
What we found
RLS is enabled on public.bookings, so the dashboard shows the table as protected. Its only SELECT policy is using (true), which lets every caller through.
Evidence
-- pg_policies
tablename | policyname | cmd | qual
bookings | Enable read access for all users | SELECT | true
# Signed in as Patient B (test account)
GET /rest/v1/bookings?select=id,patient_id,reason,starts_at
→ 200, 14 rows. 9 rows have patient_id = Patient A and Staff S test data.
Patient B owns 5.
Fix (pull request #1)
drop policy "Enable read access for all users" on public.bookings;
create policy "Patients read their own bookings"
on public.bookings for select to authenticated
using ((select auth.uid()) = patient_id);
create policy "Staff read bookings for their clinic"
on public.bookings for select to authenticated
using (clinic_id in (select clinic_id from private.staff
where user_id = (select auth.uid())));
Re-test
Fixed. The same request as Patient B returns 5 rows, all with Patient B's ID. With no sign-in it returns 0 rows. A database test for both cases was added to the repository (supabase/tests/bookings_rls.test.sql) and passes.
F-02 · Service-role key shipped in the browser bundle
Critical
What we found
The admin screen creates a second Supabase client with the service-role key, read from VITE_SUPABASE_SERVICE_KEY. Every VITE_ variable is compiled into the public JavaScript. The service-role key skips all RLS policies.
Evidence
assets/index-4f2a91.js contains a second token beginning eyJhbGciOi…
Decoded payload: { "role": "service_role", … }
# With that key, no sign-in
GET /rest/v1/patients?select=count
→ 200, full row count returned (test data only on staging)
We stopped at the row count. We did not download the table.
Fix (pull request #2, plus a key change done with the client on a call)
The two admin actions moved into an edge function that checks the caller is staff. The variable was removed from the front end and from the hosting settings. The client created new API keys in the Supabase dashboard and revoked the old ones while we watched; we did not keep either key.
Re-test
Fixed. The new bundle contains only the publishable key. The old service-role key now returns 401. The git history still contains the old key, which no longer matters because it is revoked.
F-03 · Users can make themselves admin
Critical
What we found
The policy on public.profiles correctly limits updates to a user's own row. It does not limit which columns, and the row includes role. The front end hides the admin menu for patients, but the database accepts the change. Automated scanners pass this table because the policy has an owner check.
Evidence
# Signed in as Patient B
PATCH /rest/v1/profiles?id=eq.<Patient B id>
{ "role": "admin" }
→ 204
# Reload the app as Patient B: the admin menu appears and
# /admin/patients lists all test patients.
Fix (pull request #3)
-- Users may update only these columns of their own row
revoke update on public.profiles from authenticated;
grant update (full_name, phone, avatar_url) on public.profiles to authenticated;
-- Roles move out of the editable table
create table private.staff (
user_id uuid primary key references auth.users on delete cascade,
clinic_id uuid not null,
role text not null check (role in ('staff', 'admin'))
);
Re-test
Fixed. The same request now returns 403 (permission denied for column role). Patient B's role was reset. Changing full_name still works.
F-04 · Edge function sends anyone's invoice without sign-in
High
What we found
The send-invoice function is deployed with verify_jwt = false and does not check the caller in its code. It takes a booking_id and an email, and emails that booking's invoice to that address.
Evidence
# No Authorization header
POST /functions/v1/send-invoice
{ "booking_id": "<Patient A booking>", "email": "<our test inbox>" }
→ 200. Patient A's invoice PDF arrived in our test inbox.
Fix (pull request #4)
verify_jwt set back to true. The function now builds a Supabase client from the caller's token, loads the booking through RLS, and sends only to the email address on the caller's own account. The email field was removed from the request.
Re-test
Fixed. No token: 401. Patient B's token with Patient A's booking: 404. Patient A's token with Patient A's booking: invoice sent to Patient A's address.
F-05 · Patient documents in a public storage bucket
High
What we found
The documents bucket is public and files are named after the booking ID. Anyone who knows or sees a booking ID can open the file without signing in. Booking IDs appear in page addresses and in emails.
Evidence
select id, public from storage.buckets;
documents | true
# No sign-in, in a private browser window
GET /storage/v1/object/public/documents/<Patient A booking id>.pdf
→ 200, the test referral letter
Fix (pull request #5)
Bucket set to private. Files moved to <patient id>/<random name>.pdf. Storage policies allow a patient to read only their own folder and staff only their clinic's patients. The app now shows files through signed links that expire after 10 minutes.
Re-test
Fixed. The old public address returns 400. Patient B asking for a signed link to Patient A's file is refused.
F-06 · No limit or CAPTCHA on sign-in codes
Medium
What we found
The sign-in form requests an SMS code with no CAPTCHA. The project's rate limits were raised during development and never lowered.
Evidence
From one address, 30 code requests for our own test phone number in 5 minutes were all accepted and delivered. We stopped there.
Fix
CAPTCHA protection enabled in the Supabase dashboard and wired into the sign-in and sign-up forms (pull request #6). We recommended lowering the SMS limit and allowing only the country the clinic serves.
Re-test
Partly fixed. Requests without a CAPTCHA token are refused. The SMS limit is unchanged because the client is waiting for their SMS provider to confirm expected volume. This is the client's decision and is recorded here as open.
F-07 · Source maps published on the live site
Low
What we found
build.sourcemap is true in vite.config.ts, so the original source with comments is downloadable. It made F-02 and F-04 quicker to find.
Evidence
GET /assets/index-4f2a91.js.map → 200.
Fix (pull request #7)
build: { sourcemap: false }.
Re-test
Fixed. The .map address returns 404 after the next deploy.