Skip to content

Commit 3469b02

Browse files
authored
UN-3124 [FIX] : Add security headers and HTTP method restrictions to nginx (#1726)
* feat: Add security headers and HTTP method restrictions to nginx - Add X-Content-Type-Options header to prevent MIME sniffing - Add X-Frame-Options header to prevent clickjacking - Add X-XSS-Protection header for XSS protection - Add Referrer-Policy header for referrer control - Disable TRACE and TRACK HTTP methods - Limit allowed HTTP methods to GET, HEAD, POST in location block * fix: Remove deprecated X-XSS-Protection header X-XSS-Protection is deprecated and ignored by modern browsers. Chrome removed support in 2019. Content-Security-Policy (CSP) is the recommended replacement for XSS protection. * fix: Limit HTTP methods to GET and HEAD only Static file serving only requires GET and HEAD methods. POST is not needed as API calls go directly to the backend.
1 parent 8ddb575 commit 3469b02

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

frontend/nginx.conf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,27 @@ http {
4242
root /usr/share/nginx/html;
4343
include /etc/nginx/mime.types;
4444

45+
# Security headers
46+
add_header X-Content-Type-Options "nosniff" always;
47+
add_header X-Frame-Options "SAMEORIGIN" always;
48+
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
49+
50+
# Disable TRACE and TRACK methods
51+
if ($request_method ~ ^(TRACE|TRACK)$) {
52+
return 405;
53+
}
54+
4555
# If a react app URI is directly accessed we will get 404
4656
# since there will be no file representing that path.
4757
# Below config will load index.html file in such case and
4858
# browser will load the proper path using JS.
4959
location / {
60+
# Limit allowed HTTP methods
61+
limit_except GET HEAD {
62+
deny all;
63+
}
5064
try_files $uri /index.html;
5165
}
66+
5267
}
5368
}

0 commit comments

Comments
 (0)