supabase / auth-helpers

A collection of framework specific Auth utilities for working with Supabase.
https://supabase.github.io/auth-helpers/
MIT License
892 stars 240 forks source link

Cookie issue leads to 502 Gateway Error with supabase SSR #801

Closed philmas closed 3 weeks ago

philmas commented 3 weeks ago

Bug report

Describe the bug

I am not sure whether this is related to this discussion. However, I seem to be running into an issue where I obtain a 502 Bad Gateway error in my application to do with cookies setup. The supabase instance reports success.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create an SSR authentication flow as described in the docs
  2. Obtain a valid cookie by logging in.
  3. Wait until cookie refresh needs to occur and visit the website.
  4. See error

Expected behavior

Should function normally. If I remove my cookies, the site functions normally and login works flawlessly. Only when cookie refresh needs to occur it leads to an 502. Cookie size is about 2300.

Log Details

No errors are to be found anywhere except for a successful auth log from supabase. Other sveltekit applications have the same issue. Making it likely that it is a supabase issue / incorrect implementation of code.

{
  "component": "api",
  "level": "info",
  "method": "POST",
  "msg": "request started",
  "path": "/token",
  "referer": "<url>",
  "remote_addr": "172.19.0.1",
  "time": "2024-06-09T20:41:07Z",
  "timestamp": "2024-06-09T20:41:07Z"
}

{
  "action": "login",
  "instance_id": "00000000-0000-0000-0000-000000000000",
  "level": "info",
  "login_method": "token",
  "metering": true,
  "msg": "Login",
  "time": "2024-06-09T20:41:07Z",
  "user_id": "<user-id>"
}

{
  "auth_event": {
    "action": "token_refreshed",
    "actor_id": "<actor_id>",
    "actor_username": "<username>",
    "actor_via_sso": false,
    "log_type": "token"
  },
  "component": "api",
  "duration": 13129690,
  "level": "info",
  "method": "POST",
  "msg": "request completed",
  "path": "/token",
  "referer": "<url>",
  "remote_addr": "172.19.0.1",
  "status": 200,
  "time": "2024-06-09T20:41:07Z",
  "timestamp": "2024-06-09T20:41:07Z"
}

System information

philmas commented 3 weeks ago

Issue was related to the header size.

Solved by adding the following to the proxy configuration.

proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
large_client_header_buffers 4 16k;