diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a21fe4ba..66553ac47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -506,6 +506,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security +* **role:apache_httpd**: The `localhost` vHost refuses the HTML view of the PHP-FPM status page (`/fpm-status?html`), in which any client of the pool can plant script for whoever opens the page ([GHSA-3mg3-cr28-46gc](https://github.com/php/php-src/security/advisories/GHSA-3mg3-cr28-46gc)), while the other views and the `php-fpm-status` check keep working. * **role:acme_sh**: The ACME challenge directory and its `index.html` belong to root instead of the web server user, which only reads them. * **role:monitoring_plugins**: `/var/www/html/localhost/monitoring.php` belongs to root instead of the web server user, which only executes it. * **role:icinga_kubernetes_web, role:icingaweb2_module_\*, role:icingaweb2_theme_linuxfabrik**: The module code below `/usr/share/icingaweb2/modules` belongs to root instead of the web server user, so a compromised web server can no longer change code that the module daemons and `icingacli` run as root. The module configuration below `/etc/icingaweb2/modules` belongs to `root:icingaweb2` as in the Icinga packages; the web server still writes it through the `icingaweb2` group. The Jira and Grafana configurations and the Grafana JWT key are no longer world-readable. diff --git a/extensions/molecule/apache_httpd/verify.yml b/extensions/molecule/apache_httpd/verify.yml index b1d7c3f9c..a6e74fdbe 100644 --- a/extensions/molecule/apache_httpd/verify.yml +++ b/extensions/molecule/apache_httpd/verify.yml @@ -14,6 +14,8 @@ # client address Apache logs for it. # And the LogLevel and the placeholder certificates: by what the running Apache wrote to the journal. # And the logs of the raw and redirect templates: by the lines a request leaves in them. +# And the guard against the HTML view of the PHP-FPM status page: by the status code of requests +# for it. - name: 'Verify apache_httpd serves HTTP/2, basic auth, compression, the Core Rule Set, PHP and the forwarded client where it is configured to' hosts: 'systems_under_test' gather_facts: true @@ -523,3 +525,48 @@ that: - '__molecule__apache_httpd_raw_error_result["stdout"] is search("AH00126: Invalid URI in request|AH10244: invalid URI path")' fail_msg: 'expected AH00126 or AH10244 in raw.example.com-error.log, got "{{ __molecule__apache_httpd_raw_error_result["stdout"] }}"' + + # The localhost vHost refuses the HTML view of the PHP-FPM status page (GHSA-3mg3-cr28-46gc) + # and passes the flags of the other views. No PHP-FPM runs in this scenario, so a request that + # passes ends at the missing pool socket (503) and only a refused one is answered with 403. + # php-fpm decodes the query before it looks for `html`, so the encoded variants have to be + # refused as well. + - name: 'curl http://localhost/fpm-status?' # noqa command-instead-of-module (ansible.builtin.uri cannot send a query as is) + ansible.builtin.command: >- + curl --silent + --output /dev/null + --write-out '%{http_code}' + 'http://localhost/fpm-status{{ item["query"] }}' + register: '__molecule__apache_httpd_fpm_status_result' + changed_when: false + loop: + - query: '' + refused: false + - query: '?json&full' + refused: false + - query: '?openmetrics' + refused: false + - query: '?xml&full' + refused: false + - query: '?full&html' + refused: true + - query: '?%68tml' + refused: true + - query: '?+html' + refused: true + - query: '?html%00' + refused: true + - query: '?json&%zz&html' + refused: true + loop_control: + label: '{{ item["query"] }}' + + - name: 'Assert the localhost vHost refuses the HTML view of the PHP-FPM status page only' + ansible.builtin.assert: + that: '(item["stdout"] == "403") == item["item"]["refused"]' + fail_msg: >- + /fpm-status{{ item["item"]["query"] }} answered {{ item["stdout"] }}, + expected {{ item["item"]["refused"] | ternary("403", "anything but 403") }} + loop: '{{ __molecule__apache_httpd_fpm_status_result["results"] }}' + loop_control: + label: '{{ item["item"]["query"] }}' diff --git a/roles/apache_httpd/README.md b/roles/apache_httpd/README.md index 4448ccc4d..709fd9c25 100644 --- a/roles/apache_httpd/README.md +++ b/roles/apache_httpd/README.md @@ -539,7 +539,7 @@ Types of vHosts: * **localhost**: A hardened, pre-defined VirtualHost just listening on https://localhost, and only accessible from localhost. Due to its naming, it is the first defined vHost. Can be extended by using the `raw` variable. The following URLs are pre-configured and only accessible from localhost: * `/fpm-ping` - PHP-FPM health check of the `www` pool - * `/fpm-status` - PHP-FPM status page of the `www` pool + * `/fpm-status` - PHP-FPM status page of the `www` pool, without its HTML view * `/monitoring.php` - Linuxfabrik monitoring endpoint * `/server-info` - Apache server info (`mod_info` required, disabled by default) * `/server-status` - Apache server status (`mod_status` required) @@ -550,9 +550,14 @@ Types of vHosts: Require local ProxyPass unix:/run/php-fpm/app1.sock|fcgi://localhost/fpm-status + + Require all denied + ``` + The `` block answers every query other than the `full`, `json`, `openmetrics` and `xml` flags with `403`. It keeps out the HTML view (`?html`), which prints request fields that any client of the pool controls unescaped, so they run script in the browser of whoever opens the page ([GHSA-3mg3-cr28-46gc](https://github.com/php/php-src/security/advisories/GHSA-3mg3-cr28-46gc)). The check works on the raw query string, because PHP-FPM decodes the query and also shows the HTML view for `?%68tml`. The `php-fpm-status` check asks for `?json&full` and is not affected. + * **proxy**: A typical hardened reverse proxy vHost. Can be extended by using the `raw` variable. This proxy vHost definition prevents Apache from functioning as a forward proxy server (inside > out). Forward to the backend with `ProxyPass` in `raw`, not with `RewriteRule ... [proxy]`: mod_rewrite passes the path on decoded, so a `?` in a path segment, such as in a file name, reaches the backend as the start of the query string. See the [nextcloud](https://github.com/Linuxfabrik/lfops/tree/main/roles/nextcloud) role for an example. * **raw**: If none of the above vHost templates fit, use the `raw` one and define everything except ``, `` and the logs completely from scratch. Like every other template it logs to its own error and access log, so requests to a raw vHost, for example a catch-all for unknown host names, reach fail2ban. * **redirect**: A vHost that redirects every request to `https://` on the same host, keeping the requested hostname and path. Set `virtualhost_port: 80` to redirect the plain HTTP port. Requests below `/.well-known/acme-challenge/` are excluded, so ACME/Let's Encrypt HTTP-01 challenges keep working. The `raw` variable replaces the redirect rule instead of extending it. diff --git a/roles/apache_httpd/templates/etc/httpd/sites-available/localhost.conf.j2 b/roles/apache_httpd/templates/etc/httpd/sites-available/localhost.conf.j2 index 4e6b1277e..fdf57871d 100644 --- a/roles/apache_httpd/templates/etc/httpd/sites-available/localhost.conf.j2 +++ b/roles/apache_httpd/templates/etc/httpd/sites-available/localhost.conf.j2 @@ -1,5 +1,5 @@ # {{ ansible_managed }} -# 2026111801 +# 2026111901 # Local vHost {% if item['by_role'] | d() %} # Generated by Ansible role: {{ item['by_role'] }} @@ -122,6 +122,15 @@ Require local ProxyPass unix:{{ __apache_httpd__php_socket }}|fcgi://localhost/fpm-status + # Only the flags for the text, JSON, XML and OpenMetrics output pass. The HTML + # view (`html`) prints request fields that any client of the pool controls + # unescaped, so they run script in the browser of whoever opens the page + # (CVE-2026-129292, GHSA-3mg3-cr28-46gc). An allowlist on the raw query string, + # because php-fpm decodes the query before it looks for `html`, so `%68tml` + # selects it as well. Verified with httpd 2.4.37 and 2.4.62 on Rocky 8 and 9. + + Require all denied + Alias /fpm-ping /dev/null diff --git a/roles/php/README.md b/roles/php/README.md index 7e961a9ea..c543aaed1 100644 --- a/roles/php/README.md +++ b/roles/php/README.md @@ -45,7 +45,7 @@ This role never exposes to the world that PHP is installed on the server, no mat * The role orders Apache after PHP-FPM at boot with the drop-in `/etc/systemd/system/httpd.service.d/z00-php.conf` (`apache2.service.d` on Debian). The RHEL package only makes httpd pull in php-fpm and Debian does not even that, so both otherwise start side by side, and the first requests after a reboot fail with `AH02454: FCGI: attempt to connect to Unix domain socket ... failed` until the PHP-FPM socket exists. On a host without Apache the ordering is ignored. It takes effect at the next boot, without a restart. * The pool sets `env[PATH]`, which upstream leaves unset: with `clear_env` at its default the worker environment is empty, so `getenv("PATH")` returns nothing, which trips applications that shell out and fails Nextcloud's "PHP getenv" setup check. * Every pool gets its own WSDL cache directory below `/var/lib/php/wsdlcache`, owned like its session directory. The SOAP extension caches parsed WSDL files there, so a `SoapClient` does not refetch and reparse the service description on every request. PHP's own default is `/tmp`, which on RedHat means the php-fpm unit's `PrivateTmp` namespace and therefore a cache thrown away on every restart, and on Debian the shared `/tmp`. Only relevant to applications using `SoapClient`: without the `soap` extension installed the setting is inert, and `ini_get('soap.wsdl_cache_dir')` returns an empty string. -* Every pool answers on the same two FPM-internal endpoints, `/fpm-status` (the status page) and `/fpm-ping` (a liveness check returning `pong`). Which pool answers is decided by the socket the request arrives on, not by the path, so a second pool is published by giving it its own `Location` pointing at that pool's socket while keeping `/fpm-status` as the path sent to FPM. The `localhost` vHost of the [apache_httpd](https://github.com/Linuxfabrik/lfops/tree/main/roles/apache_httpd) role does this for the `www` pool, which is what the `php-fpm-status` and `php-fpm-ping` [Monitoring Plugins](https://github.com/Linuxfabrik/monitoring-plugins) check by default; `php-fpm-status` accepts `--url` several times for the additional pools. Both endpoints are reachable for anyone who can reach the pool socket, so take care with a vHost that forwards its whole URI space to a pool, or with a reverse proxy that passes unknown paths through. Set `pm_status_path` and / or `ping_path` to an empty string to turn them off for a pool. +* Every pool answers on the same two FPM-internal endpoints, `/fpm-status` (the status page) and `/fpm-ping` (a liveness check returning `pong`). Which pool answers is decided by the socket the request arrives on, not by the path, so a second pool is published by giving it its own `Location` pointing at that pool's socket while keeping `/fpm-status` as the path sent to FPM. The `localhost` vHost of the [apache_httpd](https://github.com/Linuxfabrik/lfops/tree/main/roles/apache_httpd) role does this for the `www` pool, which is what the `php-fpm-status` and `php-fpm-ping` [Monitoring Plugins](https://github.com/Linuxfabrik/monitoring-plugins) check by default; `php-fpm-status` accepts `--url` several times for the additional pools. Both endpoints are reachable for anyone who can reach the pool socket, so take care with a vHost that forwards its whole URI space to a pool, or with a reverse proxy that passes unknown paths through. The `localhost` vHost refuses the HTML view of the status page, which prints request fields unescaped ([GHSA-3mg3-cr28-46gc](https://github.com/php/php-src/security/advisories/GHSA-3mg3-cr28-46gc)); a `Location` of your own needs the same `` block, see the apache_httpd README. Set `pm_status_path` and / or `ping_path` to an empty string to turn them off for a pool. ## Known Limitations