fix(invitations): a token could never be generated — pgcrypto is in another schema - #808
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
generate_invitation_token()callsgen_random_bytes(24)unqualified and declares nosearch_path, so the name resolves against whatever the caller has. pgcrypto lives inextensions(the normal Supabase layout) and PostgREST calls withpublicon 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:
extensions.gen_random_bytes, so it resolves by name rather than by whoever is calling;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:
function gen_random_bytes(integer) does not exist🤖 Generated with Claude Code
https://claude.ai/code/session_012dpTLxh5GJWeWTF1UEvcD5