Pentest R95: portalUsername (Manual-Modus) härten
R95.1 MEDIUM: foo\r\nBcc:evil@x.de → Header-Injection-Vektor R95.3 LOW: <script>...</script>@x.de → silent stripHtml-Mutation R95.4 LOW: >190 Zeichen → VARCHAR-Overflow → 500 statt 400 Fix: validatePortalUsername() in sanitize.ts mit Whitelist ^[A-Za-z0-9_\-/.@+ ]{0,100}$. Strukturell sind CRLF, Tab, alle Control-Chars, Tags und Quotes raus → R95.1+R95.3 ohne extra Check. Max 100 → ApiError(400) → R95.4. Raw-Input vor stripHtml geprüft (R87-Pattern). Eingehängt in sanitizeContractBody. R95.2 (Email-Format-Pflicht) bewusst NICHT übernommen: portalUsername ist im Manual-Modus nicht zwingend eine Email (Vodafone, 1&1, EWE und Stadtwerke nutzen Kundennummern oder Pseudonyme als Portal-Login). Doku in SECURITY-HARDENING.md § Runde 95. Frontend: maxLength={100} am Input als UX-Schicht. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -396,6 +396,58 @@ export function validateContractIdentifier(
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
// Pentest 95.1/95.3/95.4 (MEDIUM/LOW, 2026-06-21): Manuelles
|
||||
// `portalUsername` am Vertrag hatte gar keine Validierung. Drei
|
||||
// nachweisbare Effekte:
|
||||
// - `foo\r\nBcc:evil@x.de` (CRLF) verbatim gespeichert →
|
||||
// Header-Injection-Vektor sobald der Wert in Mail-Templates
|
||||
// oder PDF-Footers landet.
|
||||
// - `<script>alert(1)</script>@x.de` lief durch stripHtml →
|
||||
// stille Mutation (R87.1/R89.2-Pattern auf neuem Feld).
|
||||
// - >190 Zeichen → VARCHAR-Overflow → generischer 500 statt 400.
|
||||
//
|
||||
// Bewusst NICHT übernommen wurde R95.2 (Email-Format-Pflicht):
|
||||
// `portalUsername` ist im Manual-Modus nicht zwingend eine
|
||||
// E-Mail. Vodafone, 1&1, EWE und etliche Stadtwerke nutzen
|
||||
// Kundennummern, Pseudonyme oder Customer-IDs als Portal-Login.
|
||||
// Eine `email().regex()`-Pflicht würde legitime Logins ablehnen.
|
||||
// Der Stressfrei-Modus hängt eh an einer schon validierten
|
||||
// Email-Stammdate (assertValidForwardingEmail).
|
||||
//
|
||||
// Allowed: Alphanumerisch + `_`, `-`, `.`, `/`, `@`, `+`, Space.
|
||||
// Damit sind Vodafone-Kunden-IDs (`12345678`), Pseudonyme
|
||||
// (`max.mustermann`), Plus-Tag-Emails (`m+tag@example.com`)
|
||||
// und gemischte Formen abgedeckt. Strukturell sind CRLF, Tab,
|
||||
// alle Control-Chars, Tags und Quotes raus → R95.1+R95.3 ohne
|
||||
// extra Check. Max 100 Zeichen << VARCHAR(191) → R95.4.
|
||||
const PORTAL_USERNAME_ALLOWED = /^[A-Za-z0-9_\-/.@+ ]{0,100}$/;
|
||||
const PORTAL_USERNAME_MAX_LEN = 100;
|
||||
|
||||
export function validatePortalUsername(
|
||||
raw: unknown,
|
||||
fieldLabel = 'portalUsername',
|
||||
): string | null {
|
||||
if (raw == null) return null;
|
||||
if (typeof raw !== 'string') {
|
||||
throw new ApiError(400, `${fieldLabel} muss ein Text sein.`);
|
||||
}
|
||||
const trimmed = raw.trim();
|
||||
if (trimmed === '') return null;
|
||||
if (trimmed.length > PORTAL_USERNAME_MAX_LEN) {
|
||||
throw new ApiError(
|
||||
400,
|
||||
`${fieldLabel} darf maximal ${PORTAL_USERNAME_MAX_LEN} Zeichen lang sein.`,
|
||||
);
|
||||
}
|
||||
if (!PORTAL_USERNAME_ALLOWED.test(trimmed)) {
|
||||
throw new ApiError(
|
||||
400,
|
||||
`${fieldLabel} enthält unzulässige Zeichen (erlaubt: Buchstaben, Ziffern, Punkt, Bindestrich, Schrägstrich, Unterstrich, @, +, Leerzeichen).`,
|
||||
);
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
// Pentest 89.1 + 89.2 (MEDIUM/LOW, 2026-06-21): Postadressen am
|
||||
// Provider (`contactAddress`, `cancellationAddress`). sanitizeNotes
|
||||
// hat das Length-Cap silent durchgeschoben (slice statt Error) und
|
||||
|
||||
Reference in New Issue
Block a user