Skip to content

Commit 6c8c8ca

Browse files
committed
Add security measures to block PHP execution in storage directory (#641)
Implemented restrictions across Apache, NGINX, and FrankenPHP configurations to prevent the execution of PHP files in the /storage directory, addressing potential vulnerabilities related to arbitrary file uploads (GHSA-29cq-5w36-x7w3).
1 parent bc7b365 commit 6c8c8ca

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

src/variations/fpm-apache/etc/apache2/conf-available/security.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains
5555
# | File Access Restrictions |
5656
# ------------------------------------------------------------------------------
5757

58+
# Block PHP execution in storage directory to prevent uploaded malicious PHP files from running
59+
# Reference: Livewire arbitrary file upload (GHSA-29cq-5w36-x7w3)
60+
<LocationMatch "^/storage/.*\.php$">
61+
Require all denied
62+
</LocationMatch>
63+
5864
# Block access to all hidden files and directories (dotfiles)
5965
# EXCEPT for the "/.well-known/" directory which is required by RFC 8615
6066
# for ACME challenges, security.txt, and other standardized endpoints.

src/variations/fpm-nginx/etc/nginx/site-opts.d/http.conf.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ location / {
3030
try_files $uri $uri/ /index.php?$query_string;
3131
}
3232

33+
# Block PHP execution in storage directory to prevent uploaded malicious PHP files from running
34+
# Reference: Livewire arbitrary file upload (GHSA-29cq-5w36-x7w3)
35+
location ~* ^/storage/.*\.php$ {
36+
deny all;
37+
}
38+
3339
# Pass "*.php" files to PHP-FPM
3440
location ~ \.php$ {
3541
fastcgi_pass 127.0.0.1:9000;

src/variations/fpm-nginx/etc/nginx/site-opts.d/https.conf.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ location / {
3636
try_files $uri $uri/ /index.php?$query_string;
3737
}
3838

39+
# Block PHP execution in storage directory to prevent uploaded malicious PHP files from running
40+
# Reference: Livewire arbitrary file upload (GHSA-29cq-5w36-x7w3)
41+
location ~* ^/storage/.*\.php$ {
42+
deny all;
43+
}
44+
3945
# Pass "*.php" files to PHP-FPM
4046
location ~ \.php$ {
4147
fastcgi_pass 127.0.0.1:9000;

src/variations/frankenphp/etc/frankenphp/Caddyfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ fd00::/8 \
138138
# RFC 8615 - Well-Known URIs
139139
# https://www.rfc-editor.org/rfc/rfc8615
140140

141+
# Block PHP execution in storage directory to prevent uploaded malicious PHP files from running
142+
# Reference: Livewire arbitrary file upload (GHSA-29cq-5w36-x7w3)
143+
@storage-php path_regexp ^/storage/.*\.php$
144+
respond @storage-php 403
145+
141146
# Block access to files that may expose sensitive information
142147
@rejected {
143148
path *.bak *.conf *.config *.dist *.inc *.ini *.log *.sh *.sql *.swp *.swo *~ */.*

0 commit comments

Comments
 (0)