-
Notifications
You must be signed in to change notification settings - Fork 4
ENG-925 Upgrade supabase JWT keys #752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fad28f3
e7f9da0
68b3e04
be52a84
c958756
2a3e1b6
67b12c0
6341a73
491651a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
maparent marked this conversation as resolved.
Show resolved
Hide resolved
|
maparent marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,6 @@ | ||||||||||||||||||||||||
| // Follow this setup guide to integrate the Deno language server with your editor: | ||||||||||||||||||||||||
| // https://deno.land/manual/getting_started/setup_your_environment | ||||||||||||||||||||||||
| // This enables autocomplete, go to definition, etc. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import "@supabase/functions-js/edge-runtime"; | ||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||
| createClient, | ||||||||||||||||||||||||
|
|
@@ -209,22 +208,46 @@ Deno.serve(async (req) => { | |||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const input = await req.json(); | ||||||||||||||||||||||||
| // @ts-ignore Deno is not visible to the IDE | ||||||||||||||||||||||||
| const url = Deno.env.get("SUPABASE_URL"); | ||||||||||||||||||||||||
| const url = Deno.env.get("SUPABASE_URL") as string | undefined; | ||||||||||||||||||||||||
| // @ts-ignore Deno is not visible to the IDE | ||||||||||||||||||||||||
| const key = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY"); | ||||||||||||||||||||||||
| const key = Deno.env.get("SB_SECRET_KEY") as string | undefined; | ||||||||||||||||||||||||
| if (!url || !key) { | ||||||||||||||||||||||||
| return new Response("Missing SUPABASE_URL or SUPABASE_SERVICE_ROLE_KEY", { | ||||||||||||||||||||||||
| return new Response("Missing SUPABASE_URL or SB_SECRET_KEY", { | ||||||||||||||||||||||||
| status: 500, | ||||||||||||||||||||||||
| headers: { "Content-Type": "application/json" }, | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // check that we have at least a valid anonymous token with a dummy query. | ||||||||||||||||||||||||
| // Unfortunately, this seems to be too permissive. | ||||||||||||||||||||||||
| const authHeader = req.headers.get('Authorization') as string | undefined; | ||||||||||||||||||||||||
| if (!authHeader) { | ||||||||||||||||||||||||
| return Response.json( | ||||||||||||||||||||||||
| { msg: 'Missing authorization headers' }, | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| status: 401, | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| const token = authHeader.replace('Bearer ', ''); | ||||||||||||||||||||||||
| const supabaseAnonClient: DGSupabaseClient = createClient( | ||||||||||||||||||||||||
| url, token, { global: { headers: { Authorization: authHeader } } }); | ||||||||||||||||||||||||
|
Comment on lines
+234
to
+235
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical Bug: The The token is already being passed in the Authorization header via options. The second parameter should be the const anonKey = Deno.env.get("SB_PUBLISHABLE_KEY");
if (!anonKey) {
return Response.json(
{ msg: 'Missing SB_PUBLISHABLE_KEY' },
{ status: 500 }
)
}
const supabaseAnonClient: DGSupabaseClient = createClient(
url, anonKey, { global: { headers: { Authorization: authHeader } } });
Suggested change
Spotted by Graphite Agent |
||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| const { error } = await supabaseAnonClient.from("Space").select("id").limit(1); | ||||||||||||||||||||||||
| if (error?.code) return new Response(JSON.stringify(error), { | ||||||||||||||||||||||||
| status: 401, | ||||||||||||||||||||||||
| headers: { "Content-Type": "application/json" }, | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // note: If we wanted this to be bound by permissions, we'd set the following options: | ||||||||||||||||||||||||
| // { global: { headers: { Authorization: req.headers.get('Authorization')! } } } | ||||||||||||||||||||||||
| // { global: { headers: { Authorization: authHeader } } } | ||||||||||||||||||||||||
| // But the point here is to bypass RLS | ||||||||||||||||||||||||
| const supabase: DGSupabaseClient = createClient(url, key); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const input = await req.json(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const { data, error } = await processAndGetOrCreateSpace(supabase, input); | ||||||||||||||||||||||||
| if (error) { | ||||||||||||||||||||||||
| const status = error.code === "invalid space" ? 400 : 500; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.