Skip to content

Commit 57f51f5

Browse files
authored
Merge pull request #411 from coreruleset/copilot/fix-x-forwarded-port-headers
fix(nginx): disable port_in_redirect to fix internal port leakage in redirects
2 parents faf26bc + 63e57d3 commit 57f51f5

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ An example can be seen in the [docker-compose](https://github.com/coreruleset/mo
155155
156156
Both nginx and httpd containers now run with an **unprivileged user**. This means that we cannot bind to ports below 1024, so you might need to correct your `PORT` and `SSL_PORT` settings. Now the defaults for both nginx and httpd are `8080` and `8443`.
157157

158+
### Nginx `port_in_redirect` breaking change
159+
160+
> [!WARNING]
161+
> nginx now has [`port_in_redirect`](https://nginx.org/en/docs/http/ngx_http_core_module.html#port_in_redirect) set to `off` in all server blocks.
162+
163+
Previously, nginx's default `port_in_redirect on` caused the internal listening port (e.g., `8080` or `8443`) to be included in redirect `Location` headers (e.g., when nginx adds a trailing slash: `/address``http://example.com:8080/address/`). This broke setups where the container is behind a reverse proxy and the external port differs from the internal port.
164+
165+
With `port_in_redirect off`, nginx omits the port from redirect URLs, so clients follow redirects using the correct external port. **If you relied on the port being included in nginx-generated redirects, you will need to mount a custom `default.conf.template` and re-enable this directive.**
166+
158167
### Common ENV Variables
159168

160169
These variables are common to image variants and will set defaults based on the image name.

nginx/templates/conf.d/default.conf.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ server {
1313
server_name ${SERVER_NAME};
1414
set $always_redirect ${NGINX_ALWAYS_TLS_REDIRECT};
1515

16+
port_in_redirect off;
17+
1618
PROXY_SSL_CONFIG
1719

1820
location / {
@@ -38,6 +40,8 @@ server {
3840

3941
server_name ${SERVER_NAME};
4042

43+
port_in_redirect off;
44+
4145
ssl_certificate ${SSL_CERT_FILE};
4246
ssl_certificate_key ${SSL_CERT_KEY_FILE};
4347
ssl_session_timeout 1d;

0 commit comments

Comments
 (0)