0
Challenge · 48Auth: Who Is Asking?

The JWT: app_metadata vs user_metadata

Authused in ~85% of apps

One line of client-side JavaScript — supabase.auth.updateUser({ data: { role: 'admin' } }) — is legal, succeeds, and requires no special access at all. If your RLS policy or your app trusts that value for anything, you just watched a user promote themselves to admin. The bug isn't in the update call. It's in ever having asked the wrong half of the token a security question.

Core idea. A signed-in user's JWT carries two claim families that look like siblings and are not. user_metadata (backed by auth.users.raw_user_meta_data) is whatever the user last wrote about themselves — set via signUp's options.data or updateUser({ data }) — and it is exactly as trustworthy as a text field on a public profile, because the user can rewrite it at will. app_metadata (raw_app_meta_data) is never user-writable; only a server-side admin call or a custom access token hook can set it. The JWT's signature guarantees the token was genuinely issued by Supabase — it says nothing about whether the data inside it came from a user or a server, and that distinction is the entire concept.
Playground, this isn't a screenshot
alice's JWT payload (decoded)
{
"sub": "11111111-…", "role": "authenticated",
"user_metadata": { "role": "member" } — user-writable
"app_metadata": { "role": "member" } — server-only
}
RLS policy checks…
Policy denies her. app_metadata never moved — only a server (the Admin API, or a custom access token hook) can write it. Her updateUser() call had nothing to reach.
↑ play a little first, then dig in