Skip to content

fix(invitations): a token could never be generated — pgcrypto is in another schema - #808

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/invitation-token
Aug 28, 2026
Merged

fix(invitations): a token could never be generated — pgcrypto is in another schema#808
github-actions[bot] merged 1 commit into
mainfrom
fix/invitation-token

Conversation

@catomean

Copy link
Copy Markdown
Collaborator

generate_invitation_token() calls gen_random_bytes(24) unqualified and declares no search_path, so the name resolves against whatever the caller has. pgcrypto lives in extensions (the normal Supabase layout) and PostgREST calls with public on the path — so it raised "function gen_random_bytes(integer) does not exist" every time. No invitation token has ever been generated.

Same family as the timeline functions in #806: a reference resolved only at call time, so it reads as correct until somebody uses it.

Found by the gate that shipped in #806, within minutes of it going live — which is the point of it. Nothing else in the stack can see this class.

Two changes, the first being the fix:

  • qualify the call as extensions.gen_random_bytes, so it resolves by name rather than by whoever is calling;
  • pin search_path, which this function did not set at all. An unpinned search_path lets a caller shadow a name the function resolves — worth closing on a function whose job is minting a credential.

Rehearsed against production and rolled back:

before raises function gen_random_bytes(integer) does not exist
after returns a 32-character token
broken-function count 12 → 11, matching the baseline the nightly gate holds

🤖 Generated with Claude Code

https://claude.ai/code/session_012dpTLxh5GJWeWTF1UEvcD5

…nother schema

generate_invitation_token() calls gen_random_bytes(24) unqualified and
declares no search_path, so the name resolves against whatever the
caller has. pgcrypto lives in `extensions`, the normal Supabase layout,
and PostgREST calls with `public` on the path — so the function raised
"function gen_random_bytes(integer) does not exist" every time. No
invitation token has ever been generated.

Same family as the timeline functions in 20260828110000: a reference
resolved only at call time, so it reads as correct until somebody uses
it. Found by the plpgsql_check gate added alongside them — the first
thing able to see this class at all, and it found this one within
minutes of shipping.

The call is now schema-qualified, and search_path is pinned, which this
function did not set at all. An unpinned search_path lets a caller
shadow a name the function resolves, which is worth closing on a
function whose job is minting a credential.

Rehearsed against production and rolled back: raises before, returns a
32-character token after, and the broken-function count falls 12 → 11,
matching the baseline the nightly gate now holds.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012dpTLxh5GJWeWTF1UEvcD5
@github-actions
github-actions Bot merged commit 49572db into main Aug 28, 2026
8 checks passed
@github-actions
github-actions Bot deleted the fix/invitation-token branch August 28, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant