From 35f60d880f172cb639bd2580277b277c1819d544 Mon Sep 17 00:00:00 2001 From: silviroa Date: Thu, 18 Jun 2026 17:21:53 -0300 Subject: [PATCH 1/2] core(fix): Control de tipo de token en appMiddleware --- auth/auth.class.ts | 26 +++++++++++++++++++++++--- config.ts | 3 ++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/auth/auth.class.ts b/auth/auth.class.ts index a3888ce468..32cef26ab3 100644 --- a/auth/auth.class.ts +++ b/auth/auth.class.ts @@ -169,11 +169,31 @@ export class Auth { */ static deniedPatients() { return (req, res, next) => { + if (req.user.type !== 'paciente-token') { - next(); - } else { - next(403); + return next(); + } + + // Permitir explícitamente algunas rutas aún para pacientes + const allowedForPaciente = [ + '/protocolosLab', + '/historial', + '/prestaciones/huds', + '/prestaciones', + '/recetas' + ]; + const requestPath = (req.path || req.url || '').toString(); + // Si la ruta es una de las permitidas, continuar + if (allowedForPaciente.some(p => requestPath.includes(p))) { + const idPacienteQuery = req.query?.pacienteId || req.query?.idPaciente || null; + const idPacienteToken = req.user.pacientes.find(p => String(p.id) === String(idPacienteQuery)); + + if (idPacienteToken) { + return next(); + } } + // Por defecto denegar si no está en las excepciones ni coincide el paciente + return next(403); }; } diff --git a/config.ts b/config.ts index 24199035d7..8a75d27a24 100644 --- a/config.ts +++ b/config.ts @@ -7,13 +7,14 @@ import { IPS } from './config.private'; const appMiddleware = [ Auth.authenticate(), - // Auth.deniedPatients() + Auth.deniedPatients() ]; const mobileMiddleware = [ Auth.authenticate() ]; + /* const publicMiddleware = [ Auth.authenticatePublic() From 1a8153670c4c473964dcc6b572c9ecce69438de1 Mon Sep 17 00:00:00 2001 From: silviroa Date: Fri, 19 Jun 2026 10:26:48 -0300 Subject: [PATCH 2/2] fix(AUTH): agrega control en ruta de cda --- auth/auth.class.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/auth/auth.class.ts b/auth/auth.class.ts index 32cef26ab3..58b43478ca 100644 --- a/auth/auth.class.ts +++ b/auth/auth.class.ts @@ -173,24 +173,29 @@ export class Auth { if (req.user.type !== 'paciente-token') { return next(); } - // Permitir explícitamente algunas rutas aún para pacientes const allowedForPaciente = [ '/protocolosLab', '/historial', '/prestaciones/huds', '/prestaciones', - '/recetas' + '/recetas', + '/paciente/' ]; const requestPath = (req.path || req.url || '').toString(); // Si la ruta es una de las permitidas, continuar + const idPacientePath = requestPath ? requestPath.split('/').pop() : null; if (allowedForPaciente.some(p => requestPath.includes(p))) { - const idPacienteQuery = req.query?.pacienteId || req.query?.idPaciente || null; + const idPacienteQuery = req.query?.pacienteId || req.query?.idPaciente || idPacientePath || null; const idPacienteToken = req.user.pacientes.find(p => String(p.id) === String(idPacienteQuery)); if (idPacienteToken) { return next(); } + } else { + if (requestPath.endsWith('.pdf')) { + return next(); + } } // Por defecto denegar si no está en las excepciones ni coincide el paciente return next(403);