No way to specify Unix domain clients as trusted using --forwarded-allow-ips #2743
Replies: 1 comment
-
|
By my reading of the ASGI spec (https://asgi.readthedocs.io/en/latest/specs/www.html#http-connection-scope), the proper way to indicate that a client is connected via Unix socket is to set So a more robust and spec-compliant way to handle this would be:
Meanwhile, this doesn't work for AFAICT, when
The gunicorn documentation claims that |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When running uvicorn as a Unix-domain server using
--uds, I want to report the correct remote address and protocol to the ASGI application.That means that I want to honor the X-Forwarded-Proto header, and I want to honor the final entry in the X-Forwarded-For header, but I don't want to honor other entries in X-Forwarded-For unless they come from a trusted proxy.
From what I can tell, this is impossible: the only way to tell uvicorn to trust proxy headers from a Unix-domain client is to specify
--forwarded-allow-ips *, which means "trust everyone in the world".(For example, consider the recommended configuration at https://uvicorn.dev/deployment/#running-behind-nginx , which uses
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for. Without--forwarded-allow-ips, this header has no effect. With--forwarded-allow-ips *, any client is allowed to spoof any IP address.)It would be nice to be able to say something like
--forwarded-allow-ips 192.168.123.45,unix:. To make that work, I think the following change would be sufficient:But this could probably be more robust.
I also note that https://uvicorn.dev/deployment/#proxies-and-forwarded-headers says:
I think this comment is misleading; using a server socket path as a "Literal" doesn't work.
Beta Was this translation helpful? Give feedback.
All reactions