Skip to content
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

Set CORS headers for Edge Functions 401 response #213

Open
acurrieclark opened this issue Nov 25, 2022 · 2 comments
Open

Set CORS headers for Edge Functions 401 response #213

acurrieclark opened this issue Nov 25, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@acurrieclark
Copy link

Bug report

Originally posted in the main supabase repo, but reposting here as it seems to have regressed.

Describe the bug

When attempting to call an edge function with a bad token, the function rightly issues a 401 response. However, while CORS headers appear to be set for the preflight OPTIONS request, they are not for the subsequent POST request, resulting in the browser seeing a failed fetch rather than the 401 response.

Please note that this is not to do with setting cors headers within the function, as with a bad token the function code is never reached.

To Reproduce

fetch(
    import.meta.env.SUPABASE_FUNCTION_URL,
  {
    method: "POST",
    headers: {
      Authorization: "Bearer bad-token",
      "Content-Type": "application/json",
    },
  }
)
  .then((res) => {
    console.log(res);
  })
  .catch((error) => {
    console.log(error);
  });

When CORS is enabled in the browser, an error is caught. With CORS disabled (in the browser), the response is properly logged.

Expected behavior

The response should have appropriate CORS headers set.

System information

  • OS: OS X 12.5.1
  • Browser: Brave (also confirmed in Chrome)
@acurrieclark acurrieclark added the bug Something isn't working label Nov 25, 2022
@acurrieclark
Copy link
Author

I have just done some further testing, and can verify that this does not occur in a production supabase function.

@sweatybridge sweatybridge transferred this issue from supabase/cli Nov 9, 2023
@sweatybridge
Copy link

Transferring to edge runtime repo. Not sure if this is still reproducible now that we have switched out of deno container completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants