Удалена эмуляция имперсонации (enhanceImpersonation)
- Удалён v2/src/impersonation/index.js (URL-эмуляция) - Удалён enhanceImpersonation из middleware цепочек /app и /admin - Боевая checkImpersonation (IAM) не тронута - Версия 0.1.12
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ipwhitelist",
|
||||
"version": "0.1.11",
|
||||
"version": "0.1.12",
|
||||
"description": "IP WhiteList microservice for cloud provider",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
|
||||
+2
-3
@@ -26,7 +26,6 @@ const express = require('express');
|
||||
const config = require('./src/config');
|
||||
const auth = require('./src/auth');
|
||||
const { resolveContext } = require('./src/router');
|
||||
const { enhanceImpersonation } = require('./src/impersonation');
|
||||
const { createUserRouter } = require('./src/user');
|
||||
const { createAdminRouter } = require('./src/admin');
|
||||
const { pool } = require('./src/db');
|
||||
@@ -103,10 +102,10 @@ function createV2Router({ generateCsrfToken, doubleCsrfProtection } = {}) {
|
||||
});
|
||||
|
||||
// ── /v2/app — пользовательский CRUD (только с сессией) ──────────────
|
||||
router.use('/app', mutationLimiter, enhanceImpersonation, resolveContext, doubleCsrfProtection || ((req,res,next)=>next()), createUserRouter({ generateCsrfToken }));
|
||||
router.use('/app', mutationLimiter, resolveContext, doubleCsrfProtection || ((req,res,next)=>next()), createUserRouter({ generateCsrfToken }));
|
||||
|
||||
// ── /v2/admin — админка: лимиты + аудит ──────────────────────────
|
||||
router.use('/admin', mutationLimiter, enhanceImpersonation, resolveContext, doubleCsrfProtection || ((req,res,next)=>next()), createAdminRouter({ generateCsrfToken }));
|
||||
router.use('/admin', mutationLimiter, resolveContext, doubleCsrfProtection || ((req,res,next)=>next()), createAdminRouter({ generateCsrfToken }));
|
||||
|
||||
// ── GET /v2/ — редирект на /v2/app ──────────────────────────────────
|
||||
router.get('/', (req, res) => res.redirect('/v2/app'));
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
// ═══════════════════════════════════════════════════════════════════════════════
|
||||
// V2 — Имперсонация (IAM + URL-режим)
|
||||
//
|
||||
// ЭТО: middleware — подмена сессии при имперсонации.
|
||||
// НЕ: жёсткая логика в resolveContext или user/index.js.
|
||||
//
|
||||
// IAM-имперсонация: если сессия уже содержит isImpersonated=true → не трогаем.
|
||||
//
|
||||
// URL-имперсонация: для разрешённых пользователей (IMPERSONATION_ALLOWED_USERS).
|
||||
// /v2/app?impersonate=email&company=W***
|
||||
// Полная подмена сессии: email, clientId, profiles — всё от таргета.
|
||||
//
|
||||
// ENV:
|
||||
// IMP_ALLOWED — emails через запятую (кому можно)
|
||||
// ═══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
const ALLOWED_USERS = new Set(
|
||||
(process.env.IMP_ALLOWED || '')
|
||||
.split(/[\s,/]+/).map(s => s.trim()).filter(Boolean)
|
||||
);
|
||||
|
||||
function enhanceImpersonation(req, res, next) {
|
||||
const u = req.session && req.session.user;
|
||||
if (!u) return next();
|
||||
|
||||
// ── IAM-имперсонация — уже в сессии, не трогаем ────────────────────
|
||||
if (u.isImpersonated) return next();
|
||||
|
||||
// ── URL-имперсонация ───────────────────────────────────────────────
|
||||
const targetEmail = req.query.impersonate;
|
||||
const targetCompany = req.query.company;
|
||||
|
||||
if (targetEmail && targetCompany && ALLOWED_USERS.has(u.email)) {
|
||||
// Сохраняем оригинал
|
||||
const origEmail = u.email;
|
||||
const origFio = u.fio;
|
||||
|
||||
// Подменяем ВСЕ данные на таргета (как делает IAM)
|
||||
u.email = targetEmail;
|
||||
u.clientId = targetCompany;
|
||||
u.activeClientId = targetCompany;
|
||||
u.allClientIds = [targetCompany];
|
||||
u.companyName = targetCompany;
|
||||
u.isImpersonated = true;
|
||||
u.originalUserEmail = origEmail;
|
||||
u.originalUserFullName = origFio ? (origFio.fullName || '') : '';
|
||||
u.impersonatedCompanyId = targetCompany;
|
||||
u.fio = null;
|
||||
|
||||
u.profiles = [{
|
||||
client_id: targetCompany,
|
||||
company_name: targetCompany,
|
||||
is_active_profile: true,
|
||||
}];
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
module.exports = { enhanceImpersonation };
|
||||
Reference in New Issue
Block a user