-
Notifications
You must be signed in to change notification settings - Fork 5
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
Routes without trailing slash cause 307
redirect which breaks reverse proxies via paths
#327
Closed
3 tasks done
Labels
released
This issue/pull request has been released.
Comments
7 tasks
PR #328 is ready to merge, but will wait for the PR for neurobagel/query-tool#234 to maintain compatibility with the query tool. |
3 tasks
🚀 Issue was released in |
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context
Depending on whether a route in FastAPI is defined with or without a trailing slash, FastAPI by default tries to automatically redirect the alternative to the URL with the
/
added or removed (see examples below).Right now:
curl -L
):307
)307
)Some consequences:
my-neurobagel-node.org/api
->localhost:8000
, when we send a request tomy-neurobagel-node.org/api/query
, the redirect is followed leading tomy-neurobagel-node.org/query
, which does not exist from the perspective of the proxyhttps://
, this can become lost and turn intohttp://
during the redirect (e.g., Trailing backslash reruns makes a redirect that looses https. fastapi/fastapi#8514)curl -v -L https://qpn.neurobagel.org/query
), possibly because (1) the Dockerized NGINX config which forwards headers by default, and (2) the NGINX container is on the same Docker network as the Uvicorn server, there might be an implicit trust mechanism between IPs on the same networkThis hasn't been an issue for us in the past because:
-L
(or, we have been using it pretty liberally)Rather than the current redirect behaviour (which is also less efficient due to multiple round trips), we probably want one of the following outcomes:
Option 1:
(can be achieved via two route decorators)
Option 2 (selected):
(can be achieved w/ the
redirect_slashes
parameter of the FastAPI and/or APIRouter class)Decisions
redirect_slashes
globally (option 2) for more predictable behaviour--forwarded-allow-ips=*
flag as recommended in Why FastAPI redirects url with a trailing slash instead of resolving it internally? fastapi/fastapi#9328 (comment) to ensure we don't lose HTTPS behind a proxy (this shouldn't happen anymore now that we're getting rid of redirects, but might be a good safeguard regardless)Relevant issues:
The text was updated successfully, but these errors were encountered: