From 9529714aaa65a1bf6cebc25dde04e36be83440ab Mon Sep 17 00:00:00 2001 From: alexanderM91 Date: Tue, 17 Nov 2026 08:05:13 +0100 Subject: [PATCH] Serve /build.json and /build.php only to private networks --- docs/10-configuration-reference.md | 21 ++++++++++++++ .../nginx/conf.d/frontend.default.conf.twig | 2 ++ .../src/templates/nginx/http/build.conf.twig | 16 ++++++++++ .../nginx/modules/build-info.http.conf.twig | 29 +++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 generator/src/templates/nginx/modules/build-info.http.conf.twig diff --git a/docs/10-configuration-reference.md b/docs/10-configuration-reference.md index 02e2526b2..581e2ff12 100644 --- a/docs/10-configuration-reference.md +++ b/docs/10-configuration-reference.md @@ -74,3 +74,24 @@ image: memory_limit: {memroy_limit_value} ... ``` + + +## Checking the deployed build + +Every application endpoint serves `/build.json` (from the frontend container) and `/build.php` (from the application container). They return the deployed build hash and build timestamp: + +```json +{"self":"application","build":"{build_hash}","stamp":"{build_timestamp}"} +``` + +The endpoints need no configuration and are not public. They respond only to requests that did not pass through a public network: the client address, every `X-Forwarded-For` entry, and `X-Real-IP` must be private (`127.0.0.0/8`, `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`). Such requests skip the endpoint's `auth:`. All other requests are rejected with `403`, even with valid basic auth credentials. + +* Locally, open `http://{endpoint host}/build.json` or `http://{endpoint host}/build.php` in a browser or run `curl` against it. +* In AWS, send the request from inside the VPC directly to the frontend, for example, from the frontend container: + +```bash +curl -s -H 'Host: {endpoint host}' http://127.0.0.1/build.json +curl -s -H 'Host: {endpoint host}' http://127.0.0.1/build.php +``` + +Requests to the public endpoint URL, including the ones sent from AWS through the NAT gateway, are rejected. diff --git a/generator/src/templates/nginx/conf.d/frontend.default.conf.twig b/generator/src/templates/nginx/conf.d/frontend.default.conf.twig index e5ada1acb..40d013b14 100644 --- a/generator/src/templates/nginx/conf.d/frontend.default.conf.twig +++ b/generator/src/templates/nginx/conf.d/frontend.default.conf.twig @@ -12,6 +12,8 @@ geo $is_whitelisted_ip { {% endif %} } +{% include "nginx/modules/build-info.http.conf.twig" %} + {% if _realIpTrusted is not empty %} {% include "nginx/modules/real-ip.http.conf.twig" with { realIpConfigs: _realIpTrusted, diff --git a/generator/src/templates/nginx/http/build.conf.twig b/generator/src/templates/nginx/http/build.conf.twig index edbd91ea6..5735b6d51 100644 --- a/generator/src/templates/nginx/http/build.conf.twig +++ b/generator/src/templates/nginx/http/build.conf.twig @@ -1,9 +1,25 @@ +{# + Build info is served only to requests that did not pass through a public network, + see nginx/modules/build-info.http.conf.twig. Such requests skip the endpoint's own auth. +#} location =/build.json { + if ($spryker_build_info_allowed = 0) { + return 403; + } + allow all; + auth_basic off; + root /usr/share/nginx/; try_files $uri =404; } location =/build.php { + if ($spryker_build_info_allowed = 0) { + return 403; + } + allow all; + auth_basic off; + root /home/spryker; include fastcgi.conf; {# Variable is necessary for https://www.nginx.com/blog/dns-service-discovery-nginx-plus/#domain-name-upstream-group #} diff --git a/generator/src/templates/nginx/modules/build-info.http.conf.twig b/generator/src/templates/nginx/modules/build-info.http.conf.twig new file mode 100644 index 000000000..755a9e8d3 --- /dev/null +++ b/generator/src/templates/nginx/modules/build-info.http.conf.twig @@ -0,0 +1,29 @@ +{% set privateIpListRegex = '~^(?:[ ]*(?:127(?:[.][0-9]{1,3}){3}|10(?:[.][0-9]{1,3}){3}|172[.](?:1[6-9]|2[0-9]|3[01])(?:[.][0-9]{1,3}){2}|192[.]168(?:[.][0-9]{1,3}){2})[ ]*(?:,|$))+$' %} +# Build info (/build.json, /build.php) is served only to requests that did not pass through a public network: +# the client address, every X-Forwarded-For entry and X-Real-IP must be private (127/8, 10/8, 172.16/12, 192.168/16). +# Public traffic in AWS comes from the private address of the load balancer, which appends the public client address +# to X-Forwarded-For. Requests from inside the VPC and from the local docker/sdk gateway carry only private addresses. +geo $spryker_build_info_client_is_private { + default 0; + 127.0.0.0/8 1; + 10.0.0.0/8 1; + 172.16.0.0/12 1; + 192.168.0.0/16 1; +} + +map $http_x_forwarded_for $spryker_build_info_forwarded_for_is_private { + default 0; + "" 1; + "{{ privateIpListRegex | raw }}" 1; +} + +map $http_x_real_ip $spryker_build_info_real_ip_is_private { + default 0; + "" 1; + "{{ privateIpListRegex | raw }}" 1; +} + +map "$spryker_build_info_client_is_private$spryker_build_info_forwarded_for_is_private$spryker_build_info_real_ip_is_private" $spryker_build_info_allowed { + default 0; + "111" 1; +}