Repository navigation
Send only valid Drupal aggregate names to PHP - #168
Merged
Merged
Conversation
jekuaitk
reviewed
Nov 30, 2026
| try_files $uri /index.php?$query_string; | ||
| } | ||
|
|
||
| location ~ ^/sites/[^/]+/files/(css|js)/ { |
Contributor
There was a problem hiding this comment.
Could we make this case-insensitive and not anchored to the start of the path?
Drupal also sends these to the aggregate controller, so they still reach Drupal with the current rule:
/da/sites/default/files/css/css_x.css(language prefix is stripped before routing)/sites/default/files/CSS/css_x.css(route matching ignores case)
Suggested change
| location ~ ^/sites/[^/]+/files/(css|js)/ { | |
| location ~* /sites/[^/]+/files/(css|js)/ { |
Contributor
Author
There was a problem hiding this comment.
Done in a435413. I applied the suggestion.
I also moved both aggregate blocks below the deny rules. Before, a file such as files/css/x.php or files/css/.htaccess matched the aggregate block first, and nginx sent it as plain text.
I tested the old and the new config in nginx/nginx-unprivileged:alpine:
| Request | Old | New |
|---|---|---|
/da/sites/default/files/css/css_x.css |
502 (to Drupal) | 404 |
/sites/default/files/CSS/css_x.css |
502 (to Drupal) | 404 |
/sites/default/files/css/x.php |
200 | 403 |
/sites/default/files/css/.htaccess |
200 | 403 |
| Aggregate with a valid hash, not on disk | 502 (to Drupal) | 502 (to Drupal) |
| Aggregate with a valid hash, on disk | 200 | 200 |
jekuaitk
approved these changes
Nov 30, 2026
This was referenced Nov 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make nginx return 404 for CSS and JS aggregate requests with a fake file name, so these requests do not reach Drupal.
Changes
templates/drupal/.docker/templates/default.conf.template(also used bydrupal-10anddrupal-11through symlinks):css_<43 characters>.cssorjs_<43 characters>.js.sites/*/files/css/andsites/*/files/js/.Why
Since Drupal 10.1, Drupal builds a missing CSS or JS aggregate on request (
AssetControllerBase). Theincludequery parameter gives the list of libraries. If the hash in the file name is not correct, Drupal does not write the file to disk. It returns the aggregate withCache-Control: private, no-store. Thus each request with a fake name starts Drupal and builds the aggregate again.On dokk1.dk, a scanner sent approximately 7,800 requests in 3 hours to
/sites/default/files/css/css_x.css?theme=claro&include=…. Together with the requests to the maintenance scripts that #167 blocks, this causedDatabaseConnectionRefusedException: SQLSTATE[HY000] [2002] Address not availableerrors, 500 responses and Uptime Kuma alerts.The hash is
Crypt::hmacBase64()of SHA-256, so a valid name has 43 base64url characters. This rule does not stop a request with a fake 43-character hash. It stops the simple flood. Use a rate limit in Traefik for full protection.Tested on dokk1 with a copy of the production database:
css_x.css: nginx returns 404, and the request does not reach PHP.nginx -tpasses for the template.The
drupal-8anddrupal-9templates do not have this change. Drupal 8 and 9 do not build aggregates on request.