-
-
Notifications
You must be signed in to change notification settings - Fork 894
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
HTTPS: Hostname is not an accepted origin, even on same-origin requests #1501
Comments
Are you using something like the https://werkzeug.palletsprojects.com/en/1.0.x/middleware/proxy_fix/ |
Thanks for the quick response, @miguelgrinberg!
Oh, I'm not. Is that Flask-SocketIO's recommended solution for accessing a Flask-SocketIO endpoint through nginx? From reading the source more carefully, I realized that this nginx configuration gets things working under HTTPS and seems fairly clean:
|
All these headers that you added manually are included in the If you are using a relatively new build of the python-engineio package than this is all it takes. I mentioned the ProxyFix because that used to be required in the past. You indicated that you were using the same nginx configuration that is shown in the documentation, so I assumed you already had the proxy params defined. |
The It looks like Flask-SocketIO is looking for the $ cat /etc/nginx/proxy_params
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; $ nginx -V
nginx version: nginx/1.14.2
built with OpenSSL 1.1.1d 10 Sep 2019
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-dPHYpN/nginx-1.14.2=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-mail=dynamic --with-mail_ssl_module --add-dynamic-module=/build/nginx-dPHYpN/nginx-1.14.2/debian/modules/http-auth-pam --add-dynamic-module=/build/nginx-dPHYpN/nginx-1.14.2/debian/modules/http-dav-ext --add-dynamic-module=/build/nginx-dPHYpN/nginx-1.14.2/debian/modules/http-echo --add-dynamic-module=/build/nginx-dPHYpN/nginx-1.14.2/debian/modules/http-upstream-fair --add-dynamic-module=/build/nginx-dPHYpN/nginx-1.14.2/debian/modules/http-subs-filter |
Oh, okay, I see the problem now. It's a bug. The |
Describe the bug
I'm accessing my Flask-SocketIO endpoint through an nginx reverse proxy. It works correctly over plaintext HTTP, but it fails over HTTPS with:
I know that one option is
cors_allowed_origins
, but that's not a great fit for my scenario. This is a server that users self-host, so they want to be able to rename it, access it by IP, or access it via a client-side host alias.The behavior I'm observing doesn't seem to match the docs:
I've captured HTTP traffic between nginx and my Flask-SocketIO endpoint under different nginx configurations:
http://tinypilot.local
tinypilot.local
HTTP/1.1 101 Switching Protocols
https://tinypilot.local
tinypilot.local
HTTP/1.1 400 BAD REQUEST "https://tinypilot.local is not an accepted origin."
proxy_set_header Origin http://$http_host;
tinypilot.local
tinypilot.local
HTTP/1.1 400 BAD REQUEST tinypilot.local is not an accepted origin.
proxy_set_header Origin "";
tinypilot.local
HTTP/1.1 101 Switching Protocols
The last configuration works, but it exposes a CSRF vulnerability because it would make all requests look like same-origin.
What is Flask-SocketIO's recommended configuration for communicating through a TLS proxy?
To Reproduce
Server
Client
Steps to reproduce the behavior:
socketio = flask_socketio.SocketIO())
const socket = io();
)Expected behavior
Flask-SocketIO accepts the connection because it's a same-origin request.
Logs
$http_host
(fails)The text was updated successfully, but these errors were encountered: