From c17319d61ec7d856839d0be48bfde6d7bef82fb7 Mon Sep 17 00:00:00 2001 From: turegjorup Date: Sun, 29 Nov 2026 13:31:20 +0100 Subject: [PATCH 1/3] fix: send only valid Drupal aggregate names to PHP in nginx --- .../drupal/.docker/templates/default.conf.template | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/templates/drupal/.docker/templates/default.conf.template b/templates/drupal/.docker/templates/default.conf.template index 451bd59..230b791 100644 --- a/templates/drupal/.docker/templates/default.conf.template +++ b/templates/drupal/.docker/templates/default.conf.template @@ -43,6 +43,17 @@ server { return 403; } + # Drupal builds a missing CSS or JS aggregate on each request. Send only + # file names with a valid hash (43 characters) to Drupal. Return 404 for + # other names, for example "css_x.css" in a cache-busting flood. + location ~ "^/sites/[^/]+/files/(css/css_[A-Za-z0-9_-]{43}\.css|js/js_[A-Za-z0-9_-]{43}\.js)$" { + try_files $uri /index.php?$query_string; + } + + location ~ ^/sites/[^/]+/files/(css|js)/ { + try_files $uri =404; + } + # Block access to scripts in site files directory location ~ ^/sites/[^/]+/files/.*\.php$ { deny all; From f3a34cc400542706eb3d516fef9a361676911bee Mon Sep 17 00:00:00 2001 From: turegjorup Date: Sun, 29 Nov 2026 13:31:32 +0100 Subject: [PATCH 2/3] docs: add changelog entry for PR-168 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9295a57..3f92000 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ Changelog", this file is a reverse-chronological list of merged pull requests. ## Open PR's +- [PR-168](https://github.com/itk-dev/devops_itkdev-docker/pull/168) - 2026-11-29 - + Send only valid Drupal aggregate names to PHP. - [PR-135](https://github.com/itk-dev/devops_itkdev-docker/pull/135) - 2026-01-29 - Add Podman support with dynamic machine detection - [PR-126](https://github.com/itk-dev/devops_itkdev-docker/pull/126) - 2026-01-05 - From a435413d74cde5dcde8c00e92daefbf2d9a76c92 Mon Sep 17 00:00:00 2001 From: turegjorup Date: Mon, 30 Nov 2026 13:56:08 +0100 Subject: [PATCH 3/3] fix: harden aggregate location rules and their order --- .../.docker/templates/default.conf.template | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/templates/drupal/.docker/templates/default.conf.template b/templates/drupal/.docker/templates/default.conf.template index 230b791..25c3256 100644 --- a/templates/drupal/.docker/templates/default.conf.template +++ b/templates/drupal/.docker/templates/default.conf.template @@ -43,17 +43,6 @@ server { return 403; } - # Drupal builds a missing CSS or JS aggregate on each request. Send only - # file names with a valid hash (43 characters) to Drupal. Return 404 for - # other names, for example "css_x.css" in a cache-busting flood. - location ~ "^/sites/[^/]+/files/(css/css_[A-Za-z0-9_-]{43}\.css|js/js_[A-Za-z0-9_-]{43}\.js)$" { - try_files $uri /index.php?$query_string; - } - - location ~ ^/sites/[^/]+/files/(css|js)/ { - try_files $uri =404; - } - # Block access to scripts in site files directory location ~ ^/sites/[^/]+/files/.*\.php$ { deny all; @@ -85,6 +74,19 @@ server { return 404; } + # Drupal builds a missing CSS or JS aggregate on each request. Send only + # file names with a valid hash (43 characters) to Drupal. Return 404 for + # other names, for example "css_x.css" in a cache-busting flood. + # Keep these rules after the deny rules above. Nginx uses the first regex + # location that matches. + location ~ "^/sites/[^/]+/files/(css/css_[A-Za-z0-9_-]{43}\.css|js/js_[A-Za-z0-9_-]{43}\.js)$" { + try_files $uri /index.php?$query_string; + } + + location ~* /sites/[^/]+/files/(css|js)/ { + try_files $uri =404; + } + # Block web access to Drupal's maintenance scripts (update, install, cache # rebuild, and authorize). Use drush and composer for these tasks instead. location ^~ /update.php {