From 600119cdd1982ef8d782efbc68720039f88fe18d Mon Sep 17 00:00:00 2001 From: ayurishchev Date: Wed, 7 Oct 2026 13:07:16 +0300 Subject: [PATCH] UI review, stage 2: nginx security headers, gzip, cache; npm ci; no v-html default.conf.template: X-Content-Type-Options, X-Frame-Options, Referrer-Policy, CSP, gzip, immutable cache for /assets/, no-cache for index.html and config.json, server_tokens off, drop proxy_pass_header. Dockerfile uses npm ci, .dockerignore added (nginx stays root: the image entrypoint and port 80 need it). Status badge is a component instead of v-html. Co-Authored-By: Claude Sonnet 5.5 --- APP_UI/.dockerignore | 6 +++ APP_UI/Dockerfile | 5 ++- APP_UI/default.conf.template | 37 ++++++++++++++++++- APP_UI/src/components/ProfileDetailsModal.vue | 11 +----- APP_UI/src/components/StatusBadge.vue | 27 ++++++++++++++ APP_UI/src/views/Certificates.vue | 22 ++--------- 6 files changed, 76 insertions(+), 32 deletions(-) create mode 100644 APP_UI/.dockerignore create mode 100644 APP_UI/src/components/StatusBadge.vue diff --git a/APP_UI/.dockerignore b/APP_UI/.dockerignore new file mode 100644 index 0000000..bbedb18 --- /dev/null +++ b/APP_UI/.dockerignore @@ -0,0 +1,6 @@ +node_modules +dist +.vscode +.git +*.bak +*.log diff --git a/APP_UI/Dockerfile b/APP_UI/Dockerfile index a52aedb..d6e3856 100644 --- a/APP_UI/Dockerfile +++ b/APP_UI/Dockerfile @@ -2,14 +2,15 @@ FROM node:20-alpine AS build-stage WORKDIR /app COPY package*.json ./ -RUN npm install +RUN npm ci COPY . . RUN npm run build # Stage 2: Serve +# nginx runs as root here: the image entrypoint renders the template into /etc/nginx/conf.d and port 80 +# is published by docker-compose. An unprivileged variant would change the port and the image. FROM nginx:alpine COPY --from=build-stage /app/dist /usr/share/nginx/html COPY default.conf.template /etc/nginx/templates/default.conf.template EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] - diff --git a/APP_UI/default.conf.template b/APP_UI/default.conf.template index 196e76d..d6c5513 100644 --- a/APP_UI/default.conf.template +++ b/APP_UI/default.conf.template @@ -1,21 +1,54 @@ server { listen 80; server_name localhost; + server_tokens off; root /usr/share/nginx/html; index index.html; + # Security headers. add_header in a location replaces the ones inherited from the server block, + # so the /assets/ location below repeats them. CSP: the bundle is served from this origin only; + # style-src 'unsafe-inline' is needed by Bootstrap and Chart.js (inline style attributes); + # connect-src 'self' means config.json must point to proxied paths (the defaults /api/v1 and /profiles-api). + add_header X-Content-Type-Options "nosniff" always; + add_header X-Frame-Options "DENY" always; + add_header Referrer-Policy "no-referrer" 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'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" always; + + gzip on; + gzip_vary on; + gzip_min_length 1024; + gzip_types text/plain text/css text/javascript application/javascript application/json image/svg+xml; + location / { try_files $uri $uri/ /index.html; } + # Hashed build files never change under the same name + location /assets/ { + try_files $uri =404; + add_header Cache-Control "public, max-age=31536000, immutable"; + add_header X-Content-Type-Options "nosniff" always; + add_header X-Frame-Options "DENY" always; + add_header Referrer-Policy "no-referrer" 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'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" always; + } + + # The entry page and the runtime configuration must be revalidated after an update + # (expires -1 sends "Cache-Control: no-cache" and keeps the server-level headers) + location = /index.html { + expires -1; + } + location = /config.json { + expires -1; + } + # Модуль 1: Мониторинг (Flask, порт 5001) location /api/ { proxy_pass http://${OVP_API_HOST}:${OVP_API_PORT}; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_pass_header Authorization; } # Модуль 2: Управление профилями (FastAPI, порт 8000) @@ -34,4 +67,4 @@ server { location = /50x.html { root /usr/share/nginx/html; } -} \ No newline at end of file +} diff --git a/APP_UI/src/components/ProfileDetailsModal.vue b/APP_UI/src/components/ProfileDetailsModal.vue index 334d261..dbee46c 100644 --- a/APP_UI/src/components/ProfileDetailsModal.vue +++ b/APP_UI/src/components/ProfileDetailsModal.vue @@ -3,7 +3,7 @@