Skip to content

Commit

Permalink
DIGITAL-000: Fix NGINX routing to styles path.
Browse files Browse the repository at this point in the history
  • Loading branch information
casey-rapnicki-bixal committed Jan 2, 2025
1 parent 972f5f9 commit 506e571
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 12 deletions.
1 change: 1 addition & 0 deletions terraform/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ applications/caddy-proxy/*.acl
applications/nginx-waf/modules/*
applications/nginx-waf/nginx/snippets/*.conf
!applications/nginx-waf/nginx/snippets/owasp*.conf
!applications/nginx-waf/nginx/snippets/x*.conf
!applications/nginx-waf/packages/*
115 changes: 103 additions & 12 deletions terraform/applications/nginx-waf/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ server {
break;
}

location @rewrite {
location ^~ /s3/files {
set $port 8883;
proxy_redirect off;
proxy_connect_timeout 300;
Expand All @@ -47,14 +47,7 @@ server {
proxy_set_header Host $cf_forwarded_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
error_page 403 = @fourohfour_english;
}

# Required by Drupal/S3FS Module
# Proxy request for image styles to CMS
# Harvested from https://github.com/usagov/vote-gov-tf/blob/main/applications/nginx-waf/nginx/conf.d/default.conf#L214C3-L219C4
location ^~ /s3/files {
try_files $uri @rewrite;
error_page 403 =404 @fourohfour_english;
}

location / {
Expand All @@ -66,7 +59,7 @@ server {
proxy_set_header Host $cf_forwarded_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
error_page 403 = @fourohfour_english;
error_page 403 =404 @fourohfour_english;
}
}

Expand Down Expand Up @@ -106,9 +99,107 @@ server {
access_log off;

default_type text/plain;
return 403 'Forbidden by USAGov';
return 403 'Forbidden by Digital.gov';
break;
# redirect to homepage usa.gov
}

include nginx/snippets/x-security.conf;

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location ~ \..*/.*\.php$ {
return 403;
}

location ~ ^/sites/.*/private/ {
return 403;
}

# Block access to scripts in site files directory
location ~ ^/sites/[^/]+/files/.*\.php$ {
deny all;
}

# Allow "Well-Known URIs" as per RFC 5785
location ~* ^/.well-known/ {
allow all;
}

# Block access to "hidden" files and directories whose names begin with a
# period. This includes directories used by version control systems such
# as Subversion or Git to store control files.
location ~ (^|/)\. {
return 403;
}

# Protect files and directories from prying eyes.
location ~* \.(?:engine|inc|install|make|module|profile|po|sh|.*sql|theme|twig|tpl(?:\.php)?|xtmpl|yml)(?:~|\.sw[op]|\.bak|\.orig|\.save)?(?:$|/) {
deny all;
return 404;
}

location ~* ^/(\.(?!well-known/).*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock))(?:/|$)|^/#.*#(?:/|$)|\.php(?:~|\.sw[op]|\.bak|\.orig|\.save)(?:/|$) {
deny all;
return 404;
}

# Add patterns here to block files located anywhere in the site.
location ~* /README\.md {
deny all;
return 404;
}

location ~* ^/(update\.php|test\.txt|README\.md|LICENSE\.txt|install\.php|INSTALL(\..*?)?\.txt)(?:/|$) {
deny all;
return 404;
}

# Don't allow access to generated php files.
location = /sites/default/files/php {
deny all;
return 404;
}

location ^~ /sites/default/files/php/ {
deny all;
return 404;
}

location ^~ /vendor/ {
deny all;
return 404;
}

location ~* /autoload.php {
deny all;
return 404;
}

#Dont allow direct access to *.(css|js).gz files.
location ~ /sites/default/files/(css/.*\.css|js/.*\.js)\.gz(?:/|$) {
deny all;
return 404;
}

location @rewrite {
rewrite ^ /index.php;
include nginx/snippets/proxy-to-app.conf;
}

#Required by Drupal/S3FS Module
#Proxy request for image styles to CMS
location ~ /s3/files/styles/ {
try_files $uri @rewrite;
include nginx/snippets/proxy-to-app.conf;
}

location / {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;

0 comments on commit 506e571

Please sign in to comment.