V 1.4.0 Komplette Absicherung mit Hilfe von Claude
This commit is contained in:
@@ -1,41 +1,130 @@
|
||||
# Nginx-Konfiguration fuer das Frontend (Container).
|
||||
# TLS wird von Traefik vorne dran terminiert; dieser Server lauscht nur auf HTTP intern.
|
||||
|
||||
# Nginx-Version aus Headern und Fehlerseiten raus
|
||||
server_tokens off;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Docker DNS resolver für dynamische Service-Auflösung
|
||||
# Body-Limit (Frontend braucht keine grossen POSTs)
|
||||
client_max_body_size 1m;
|
||||
|
||||
# Docker DNS resolver fuer dynamische Service-Aufloesung
|
||||
resolver 127.0.0.11 valid=30s;
|
||||
resolver_timeout 5s;
|
||||
|
||||
# Gzip compression
|
||||
# Gzip
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/json;
|
||||
gzip_types
|
||||
text/plain
|
||||
text/css
|
||||
text/xml
|
||||
text/javascript
|
||||
application/x-javascript
|
||||
application/xml+rss
|
||||
application/json;
|
||||
|
||||
# API proxy (wird im Docker-Compose-Netzwerk aufgelöst)
|
||||
# ----------------------------------------------------------------- #
|
||||
# Security-Header — gelten fuer alle Antworten dieses Servers.
|
||||
# 'always' sorgt dafuer, dass sie auch bei 4xx/5xx ausgeliefert werden.
|
||||
# ----------------------------------------------------------------- #
|
||||
|
||||
# HSTS: ein Jahr, inkl. Subdomains. Wenn die Domain noch nicht zu 100%
|
||||
# auf HTTPS laeuft, kann der Wert auf "max-age=300" reduziert werden,
|
||||
# bis sicher ist, dass nichts mehr ueber HTTP geht. preload weglassen,
|
||||
# solange die Domain nicht in der Preload-Liste eingetragen werden soll.
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
|
||||
# MIME-Sniffing aus
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
|
||||
# Clickjacking-Schutz: keine Einbettung als iframe
|
||||
|
||||
# Referrer nur an gleiche Origin senden
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
|
||||
# Browser-APIs deaktivieren, die das Frontend nicht benoetigt
|
||||
add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=(), magnetometer=(), gyroscope=(), accelerometer=()" always;
|
||||
|
||||
# Content Security Policy — strict, keine externen Quellen
|
||||
# 'unsafe-inline' fuer style-src ist noetig, weil Highcharts inline-styles
|
||||
# fuer dynamische Diagramme setzt. script-src bleibt strikt.
|
||||
# TODO: http://test.sternwarte-welzheim.de entfernen, sobald der Test-Server
|
||||
# auf HTTPS umgestellt ist. Drei Stellen: server-Block + zwei locations.
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; frame-ancestors 'self' https://sternwarte-welzheim.de https://www.sternwarte-welzheim.de https://test.sternwarte-welzheim.de http://test.sternwarte-welzheim.de; base-uri 'self'; form-action 'self'; object-src 'none'" always;
|
||||
|
||||
# ----------------------------------------------------------------- #
|
||||
# API-Proxy
|
||||
# ----------------------------------------------------------------- #
|
||||
location /api/ {
|
||||
set $upstream_api api:8000;
|
||||
proxy_pass http://$upstream_api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
|
||||
# Standard-Header
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# Timeouts: lieber sichtbar fehlschlagen als ewig haengen
|
||||
proxy_connect_timeout 5s;
|
||||
proxy_send_timeout 15s;
|
||||
proxy_read_timeout 15s;
|
||||
|
||||
# Wenn das Upstream tot ist, sofort 502 statt Retry-Loops
|
||||
proxy_next_upstream off;
|
||||
|
||||
# WebSockets/Upgrade-Pfad behalten, falls spaeter noch gebraucht
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $http_connection;
|
||||
}
|
||||
|
||||
# Frontend routes
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# Cache static assets
|
||||
# ----------------------------------------------------------------- #
|
||||
# Statische Assets — lange Cache-Zeit, da mit Hash im Dateinamen
|
||||
# ----------------------------------------------------------------- #
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
add_header Cache-Control "public, immutable" always;
|
||||
|
||||
# nginx-Quirk: sobald ein add_header in einem location-Block steht,
|
||||
# werden ALLE add_header der server-Ebene ignoriert. Daher hier
|
||||
# alle Security-Header noch einmal explizit.
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=(), magnetometer=(), gyroscope=(), accelerometer=()" always;
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; frame-ancestors 'self' https://sternwarte-welzheim.de https://www.sternwarte-welzheim.de https://test.sternwarte-welzheim.de http://test.sternwarte-welzheim.de; base-uri 'self'; form-action 'self'; object-src 'none'" always;
|
||||
}
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------- #
|
||||
# Frontend-Routing (SPA)
|
||||
# ----------------------------------------------------------------- #
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
|
||||
# index.html selbst nicht aggressiv cachen, sonst sehen Nutzer
|
||||
# nach einem Deploy alte Asset-Hashes
|
||||
add_header Cache-Control "no-cache" always;
|
||||
|
||||
# Security-Header hier nochmal explizit (nginx-Quirk, s.o.)
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=(), magnetometer=(), gyroscope=(), accelerometer=()" always;
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; frame-ancestors 'self' https://sternwarte-welzheim.de https://www.sternwarte-welzheim.de https://test.sternwarte-welzheim.de http://test.sternwarte-welzheim.de; base-uri 'self'; form-action 'self'; object-src 'none'" always;
|
||||
}
|
||||
|
||||
# Versteckte/Punktdateien blocken (z.B. .env, .git versehentlich im Build)
|
||||
location ~ /\. {
|
||||
deny all;
|
||||
access_log off;
|
||||
log_not_found off;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user