peppermint icon indicating copy to clipboard operation
peppermint copied to clipboard

next-auth makes a request to BASE_URL for CSRF tokens, which may fail behind a loadbalancer

Open mac-chaffee opened this issue 3 years ago • 1 comments

If you place peppermint behind some kind of loadbalancer or proxy where the BASE_URL might not be reachable from within the container, logins will fail with an error like this:

name: 'FetchError'
  at processTicksAndRejections (internal/process/task_queues.js:95:5)',
  at runMicrotasks (<anonymous>)\n' +
  at /app/node_modules/node-fetch/lib/index.js:272:32\n' +
    stack: 'FetchError: invalid json response body at http://mac-peppermint.macchaffee.com/api/auth/csrf reason: Unexpected token < in JSON at position 0\n' +
    message: 'invalid json response body at http://mac-peppermint.macchaffee.com/api/auth/csrf reason: Unexpected token < in JSON at position 0',

https://next-auth.js.org/errors#client_fetch_error invalid json response body at http://mac-peppermint.macchaffee.com/api/auth/csrf reason: Unexpected token < in JSON at position 0

In my case, my loadbalancer rejected the request with a 403 HTTP response (hence the opening angle bracket) because the source IP of the request came from within the container, which I have not allow-listed.

Not sure if this is an issue with peppermint or with next-js, but it is definitely strange that a web server should need to send itself an API call.

It sorta works if BASE_URL is set to localhost:5001 since that request always works from within the container, but then that breaks other parts of Peppermint.

mac-chaffee avatar Mar 10 '22 21:03 mac-chaffee

Will have to have a deeper look into this :)

potts99 avatar Mar 20 '22 16:03 potts99

Working on moving away from next auth which should remove this issue

potts99 avatar Sep 02 '23 14:09 potts99