"Sign in with Google" lets anyone in: restrict who can use your app (allowlist, domain check, RLS)
Updated · Applies to: Supabase, Firebase, Clerk, Google, Lovable, Bolt, Replit, Cursor, v0
TL;DR fix: A Google login is authentication (who you are), not authorization (whether you may use this app). Out of the box, Supabase and Firebase create an account for any Google user who signs in, and policies like to authenticated using (true), auth.role() = 'authenticated', auth.uid() is not null or Firestore request.auth != null then show them everything. Fix it in two layers: stop strangers getting an account (Supabase: turn off Allow new users to sign up or add a deny-by-default before-user-created hook; Firebase: a beforeUserCreated blocking function; Clerk: Invite-only or Allowlist), and check membership on every read and write (RLS that looks up a members table, or Firestore rules that check a members document or custom claim). Google's hd request parameter only changes the account picker; it is not a gate.
Steps
- Sign in as a stranger. Open the app in a private window and sign in with a personal Gmail account that was never invited. If you get past the login and see real data, any Google user can.
- List who already has an account. Run the users-by-provider-and-domain query below in the Supabase SQL Editor (or open Authentication > Users in Firebase). Accounts from domains you don't recognise mean strangers already signed up.
- Find policies that only check 'signed in'. Run the policy check query. Any policy whose whole condition is true, auth.role() = 'authenticated' or auth.uid() is not null lets every signed-in user through, including strangers and Supabase anonymous users.
- Stop strangers getting an account. Supabase: turn off 'Allow new users to sign up' (only existing users can sign in) or add a deny-by-default before-user-created hook that allows your domain and invited emails. Firebase: deploy a beforeUserCreated blocking function. Clerk: switch Access mode to Invite-only or enable the Allowlist.
- Check membership on every read and write. Create a members table that only admins or server code can write, and replace 'signed in' policies with policies that require a row in it (or, in Firestore, a members document or custom claim). This is what actually protects the data.
- Remove strangers who already got in. Hooks and blocking functions only stop new accounts. Delete or ban existing accounts that shouldn't be there, and rotate anything they could have read, such as API keys stored in tables.
- Retest as the stranger and as a real member. Repeat the private-window test: the stranger should be refused at sign-up or see nothing, and a real member should still see their data.
The bug: the login works, and that’s the problem
You asked your AI builder for an internal tool, a client portal or a team dashboard “with Google login”. It added a Sign in with Google button, a redirect to /login for logged-out visitors, and Supabase or Firebase policies that say “signed-in users can read”. You signed in, saw your data, and shipped.
Now try it with a Gmail account you’ve never invited. In most of these apps it gets straight in, because nothing ever asks is this person one of us?
- Google proves identity, not permission. A successful Google sign-in means “this person controls this Google account”. Supabase’s social login docs describe OAuth as letting users register and sign in with existing accounts: a new Google user gets a new account unless you turn signups off or reject them.
- “Signed in” policies let every account through.
to authenticated using (true),using (auth.role() = 'authenticated')andusing (auth.uid() is not null)are true for every signed-in user. Supabase’s RLS docs also note that anonymous users (if you enabled anonymous sign-ins) use the sameauthenticatedrole. - The UI check doesn’t count. A redirect or an
if (user.email.endsWith(...))in React only hides screens. The Supabase or Firebase API answers anyone holding a valid session and the public key. See rules that only live in the frontend.
In November 2026, security firm Claroc reported this exact pattern in a team app an AI builder generated for it: “Continue with Google” let any Google account in, because the code added whoever signed in to the team before checking membership (details on our share-link page).
Step 1: the 2-minute check
1. Sign in as a stranger. Private window, a personal Gmail account that was never invited. Real data on screen = the bug.
2. See who already has an account (Supabase SQL Editor):
-- Who has signed up, by sign-in provider and email domain
select coalesce(i.provider, u.raw_app_meta_data->>'provider', 'none') as provider,
lower(split_part(u.email, '@', 2)) as email_domain,
count(*) as users, max(u.created_at)::date as newest
from auth.users u
left join auth.identities i on i.user_id = u.id
group by 1, 2
order by users desc;
gmail.com or other domains you don’t recognise next to google means strangers already got accounts. A row with provider none and no domain is usually an anonymous user.
3. Find policies that only check “is signed in”:
-- Policies whose entire condition is "any signed-in user"
select schemaname, tablename, policyname, cmd, roles,
coalesce(qual, with_check) as condition
from pg_policies
where schemaname = 'public'
and roles && array['authenticated', 'public']::name[]
and regexp_replace(
regexp_replace(lower(coalesce(qual, with_check, '')), '[\s()]', '', 'g'),
'select|asuid|asrole', '', 'g')
in ('true', 'auth.role=''authenticated''::text',
'auth.uidisnotnull', 'auth.jwtisnotnull')
order by 1, 2, 3;
Every row is a table any signed-in account can use. (It deliberately skips compound conditions like auth.uid() is not null and user_id = auth.uid(), which are scoped.) Policies open to anon with using (true) are a bigger problem; see USING (true) policies.
4. Check the signup setting. In the Supabase Dashboard, Authentication settings: is Allow new users to sign up on? (In config.toml it’s auth.enable_signup, default true.)
| What you see | Cause | Fix |
|---|---|---|
| A fresh Gmail account signs in and sees data | Open signups + “signed in” policies | Step 2 and Step 3 |
| A stranger signs in but sees an empty app | Policies are scoped, but anyone can still get an account | Step 2 (and check they can’t call your APIs) |
| Login page appears, but the API returns rows to a stranger’s token | The gate is only in the frontend | Step 3 |
auth.users has gmail.com accounts you never invited | Signups were open; hooks don’t remove existing users | Step 4 |
| Strangers blocked at sign-up, but some old accounts still see data | Cleanup not done, or a leftover permissive policy | Step 4, rerun the policy check |
You passed hd=yourcompany.com and outsiders still get in | hd only changes Google’s account picker | Check the hd claim server-side, or use an allowlist |
Admin pages hidden in React, but /rest/v1/... still works for normal users | Role check is client-side only | Frontend rules, plan / is_admin columns |
Step 2: stop strangers getting an account (Supabase)
Pick one. Both are docs-based for the Supabase side; we did not run them on a live project.
Option A: turn signups off. Supabase’s general configuration docs: with Allow new users to sign up disabled, “only existing users can sign in”. Add the people you want yourself, for example with auth.admin.inviteUserByEmail from server code (never with the secret key in the browser). Test with a fresh Gmail account afterwards.
Option B: a deny-by-default before-user-created hook. Supabase’s Before User Created hook runs before a new user is created; returning an error object denies the signup and the user is not created. Per Supabase’s Auth Hooks page it’s available on Free and Pro and is enabled under Authentication > Hooks (the general configuration page lists Auth Hooks as beta). Supabase’s own domain example allows emails that match no rule; for a private app, deny by default:
create table public.signup_allowed_domains (domain text primary key check (domain = lower(domain)));
create table public.signup_invites (email text primary key check (email = lower(email)));
alter table public.signup_allowed_domains enable row level security;
alter table public.signup_invites enable row level security;
revoke all on public.signup_allowed_domains, public.signup_invites from anon, authenticated;
grant select on public.signup_allowed_domains, public.signup_invites to supabase_auth_admin;
create policy "auth admin reads domains" on public.signup_allowed_domains
for select to supabase_auth_admin using (true);
create policy "auth admin reads invites" on public.signup_invites
for select to supabase_auth_admin using (true);
insert into public.signup_allowed_domains values ('acme.com');
insert into public.signup_invites values ('[email protected]');
create or replace function public.hook_allowlist_signup(event jsonb)
returns jsonb language plpgsql as $$
declare
v_email text := lower(trim(event->'user'->>'email'));
v_domain text := split_part(v_email, '@', 2);
begin
if v_email is null or v_email = '' then
return jsonb_build_object('error', jsonb_build_object(
'http_code', 403, 'message', 'An email address is required to sign up.'));
end if;
if exists (select 1 from public.signup_invites i where i.email = v_email)
or exists (select 1 from public.signup_allowed_domains d where d.domain = v_domain) then
return '{}'::jsonb; -- allow
end if;
return jsonb_build_object('error', jsonb_build_object(
'http_code', 403, 'message', 'This app is invite-only.'));
end $$;
grant execute on function public.hook_allowlist_signup to supabase_auth_admin;
revoke execute on function public.hook_allowlist_signup from authenticated, anon, public;
Then select hook_allowlist_signup as the Before User Created hook in the Dashboard. Name variables v_email/v_domain: our first draft used email and failed with column reference "email" is ambiguous because the tables have an email column too.
Two limits, both from the docs: the hook only sees new users (existing accounts keep working, so do Step 4), and the email domain is not proof of a Workspace account (next section). We tested a local copy of a trigger on auth.users that rejects the same domains, and it works in plain Postgres, but the hook is the mechanism Supabase documents, so use that.
What about the hd claim and email_verified?
From Google’s OpenID Connect docs and ID token verification guide:
- The
hdrequest parameter only optimizes the account picker. Google: don’t rely on it to control access, because client-side requests can be modified. - The
hdclaim in the verified ID token is the domain of the user’s Workspace or Cloud organization, and Google says you must check it when restricting access to a domain. Nohdclaim = not a Google hosted domain account. - The email domain isn’t a reliable signal: people can register a Google Account without Gmail or Workspace, using another email address, and
email_verifiedcan staytrueeven if ownership of that address has since changed. Google is authoritative for@gmail.comaddresses and for accounts withemail_verifiedtrue andhdset.
We did not verify whether Supabase passes Google’s hd claim into the user record your hook receives, so don’t build on that without checking your own auth.identities.identity_data. If you need “only acme.com Workspace accounts”, the documented options are an explicit email allowlist (above) or Google’s Internal user type (next section). Either way, keep the membership check in Step 3.
The Google consent screen: Internal, External, Testing
Per Google’s Manage App Audience page:
- Internal: available to projects in a Google Cloud Organization; limits authorization to members of that organization. Others get an
org_internalerror. - External: any Google Account.
- Personal: only the single account that created the app (can’t be changed later).
- Testing (External only): up to 100 listed test users, and their authorizations expire seven days after consent. Useful while building, not as a permanent access list.
If your Supabase or Firebase Google provider uses an OAuth client in your Workspace organization’s Cloud project, Internal blocks outside Google accounts before they reach your app. That’s our inference from how the pieces fit; it only covers Google sign-in, so email, GitHub or other providers you enabled skip it.
Step 3: check membership on every read and write
This is the part that protects the data even if someone gets an account. Replace “signed in” policies with a membership lookup. The members table must be written only by an admin or server code, never by the app when someone signs in:
create table public.members (
user_id uuid primary key references auth.users(id) on delete cascade,
role text not null default 'member' check (role in ('member', 'admin')),
added_at timestamptz default now()
);
alter table public.members enable row level security;
grant select on public.members to authenticated;
revoke insert, update, delete on public.members from authenticated, anon;
create policy "members see own membership" on public.members
for select to authenticated using (user_id = (select auth.uid()));
create function public.is_member() returns boolean
language sql stable security definer set search_path = '' as $$
select exists (select 1 from public.members m where m.user_id = (select auth.uid()))
$$;
revoke execute on function public.is_member() from public, anon;
grant execute on function public.is_member() to authenticated;
-- Replace each "signed in" policy
drop policy "authenticated can read clients" on public.clients;
create policy "members read clients" on public.clients
for select to authenticated using ((select public.is_member()));
Do the same for insert/update/delete (with check ((select public.is_member())), plus any owner or team scoping you need). Rerun the policy check until it returns nothing: permissive policies are combined with OR, so one leftover “signed in” policy keeps the table open (we hit exactly that in our test). Per-team scoping: see the membership policy on the share-link page. Roles and plans users can edit themselves: plan / is_admin columns. Don’t store roles in user_metadata: Supabase’s RLS docs say users can update it; app_metadata they can’t.
Firebase and Clerk
Firebase (docs-based). Blocking functions need Firebase Authentication with Identity Platform. beforeUserCreated runs before a new user is saved; beforeUserSignedIn runs after credentials are verified, before an ID token is returned (creating a user triggers both). Throw an HttpsError to block. They must respond within 7 seconds, apply to all users in the project, and anonymous and custom auth don’t trigger them. If you delete one, unregister it too, or nobody can sign in. Firebase’s example checks user?.email?.includes('@example.com'); our test shows a substring check accepts [email protected] and rejects [email protected], so match the domain exactly:
import { beforeUserCreated, HttpsError } from "firebase-functions/v2/identity";
export const beforecreated = beforeUserCreated((event) => {
const email = (event.data?.email || "").toLowerCase();
const [local, domain, extra] = email.split("@");
if (!local || extra !== undefined || domain !== "acme.com" || !event.data?.emailVerified) {
throw new HttpsError("permission-denied", "This app is invite-only.");
}
});
Firebase can also pass the Google ID token to blocking functions if you enable that option in the Authentication settings, which is where you’d check hd. Then fix the rules: per Firebase’s rules and auth docs, request.auth.token has email, email_verified and any custom claims. request.auth != null alone means any signed-up user (see Firestore insecure rules). Require a members document (exists()) or a custom claim set by the Admin SDK:
match /databases/{database}/documents {
function isMember() {
return request.auth != null
&& request.auth.token.email_verified == true
&& exists(/databases/$(database)/documents/members/$(request.auth.uid));
}
match /clients/{id} {
allow read, write: if isMember();
}
match /members/{uid} {
allow read: if request.auth != null && request.auth.uid == uid;
allow write: if false; // only the Admin SDK / server adds members
}
}
Custom claims (request.auth.token.member == true) work too, but they reach the client only on a new sign-in, a token refresh, or getIdToken(true), and the payload must stay under 1000 bytes.
Clerk (docs-based). Per Restrict access: Access mode is Open by default; Invite-only limits access to invited users, enterprise connections or manually created users; Waitlist requires approval. The Allowlist (email addresses or whole domains) only works in Open mode, needs a paid plan in production (free in development), and enabling it with no entries blocks all sign-ups. You still need authorization on your data.
Step 4: remove strangers who already got in
- Use the Step 1 query to list accounts from unexpected domains, then delete or ban them in the Dashboard (Supabase Authentication > Users; Firebase Authentication > Users).
- If those accounts could read secrets (API keys, tokens or passwords stored in tables), rotate them. Guide: find and fix leaked API keys.
- Repeat the private-window test with a brand-new Gmail account, then sign in as a real member to confirm nothing broke.
Paste this into Lovable, Bolt, Replit or Cursor
Any Google account can sign in to this app and see data. Signing in must not
mean being allowed in. Fix authorization without breaking real users:
1. List every place we read or write data (Supabase/Firebase calls, API
routes) and every RLS policy or security rule. Flag any whose only check
is "signed in": using (true) to authenticated, auth.role() =
'authenticated', auth.uid() is not null, request.auth != null.
2. Create a members table (user_id, role) that only an admin or server code
can write. Never insert into it automatically when someone signs in.
3. Replace each "signed in" policy/rule with one that requires membership
(Supabase: a security definer is_member() function used in RLS; Firebase:
exists() on members/{uid} plus email_verified). Cover select, insert,
update and delete.
4. Stop strangers creating accounts: tell me the exact Supabase setting
(Allow new users to sign up) or write a deny-by-default
before-user-created hook that allows only these domains/emails: [LIST].
Match domains exactly, lowercase, no substring checks. Firebase: a
beforeUserCreated blocking function.
5. Do not rely on the Google hd parameter or React checks for access.
6. Give me SQL to list existing users by provider and email domain so I can
remove strangers. Show all SQL and setting changes before applying them.
What we verified
- Tested locally (Nov 18, 2026, Postgres 17 via PGlite,
research/pglite-test/t5.mjs): with Supabase-styleanon/authenticatedroles andauth.uid()/auth.role()/auth.jwt()stand-ins reading JWT claims, a “stranger” (random Gmail account) read every row throughto authenticated using (true),auth.role() = 'authenticated'andauth.uid() is not nullpolicies, and so did an anonymous user (is_anonymous,authenticatedrole); logged-outanonsaw 0 rows. The users query grouped accounts by provider and domain, and the policy check flagged all four “signed in” policies (including the(select auth.uid()) is not nullform) without flagging a scopedauth.uid() is not null and user_id = auth.uid()policy. After the membership fix: the stranger and the anonymous user saw 0 rows, couldn’t insert themselves intomembers(42501), the owner and an invited contractor on a personal Gmail saw their rows, and removing the contractor’s membership cut them off. A leftover(select auth.uid()) is not nullpolicy kept one table readable until we dropped it. The deny-by-default hook function, called assupabase_auth_admin, allowed[email protected],[email protected]and the invited Gmail address, and rejected[email protected],[email protected],[email protected]and a user with no email; signed-in users couldn’t call it or read the allowlist. ABEFORE INSERTtrigger on a localauth.userscopy rejected[email protected]and allowed[email protected], and pre-existing users were untouched. In plain JavaScript,includes('@acme.com')accepted[email protected]and[email protected]and rejected[email protected]; the exact match did the opposite. - Docs-based (fetched Nov 18, 2026, all HTTP 200): every Supabase, Google, Firebase and Clerk setting, plan, limit and behavior above comes from the linked docs, including what the signup toggle does, how and when the hook runs, and the consent screen user types. We did not sign in to a live Supabase, Firebase, Clerk or Google project, didn’t test invites with signups off, and didn’t deploy the Firebase function or run the Firestore rules in the emulator.
- Reported by others: the Claroc finding (via our share-link page).
- Our inference, labeled as such: that Google’s Internal user type blocks outside accounts before they reach a Supabase/Firebase app using that OAuth client, and that other enabled providers bypass it.
Related: Your app is public to anyone with the link, USING (true) policies, rules that only live in the frontend, users updating their own plan or is_admin column, Firestore insecure rules, and Check your Supabase RLS in two minutes.
When to get help
Get help if strangers already have accounts in an app that holds customer, health, payroll or employee data, if your AI tool keeps 'fixing' empty screens by loosening policies back to 'any signed-in user', if the app mixes several sign-in providers and you're not sure which ones skip your checks, or if you need Workspace-only access and aren't sure your setup really enforces it.
Want us to look at your app?
VibeCPR Rescue Reports are launching soon: we scan your repo and live app, and a human verifies every critical finding. Join the waitlist for early access and founder pricing. You'll also get Patch Notes, our weekly fixes newsletter.
FAQ
Why can any Google account sign in to my app?
Because signing in with Google only proves the person controls that Google account. Supabase's social login docs describe it as letting users register and sign in with their existing accounts, so a new Google user gets a new account unless you turn signups off or reject them in a hook. After that, any policy that only checks "is signed in" (to authenticated using (true), auth.role() = 'authenticated', auth.uid() is not null, or Firestore request.auth != null) shows them the data. You need a separate check of who is allowed in.
Does the hd parameter restrict Google sign-in to my domain?
No. Google's OpenID Connect docs say the hd request parameter only optimizes the account chooser, and warn not to rely on it to control access because client-side requests can be modified. To restrict access to a Google Workspace or Cloud organization domain, your backend must check the hd claim inside the verified ID token. A missing hd claim means the account doesn't belong to a Google hosted domain.
Is checking that the email ends in @mycompany.com enough?
Not on its own. Google's docs say you can't rely on the email domain to identify Workspace users and should use the hd claim, because people can register a Google Account without Gmail or Google Workspace, using another email address, and email_verified can stay true even if ownership of that third-party address has since changed. If you check the email domain, match it exactly (our test shows a substring check like includes("@acme.com") also accepts [email protected] and [email protected]), and still check membership in your database.
If I turn off "Allow new users to sign up" in Supabase, can people still use Google sign-in?
Supabase's docs say that with this setting disabled, only existing users can sign in. So people who already have an account can still use Google; new Google accounts can't create one. You then add the people you want yourself, for example with the admin API's inviteUserByEmail from server code. We haven't tested this on a live project, so confirm it with a fresh Gmail account after switching.
Can I limit sign-in with the Google OAuth consent screen instead?
Partly. In Google Auth Platform, an Internal user type limits authorization to members of your Google Cloud organization (Workspace accounts), and a Personal user type limits it to the single account that created the app. External apps in Testing are limited to up to 100 listed test users whose authorizations expire after seven days, so Testing is not a long-term access list. This only covers Google: if your Supabase or Firebase project also allows email, GitHub or other providers, those skip it (our inference). Keep the membership check in the database either way.
What is the difference between authentication and authorization?
Authentication answers "who are you?" (Google, a password or a magic link proves it). Authorization answers "what may you do here?" and has to be enforced by your backend: Supabase RLS policies that check a members table, Firestore rules that check a members document or custom claim, or server code. Hiding buttons in React is neither; anyone can call your Supabase or Firebase API directly with the public key.
How do I restrict a Firebase app to my company's Google accounts?
Firebase's docs show a beforeUserCreated blocking function that throws an HttpsError for emails outside your domain, and another that rejects unverified emails. Blocking functions need Firebase Authentication with Identity Platform and must answer within 7 seconds. Use an exact domain match rather than the docs' includes() example, and back it with Firestore rules that check request.auth.token.email_verified plus a members document or custom claim, not just request.auth != null.
Sources
- Supabase docs: Before User Created hook (reject signups by domain, provider or IP)
- Supabase docs: Auth Hooks (plans, permissions for supabase_auth_admin, Dashboard > Hooks)
- Supabase docs: General configuration (Allow new users to sign up)
- Supabase docs: Social sign-in (OAuth) overview
- Supabase docs: Login with Google
- Supabase docs: Identities
- Supabase docs: Row Level Security (authenticated role, anonymous users, auth.jwt())
- Supabase docs: CLI config (auth.enable_signup)
- Supabase docs: auth.admin.inviteUserByEmail
- Google: OpenID Connect (hd parameter and hd / email_verified claims)
- Google: Verify the Google ID token on your server side
- Google Cloud Help: Manage App Audience (Internal, External, Personal, Testing, test users)
- Firebase docs: Extend Firebase Authentication with blocking functions
- Firebase docs: Security Rules and Firebase Authentication (auth.token fields, custom claims)
- Firebase docs: Control access with custom claims
- Firebase docs: Writing conditions for Cloud Firestore Security Rules (get() and exists())
- Clerk docs: Restrict access (Access mode, Allowlist, Blocklist)
Related fixes
- AI agent pushed API keys to GitHub? git commit --no-verify skipped your pre-commit hook
- Fix a surprise AI API bill: rate limits and spend caps
- Your app is public to anyone with the link: a share link is not a login
- Triage Bolt's "RLS Policy Always True" warning: when it's fine and how to fix it
- Fix secrets leaked via Claude Code .claude/settings.local.json
- Fix "Your Cloud Firestore database has insecure rules" (Firebase email)
- Login lockout keyed only on email? Rate-limit by IP and account without locking users out
- Fix Lovable "Invalid API key" after rotating Supabase keys (anon, publishable, secret)
- Lovable won't publish because of security findings? What each finding means and how to fix it
- Fix Stripe sk_live keys left in MCP or agent config
- Fix Stripe webhook "No signatures found matching the expected signature for payload"
- Fix Supabase auth redirecting to localhost after deploy
- Fix Supabase Edge Function "blocked by CORS policy" (preflight)
- Fix Supabase "infinite recursion detected in policy for relation" (42P17) in RLS
- Form says success but no row in Supabase (or Stripe webhook returns 200 but writes nothing)
- Fix "new row violates row-level security policy for table" (Supabase)
- Supabase only returns 1,000 rows? Fix the silent max rows limit in Lovable and Bolt apps
- Fix Supabase "permission denied for table" (42501) on new tables after Oct 30, 2026
- Fix a Supabase public Storage bucket that lets anyone list or download your files
- Supabase Realtime leaking rows or not receiving changes: fix RLS and the publication
- Supabase RLS not working on the server? Your API uses the service_role or secret key
- Fix Supabase RLS policy USING (true) that makes a table publicly readable
- Your app's rules only live in the frontend: move them into Supabase
- Fix a Supabase SECURITY DEFINER function anyone can call through /rest/v1/rpc
- Fix Supabase .single() "JSON object requested, multiple (or no) rows returned" (PGRST116)
- Stop Supabase users from upgrading their own plan or making themselves admin
- Fix a Supabase view that bypasses RLS: security_invoker and revoking anon write grants
- Fix "404: NOT_FOUND" on refresh in a React/Vite app on Vercel (vercel.json rewrite)
- Fix "Module not found: Can't resolve" on Vercel (works locally)
- Is my Vite dev server exposed? Check --host / server.host and patch the RCE (GHSA-p4f5-76q4-ffq7)