Skip to content

Commit 98d8166

Browse files
committed
feat: implement centralized security headers and optimize SEO metadata and caching configuration
1 parent 6d1b231 commit 98d8166

5 files changed

Lines changed: 18 additions & 17 deletions

File tree

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ services:
3333
- "443:443"
3434
volumes:
3535
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
36+
- ./nginx/security_headers.inc:/etc/nginx/security_headers.inc:ro
3637
- ./static:/opt/infrascan/static:ro
3738
- ./certbot/conf:/etc/letsencrypt:ro
3839
- ./certbot/www:/var/www/certbot:ro

nginx/nginx.conf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ server {
2222
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
2323

2424
# Security headers for SEO
25-
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
26-
add_header X-Content-Type-Options "nosniff" always;
27-
add_header X-Frame-Options "SAMEORIGIN" always;
28-
add_header X-XSS-Protection "1; mode=block" always;
29-
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
25+
include /etc/nginx/security_headers.inc;
3026

3127
client_max_body_size 10M;
3228

@@ -41,28 +37,32 @@ server {
4137
proxy_send_timeout 600s;
4238

4339
# Cache headers for HTML (no-cache to get fresh content, but browser can revalidate)
44-
add_header Cache-Control "public, max-age=3600" always;
40+
add_header Cache-Control "no-cache" always;
41+
include /etc/nginx/security_headers.inc;
4542
}
4643

4744
location /static/ {
4845
alias /opt/infrascan/static/;
4946
# Cache static assets for 1 year
5047
expires 365d;
51-
add_header Cache-Control "public, immutable" always;
48+
add_header Cache-Control "public, max-age=31536000, immutable" always;
49+
include /etc/nginx/security_headers.inc;
5250
}
5351

5452
location = /sitemap.xml {
5553
alias /opt/infrascan/static/sitemap.xml;
5654
# Cache sitemap for 24 hours
5755
add_header Cache-Control "public, max-age=86400" always;
5856
add_header Content-Type "application/xml; charset=utf-8" always;
57+
include /etc/nginx/security_headers.inc;
5958
}
6059

6160
location = /robots.txt {
6261
alias /opt/infrascan/static/robots.txt;
6362
# Cache robots.txt for 24 hours
6463
add_header Cache-Control "public, max-age=86400" always;
6564
add_header Content-Type "text/plain; charset=utf-8" always;
65+
include /etc/nginx/security_headers.inc;
6666
}
6767

6868
# Error pages

nginx/security_headers.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
2+
add_header X-Content-Type-Options "nosniff" always;
3+
add_header X-Frame-Options "SAMEORIGIN" always;
4+
add_header X-XSS-Protection "1; mode=block" always;
5+
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' https://www.googletagmanager.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https://img.shields.io https://www.googletagmanager.com https://www.google-analytics.com; connect-src 'self' https://www.google-analytics.com; frame-ancestors 'self'; object-src 'none';" always;
6+
add_header Referrer-Policy "strict-origin-when-cross-origin" always;

static/robots.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,5 @@ User-agent: *
22
Allow: /
33
Allow: /api/
44

5-
# Block any malicious bots
6-
User-agent: AhrefsBot
7-
Disallow: /
5+
Sitemap: https://infrascan.soldevelo.com/sitemap.xml
86

9-
User-agent: SemrushBot
10-
Disallow: /
11-
12-
User-agent: DotBot
13-
Disallow: /

templates/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
<meta property="og:title" content="InfraScan - Free Infrastructure as Code Security Scanner">
1818
<meta property="og:description"
1919
content="Scan Infrastructure as Code for security vulnerabilities and cost optimization. Supports Terraform, CloudFormation, Kubernetes, and more.">
20+
<meta property="og:image" content="{{ site_domain }}{{ url_for('static', filename='images/logo_transparent.png') }}">
2021

2122
<!-- Twitter -->
2223
<meta property="twitter:card" content="summary">
2324
<meta property="twitter:url" content="{{ site_domain }}/">
2425
<meta property="twitter:title" content="InfraScan - Free Infrastructure as Code Security Scanner">
2526
<meta property="twitter:description"
2627
content="Scan Infrastructure as Code for security vulnerabilities and cost optimization. Supports Terraform, CloudFormation, Kubernetes, and more.">
28+
<meta property="twitter:image" content="{{ site_domain }}{{ url_for('static', filename='images/logo_transparent.png') }}">
2729

2830
<!-- Canonical -->
2931
<link rel="canonical" href="{{ site_domain }}/">
@@ -72,10 +74,9 @@
7274
<link rel="preconnect" href="https://fonts.googleapis.com">
7375
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
7476
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
75-
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}?v={{ static_version }}">
76-
7777
<!-- Preload critical resources -->
7878
<link rel="preload" as="style" href="{{ url_for('static', filename='style.css') }}?v={{ static_version }}">
79+
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}?v={{ static_version }}">
7980
</head>
8081

8182
<body>

0 commit comments

Comments
 (0)