web: cabeceras de proxy no falsificables, /api prioritario y cabeceras de seguridad
X-Forwarded-For se ponia con $proxy_add_x_forwarded_for, que APENDE lo que mande el cliente, y el API lee la primera entrada — asi que cualquiera elegia la IP que quedaba registrada contra el en el activity log. CF-Connecting-IP no la tocaba nadie y es la que el API mira primero. Ahora se sobrescribe con $remote_addr y la de Cloudflare se descarta salvo que pongas CF_CONNECTING_IP=$http_cf_connecting_ip, que solo es correcto con Cloudflare de verdad delante. .env.example afirmaba que el stack venia correcto de fabrica; no era cierto. location /api/ pasa a ^~ para que gane a los location con regex: sin eso una ruta como /api/algo.json la atraparia el bloque \.(js|css|json|html)$ y se buscaria en disco en vez de proxearse. Hoy no rompe nada, manana si. Y cuatro cabeceras de seguridad, repetidas en los dos location con regex porque add_header dentro de un location reemplaza los heredados en vez de sumarse. Sin HSTS ni CSP completa a proposito: eso sigue siendo del reverse proxy. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e326f1b1cb
commit
ec3dc8ba69
4 files changed
+61
-9
No files matched your search
@@ -38,6 +38,11 @@ COPY --from=build /app/dist /usr/share/nginx/html
|
||||
ENV NGINX_PORT=80
|
||||
ENV BACKEND=api
|
||||
ENV PORT=3000
|
||||
# Empty = the CF-Connecting-IP header is dropped before it reaches the API, so it cannot be
|
||||
# forged by a direct client. Set to $http_cf_connecting_ip only when Cloudflare is really in
|
||||
# front. Defined here too, not just in compose, so the template always renders for anyone
|
||||
# running the prebuilt image from their own compose file.
|
||||
ENV CF_CONNECTING_IP=""
|
||||
|
||||
# Probe the port nginx was actually told to listen on (NGINX_PORT is configurable, so a
|
||||
# hardcoded http://localhost/ breaks on any instance that changed it), and address it as
|
||||
|
||||
Reference in new issue
Block a user