From c5ceee67fa3eaaa7b0433a78abeb77e323a78680 Mon Sep 17 00:00:00 2001 From: YvesCesar Date: Sat, 14 Nov 2026 10:05:41 -0400 Subject: [PATCH] fix: harden the wordpress nginx configuration Signed-off-by: YvesCesar --- .docker/wordpress-nginx/default.conf | 65 +++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/.docker/wordpress-nginx/default.conf b/.docker/wordpress-nginx/default.conf index 903684f..d13858b 100644 --- a/.docker/wordpress-nginx/default.conf +++ b/.docker/wordpress-nginx/default.conf @@ -1,9 +1,16 @@ +map $uri $is_php_entry_point { + default 0; + ~^/(index|wp-login|wp-cron|wp-comments-post|wp-signup|wp-activate|wp-trackback|wp-links-opml)\.php$ 1; + ~^/wp-admin/((network|user)/)?[^/]+\.php$ 1; + /wp-includes/js/tinymce/wp-tinymce.php 1; +} + server { listen 80; server_name nginx localhost; index index.php index.html index.htm; root /var/www/html; - client_max_body_size 0; + client_max_body_size 10m; server_tokens off; add_header X-Frame-Options "SAMEORIGIN" always; add_header X-XSS-Protection "1; mode=block" always; @@ -22,11 +29,59 @@ server { try_files $uri $uri/ /index.php$is_args$args; } - location ~* ^/wp-content/.*/vendor(-bin)?/.*\.php$ { + location = /xmlrpc.php { + deny all; + } + + location ~ /\.(?!well-known/) { + deny all; + } + + location ~ ~$ { + deny all; + } + + location ~* \.(sql|sqlite|bak|old|orig|save|swp|swo|log|sh|dist|lock|tar|tgz|gz|bz2|xz|7z|rar|wpress|env|ini|neon|ya?ml|md)$ { + deny all; + } + + location ~* /(composer\.(json|lock)|package(-lock)?\.json|phpunit[^/]*\.xml(\.dist)?)$ { + deny all; + } + + location ~* ^/wp-content/(debug\.log|updraft|ai1wm-backups|aiowps_backups|backups?[^/]*|upgrade|upgrade-temp-backup|cache|logs)(/|$) { + deny all; + } + + location ~* ^/wp-content/uploads/(wc-logs|woocommerce_uploads|debug-log-manager)/ { deny all; } - location ~ \.php$ { + location ~* "^/wp-content/uploads/[0-9]{4}/[0-9]{2}/[^/]+\.zip$" { + try_files $uri =404; + } + + location ~* \.zip$ { + deny all; + } + + location ~* ^/wp-content/(plugins|themes)/[^/]+/(tests|stubs|node_modules|vendor-bin)/ { + deny all; + } + + location ~* ^/wp-content/(.*/)?vendor/.+\.(css|js|map|gif|ico|jpe?g|png|svg|webp|eot|ttf|woff2?)$ { + expires max; + log_not_found off; + } + + location ~* ^/wp-content/(.*/)?vendor(-bin)?/ { + deny all; + } + + location ~* \.(php[0-9]?|phtml|phar|pht)(/|$) { + if ($is_php_entry_point = 0) { + return 404; + } try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass wordpress:9000; @@ -36,10 +91,6 @@ server { fastcgi_param PATH_INFO $fastcgi_path_info; } - location ~ /\.(ht|git) { - deny all; - } - location = /favicon.ico { log_not_found off; access_log off;