Files
iistwin/server/utils/return-to.ts
Ильяс Султанов 5750a3106f security(auth): anti-enumeration, returnTo-валидация, лимит попыток логина
Шаг 2.1 плана production-готовности:
- единый 401 при любом отказе логина + constant-time bcrypt
- forgot-password: идентичный ответ независимо от существования email
- sanitizeReturnTo (open redirect fix в /api/documents/generate-link)
- 10 неудачных попыток → блок 15 мин (in-memory, аудит)
- DATABASE_SSL_REJECT_UNAUTHORIZED env (дефолт true)
- доделка 0.7: статичные тексты в llm-providers/rag/finance-di2
- 8 новых тестов (104/104)
2026-09-08 00:46:57 +03:00

12 lines
744 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Валидация returnTo/redirect-параметров против open redirect:
// принимаем только относительные пути, начинающиеся с одиночного '/'.
// '//evil.com' (protocol-relative), '/\evil.com' (backslash-trick,
// браузеры трактуют '\' как '/') и управляющие символы отклоняются.
export function sanitizeReturnTo(value: unknown): string | undefined {
if (typeof value !== 'string' || value.length === 0) return undefined;
if (!value.startsWith('/')) return undefined;
if (value.length > 1 && (value[1] === '/' || value[1] === '\\')) return undefined;
if (/[\r\n\0]/.test(value)) return undefined;
return value;
}