Hosted Edge Function returns HTTP 400 invalid_endpoint — request.url origin and route validation #52033
Replies: 4 comments
|
the routing docs show the path inside the function prefixed with the function name rather than for your handler check whether the actual pathname is your current keep an exact method and path allowlist plus your device authentication i would not infer the public origin from forwarded headers or claim the documented routing examples guarantee the internal scheme or host for every hosted deployment |
|
Your diagnostic logs ( Here are the direct technical answers to your 4 questions explaining why your validation check is failing and how to normalize it securely: 1. Does
|
|
The most useful next step is to separate the pathname validation failure from the origin/scheme validation failure before changing either security check. Supabase Edge Functions receive requests through the platform gateway, so I would avoid assuming that I'd check the following:
The key diagnostic is the actual pathname and parsed URL seen inside the handler. Since your current logs collapse both failures into Supabase's Edge Function routing documentation is a useful starting point: https://supabase.com/docs/guides/functions If you can share the sanitized pathname and protocol observed inside the function, it should be possible to narrow this down without relaxing the validation rules. |
|
I'd log the parsed URL once instead of the classified values, so you can see what the runtime actually receives: const u = new URL(req.url);
console.log(req.method, u.protocol, u.host, u.pathname);Supabase's routing docs match paths that start with the function name (e.g. const path = u.pathname.replace(/^\/functions\/v1(?=\/)/, '');
if (req.method === 'POST' && path === '/online-delivery-mvp/device/session') {
return handleDeviceSession(req); // device auth runs here, fail closed
}
return Response.json({ error: 'invalid_endpoint' }, { status: 400 });On scheme and host: I wouldn't validate them inside the function. They describe the internal hop to the runtime, which isn't documented as a contract. I also can't find documentation that The check that protects you is your device authentication, so make sure every allowlisted route runs it and rejects by default. If you also need an origin check for browsers, compare the |
Uh oh!
There was an error while loading. Please reload this page.
Issue
We are investigating an HTTP 400
invalid_endpointresponse from a hosted Supabase Edge Function.The function uses custom device authentication with
verify_jwt=false.Endpoint:
POST /functions/v1/online-delivery-mvp/device/sessionObserved behavior
The request returns HTTP 400
invalid_endpoint.Our sanitized diagnostic logs show:
The request appears to be rejected during origin and route validation, before device authentication.
What we have verified
Questions
request.urlcontain the public HTTPS URL or an internally rewritten gateway URL?request.urllegitimately use an HTTP scheme inside the hosted Edge Runtime?/functions/v1/{function-name}preserved in the URL pathname, or can the gateway strip this prefix?We want to preserve strict validation rather than weaken security checks.
Any guidance or references to the expected hosted runtime behavior would be appreciated.
Thank you.
All reactions