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

FastCGI redirect loop with uWSGI since 6.1 #71

Open
hrkfdn opened this issue May 6, 2017 · 5 comments · May be fixed by #75
Open

FastCGI redirect loop with uWSGI since 6.1 #71

hrkfdn opened this issue May 6, 2017 · 5 comments · May be fixed by #75

Comments

@hrkfdn
Copy link
Contributor

hrkfdn commented May 6, 2017

Hey,

I just upgraded my system to OpenBSD 6.1 and have been running into problems with my Flask application deployed via uWSGI and FastCGI sockets.

Whenever I try to request the application I end up with a recursive redirect loop:

--2017-05-06 11:40:04--  http://foo.bar/
Resolving foo.bar (foo.bar)... x.x.x.x
Connecting to foo.bar (foo.bar)|x.x.x.x|:80... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 301 Moved Permanently
  Connection: keep-alive
  Content-Type: text/html; charset=utf-8
  Date: Sat, 06 May 2017 09:40:04 GMT
  Location: http://foo.bar/
  Server: OpenBSD httpd
  Transfer-Encoding: chunked
Location: http://foo.bar/ [following]

As you can see I request the root path and get redirected to it. If I run uWSGI in HTTP mode without httpd in between, this does not happen, so I'm assuming it's not a webapp or uWSGI problem. Additionally, this worked
fine in 6.0.

Has something changed in the way paths are passed to FastCGI changed between 6.0 and 6.1?

@hrkfdn
Copy link
Contributor Author

hrkfdn commented Jan 16, 2018

Did some research: This happens, because PATH_INFO is "" when an application mounted at the root path of a domain is requested.

In that case, it should probably be set to "/", otherwise Flask/Werkzeug will respond with an HTTP 301 to /.

Because PATH_INFO is still passed as "" after the redirect, although "/" was requested, an endless redirect loop occurs.

I am unsure, if this is an httpd or Werkzeug error.

hrkfdn added a commit to hrkfdn/httpd that referenced this issue Jan 21, 2018
This fixes Werkzeug-based and possibly other applications using
PATH_INFO.

CGI RFC3875[1] and PEP3333 state that PATH_INFO can be empty ("") or "/"
for application root paths, but some applications (Werkzeug/Flask)
except it to be "/". This diff ensures that.

Followup discussions:
reyk#71
pallets/werkzeug#1240

[1]: https://tools.ietf.org/html/rfc3875#section-4.1.5
[2]: https://www.python.org/dev/peps/pep-3333/#environ-variables
@hrkfdn hrkfdn linked a pull request Jan 21, 2018 that will close this issue
@throwable-one
Copy link

Faced same problem with httpd--fastcgi--uwsgi(flask). Django survives it somehow, but not Flask.
app.url_map.strict_slashes = False fixes issue for Flask.

Since browser explictily sends "/", should not httpd(8) set PATH_INFO="/" for fastcgi?
From the other hand, app is mounted to "/", so slash could be treated as mountpoint, not relative path.

@hrkfdn
Copy link
Contributor Author

hrkfdn commented Jun 4, 2018

I would opt for the first option as it seems to fix many problems and not cause any. But that's just me. I tried convincing many of the parties involved (Flask/Werkzeug, httpd), but unfortunately interest is limited. For now, I just keep my local installation patched.

@flipchan
Copy link

hello, thanks alot! i had the exact same problem, app.url_map.strict_slashes = False solved

VasquezNathan added a commit to tsainez/bobchat that referenced this issue Jun 14, 2022
We were experiencing this issue:
reyk/httpd#71
and now we are not.
@artsi0m
Copy link

artsi0m commented May 22, 2023

Thanks in advance for opening this issue and providing solution for Flask

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants