Repository navigation
Block web access to Drupal's maintenance scripts - #167
Conversation
…che rebuild, and authorize)
86bf63d to
2d6f802
Compare
turegjorup
left a comment
There was a problem hiding this comment.
Use ^~ prefix locations for the maintenance script blocks. Then the blocks do not depend on their position in the config.
Problem
#163 adds include /etc/nginx/conf.d/server.d/*.conf; at the top of the server block. nginx checks regex locations in config order and uses the first match. Thus, a regex location in a project server.d/ file comes before the regex block in this PR. If that location matches .php, it gets the request, and the block has no effect.
A server-level rewrite in server.d/ (the README example in #163) is safe. nginx selects the location after the rewrite. The problem is a project location ~ ... rule, for example a PHP-FPM block.
Test
I ran nginx:alpine with the config from this PR, the include from #163, and this file in server.d/:
location ~ \.php(/|$) {
return 200 "PROJECT PHP $uri\n";
}| URL | This PR (~ regex) |
With ^~ prefixes |
|---|---|---|
/core/install.php |
200 (project block) | 404 |
/core/install.php/foo |
200 (project block) | 404 |
/update.php/selection |
200 (project block) | 404 |
/core/rebuild.php |
200 (project block) | 404 |
/index.php |
200 | 200 |
Requested change
Replace the regex block with one prefix location for each script, in drupal, drupal-8 and drupal-9:
# Block web access to Drupal's maintenance scripts (update, install, cache
# rebuild, and authorize). Use drush through ssh for these tasks instead.
# "^~" stops nginx from checking regex locations, so rules in server.d/
# cannot override these blocks.
location ^~ /update.php {
return 404;
}
location ^~ /install.php {
return 404;
}
location ^~ /core/install.php {
return 404;
}
location ^~ /core/rebuild.php {
return 404;
}
location ^~ /core/authorize.php {
return 404;
}- nginx selects prefix locations by the longest match, not by position. These blocks win against all regex locations in
server.d/. - A prefix also matches
/core/install.php/foo, so the(/|$)suffix is not necessary. - The Drupal.org guide Securing the installer recommends
location ^~ /core/install.phpfor the same reason.
A project can still override a block with a longer ^~ prefix or an exact match (location = ...) in server.d/. Nobody writes that by accident, so I think that this risk is acceptable.
https://leantime.itkdev.dk/dashboard/home?tab=ticketdetails#/tickets/showTicket/8999