Cuatro problemas encontrados en una revision de seguridad, los cuatro reproducidos antes y despues del arreglo. SSRF + cuelgue del handler. El `endpoint` de una suscripcion push se validaba solo como "string no vacio", y web-push lo pasa tal cual a https.request: cualquier usuario registrado alcanzaba cualquier host:puerto que viera el contenedor api, que comparte red Docker con el resto del stack. Ademas no habia timeout, asi que un endpoint que aceptaba TCP y se callaba dejaba colgado el handler que hacia await (>2 min medidos). Ahora el rechazo de direcciones loopback/privadas/ link-local/CGNAT vive en el lookup del propio agente, no en una pasada previa, asi que no queda ventana de DNS rebinding; y los envios llevan timeout de 10s. Amplificacion. No habia tope de suscripciones por usuario y sendPush lanzaba un Promise.all sin limite: una peticion de ~90 bytes producia 200 conexiones TLS simultaneas al host que eligiera el atacante. Cap de 20 por cuenta y 6 en vuelo. CSRF. SameSite=Lax deja fuera un origen cross-site pero no un subdominio hermano, que es el mismo site y es el reparto habitual en self-hosting; y el body se parseaba como JSON dijera lo que dijera el Content-Type, asi que bastaba un POST simple sin preflight. Ahora una peticion que cambia estado tiene que ser Sec-Fetch-Site: same-origin, o traer un Origin igual a ORIGIN donde esa cabecera no llegue. Exentas las rutas que llevan su credencial en el body y todo lo autenticado por Bearer, para no romper la app movil. Fijacion de sesion. Las cookies se reducian con Object.fromEntries, que se queda con la ultima repetida: un subdominio hermano podia plantar gymsid para el dominio padre y quedarse con la sesion. En HTTPS la cookie pasa a __Host-gymsid, que el navegador garantiza host-only; la legacy se sigue aceptando, asi que actualizar no desloguea a nadie. Un nombre repetido con valores distintos se rechaza entero. El proxy de Vite reescribe Origin porque el dev server vive en otro puerto. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
43 lines
1.7 KiB
JavaScript
43 lines
1.7 KiB
JavaScript
import { defineConfig } from 'vite'
|
|
import react from '@vitejs/plugin-react'
|
|
|
|
const backend = process.env.API_TARGET || 'http://127.0.0.1:3000'
|
|
// The API refuses a state-changing request that a browser sent from anywhere other than its own
|
|
// ORIGIN (the CSRF guard in api/server.js). The dev server is on a different port, so the page's
|
|
// real Origin is not ORIGIN — modern browsers get through on Sec-Fetch-Site: same-origin, and
|
|
// presenting the expected Origin here covers the ones that don't send it. Match your .env if you
|
|
// changed ORIGIN: API_ORIGIN=https://gym.example.com npm run dev
|
|
const apiOrigin = process.env.API_ORIGIN || 'http://localhost:8080'
|
|
const media = process.env.MEDIA_TARGET || 'http://127.0.0.1:8888'
|
|
|
|
// Optional web analytics (Umami). Injected only when BOTH vars are set at build time,
|
|
// so a plain `npm run build` — and every self-hosted install — stays telemetry-free.
|
|
// Set for the public instance: VITE_UMAMI_SRC=https://stats.example/script.js VITE_UMAMI_ID=<uuid>
|
|
const umamiSrc = process.env.VITE_UMAMI_SRC
|
|
const umamiId = process.env.VITE_UMAMI_ID
|
|
|
|
const umami = {
|
|
name: 'opengym-umami',
|
|
transformIndexHtml() {
|
|
if (!umamiSrc || !umamiId) return
|
|
return [{
|
|
tag: 'script',
|
|
attrs: { defer: true, src: umamiSrc, 'data-website-id': umamiId },
|
|
injectTo: 'head'
|
|
}]
|
|
}
|
|
}
|
|
|
|
export default defineConfig({
|
|
plugins: [react(), umami],
|
|
base: './',
|
|
server: {
|
|
proxy: {
|
|
'/api': { target: backend, changeOrigin: true, headers: { Origin: apiOrigin } },
|
|
'/img': { target: media, changeOrigin: true },
|
|
'/gif': { target: media, changeOrigin: true }
|
|
}
|
|
},
|
|
build: { chunkSizeWarningLimit: 1500 }
|
|
})
|