ring-clojure / ring-headers

Ring middleware for common response headers
26 stars 12 forks source link

Add a proxy-count option to support multiple proxies #9

Open danielcompton opened 4 years ago

danielcompton commented 4 years ago

In some environments, a request may be forwarded through multiple trusted proxies before it reaches the ring server. This commit adds a proxy-count option to configure how far from the end the middleware should look for the 'real' :remote-address.

For a concrete example, take Google Cloud App Engine Flexible with Docker. A request comes into the load balancer. The request is proxied to a web server on the VM, where it is re-proxied a final time to the application. In this case, if a request starts with no X-Forwarded-For headers, it will end up looking something like

{:headers {"X-Forwarded-For" "122.54.196.223, 216.58.196.147"}
 :remote-addr "172.17.0.5"
 ;; ... 
 }

where 122.54.196.223 is my home IP address, 216.58.196.147 is the Google load balancer address, and 172.17.0.5 is the Docker container bridge IP address.

Also, what do you think should happen if proxy-count is set to 0? Is that an error condition, or should this middleware remove itself and just call (handler request)?

This is not ready for merging, I'm opening this up for discussion on naming, documentation, implementation details, etc. What are your thoughts?