belgattitude / php-java-bridge

Soluble PHP/Java bridge server (unofficial fork)
Other
46 stars 10 forks source link

FastCGI sets SERVER_PORT to the local port instead of the server port #67

Open stefanofornari opened 1 year ago

stefanofornari commented 1 year ago

In https://github.com/belgattitude/php-java-bridge/blob/146592a8984405a6f360edf719ace96da04bbe63/src/main/java/io/soluble/pjb/servlet/fastcgi/FastCGIServlet.java#L201, which in turns call https://github.com/belgattitude/php-java-bridge/blob/146592a8984405a6f360edf719ace96da04bbe63/src/main/java/io/soluble/pjb/servlet/ServletUtil.java#L97, FastGCI sets SERVER_PORT to the local port. This does not work when the container is behind a proxy or a NAT. If for example you are natting your more router so that the external port is 80, but you run your service on a tomcat on port 8080, SERVER_PORT should be set 80, not 8080. To do so, FastCGI should pic the server port (req.getServerPort()) and may be fall back on req.getLocalPort(), not the other way around.

stefanofornari commented 1 year ago

I fixed it here: https://github.com/stefanofornari/php-java-bridge