Security: WS-Rollenprüfung, JWT-Cookie statt localStorage, XSS/SSRF-Fixes, RDP-Consent-Secret
Some checks failed
IT Nexus Deploy / Build Frontend (push) Has been cancelled
IT Nexus Deploy / Deploy to Production (push) Has been cancelled

- WebSocket Shell/RDP: Rollenprüfung statt nur JWT-Gültigkeit (war: jeder eingeloggte User konnte fremde Agents per Shell/RDP übernehmen)
- JWT_SECRET: Server bricht ab statt mit unsicherem Default weiterzulaufen
- Auth: Token läuft jetzt über httpOnly-Cookie statt localStorage (XSS-Schutz gegen Session-Diebstahl)
- WS-Auth: Token nicht mehr als URL-Query-Param (landete in nginx-Logs), sondern als erste Message bzw. automatisch via Cookie
- Frontend: toter Rollen-Check (isSuperAdmin/isAdmin ohne Funktionsaufruf) in AgentDetailPage gefixt
- XSS: DOMPurify-Sanitizing für alle marked.parse()-Renderstellen (KI-Antworten, Kommentare, Knowledge Base)
- E-Mail: HTML-Escaping für alle ticket-gesteuerten Felder (auch über öffentliche Ticket-Route erreichbar)
- SSRF-Schutz beim Knowledge-Base-URL-Import (blockt private/Loopback-Adressen)
- TV-Dashboard: Shared-Key statt komplett offenem Endpoint
- Striktes Rate-Limit auf /login, must_change_password serverseitig erzwungen
- Agent (C#) v2.7.0: RDP-Consent/Disconnect/Capture verlangen jetzt ein Pro-Session-Secret (war: jeder lokale Prozess konnte Consent vortäuschen), DataDir-ACL für agent.log/status.json
- FIDO-PINs AES-256-GCM-verschlüsselt statt Klartext, Retention-Job für alte patch_commands/audit_log

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-26 13:27:17 +02:00
parent 3ea28def4c
commit 81b1c326fc
47 changed files with 706 additions and 235 deletions

View File

@@ -0,0 +1,20 @@
const COOKIE_NAME = 'token';
const isProd = process.env.NODE_ENV === 'production';
// httpOnly-Cookie statt Token in JS-lesbarem localStorage — verhindert dass ein XSS-Treffer
// das Session-Token einfach per document.cookie/localStorage ausliest.
function setAuthCookie(res, token, maxAgeMs = 8 * 60 * 60 * 1000) {
res.cookie(COOKIE_NAME, token, {
httpOnly: true,
secure: isProd,
sameSite: 'lax',
maxAge: maxAgeMs,
path: '/',
});
}
function clearAuthCookie(res) {
res.clearCookie(COOKIE_NAME, { httpOnly: true, secure: isProd, sameSite: 'lax', path: '/' });
}
module.exports = { setAuthCookie, clearAuthCookie, COOKIE_NAME };

View File

@@ -0,0 +1,34 @@
const crypto = require('crypto');
const ALGORITHM = 'aes-256-gcm';
function getKey() {
const secret = process.env.ENCRYPTION_KEY || process.env.JWT_SECRET || 'itnexus-fallback-key';
return crypto.createHash('sha256').update(secret).digest();
}
function encrypt(plainText) {
if (plainText === null || plainText === undefined || plainText === '') return null;
const iv = crypto.randomBytes(12);
const cipher = crypto.createCipheriv(ALGORITHM, getKey(), iv);
const encrypted = Buffer.concat([cipher.update(String(plainText), 'utf8'), cipher.final()]);
const authTag = cipher.getAuthTag();
return `${iv.toString('base64')}:${authTag.toString('base64')}:${encrypted.toString('base64')}`;
}
function decrypt(cipherText) {
if (!cipherText) return null;
const parts = cipherText.split(':');
if (parts.length !== 3) return cipherText; // unverschlüsselter Altbestand
try {
const [ivB64, authTagB64, dataB64] = parts;
const decipher = crypto.createDecipheriv(ALGORITHM, getKey(), Buffer.from(ivB64, 'base64'));
decipher.setAuthTag(Buffer.from(authTagB64, 'base64'));
const decrypted = Buffer.concat([decipher.update(Buffer.from(dataB64, 'base64')), decipher.final()]);
return decrypted.toString('utf8');
} catch {
return null;
}
}
module.exports = { encrypt, decrypt };

View File

@@ -0,0 +1,47 @@
const dns = require('dns').promises;
function isPrivateIp(ip) {
if (ip.includes(':')) {
// IPv6: loopback, link-local, unique-local
return ip === '::1' || /^fe80:/i.test(ip) || /^fc[0-9a-f]{2}:/i.test(ip) || /^fd[0-9a-f]{2}:/i.test(ip);
}
const parts = ip.split('.').map(Number);
if (parts.length !== 4 || parts.some(p => Number.isNaN(p))) return true; // unparsable → sicherheitshalber blocken
const [a, b] = parts;
if (a === 127) return true; // Loopback
if (a === 10) return true; // Private
if (a === 172 && b >= 16 && b <= 31) return true; // Private
if (a === 192 && b === 168) return true; // Private
if (a === 169 && b === 254) return true; // Link-local
if (a === 0) return true; // "this network"
return false;
}
// Wirft, falls die URL auf interne/private Adressen oder Loopback zeigt — verhindert SSRF
// über den Knowledge-Base-URL-Import (Server würde sonst beliebige interne Endpunkte abrufen).
async function assertPublicUrl(urlString) {
const parsed = new URL(urlString);
if (!['http:', 'https:'].includes(parsed.protocol)) {
throw new Error('Nur HTTP/HTTPS URLs erlaubt');
}
const hostname = parsed.hostname;
if (hostname === 'localhost' || hostname.endsWith('.local')) {
throw new Error('Interne/lokale Adressen sind nicht erlaubt');
}
let addresses;
try {
addresses = await dns.lookup(hostname, { all: true });
} catch {
throw new Error('Hostname konnte nicht aufgelöst werden');
}
for (const { address } of addresses) {
if (isPrivateIp(address)) {
throw new Error('Interne/private Adressen sind nicht erlaubt');
}
}
return parsed;
}
module.exports = { assertPublicUrl, isPrivateIp };