test: XSS + rate-limiter sections (40/40 pass)

This commit is contained in:
2026-05-30 17:11:42 +03:00
parent 8ab7eed629
commit 1f5c0d8623
+44
View File
@@ -516,6 +516,50 @@ async function cleanup() {
}
}
// ─────────────────────────────────────────────────────────────────────────────
// 16. Безопасность — XSS и спецсимволы в comment
// ─────────────────────────────────────────────────────────────────────────────
console.log('\n── 16. Безопасность: XSS в comment ──');
{
const xssPayload = '<script>alert(1)</script>';
const csrf = await getCsrfFromIndex(userAgent);
const res = await userAgent.post('/add').type('form')
.send({ value: '5.5.5.5', comment: xssPayload, _csrf: csrf });
// Запись могла добавиться или нет (зависит от валидации comment)
const err = getRedirectParam(res, 'error');
// Если добавилась — проверяем что скрипт не выполняется в HTML
const page = await userAgent.get('/');
const rawScript = page.text.includes('<script>alert(1)</script>');
log(!rawScript, 'security: XSS в comment — скрипт не рендерится в HTML',
rawScript ? 'RAW SCRIPT FOUND — XSS!' : `escaped или отклонено (err=${err})`);
// Чистим
await pool.query(
`UPDATE whitelist_entries SET deleted_at = NOW(), deleted_by = 'test-cleanup'
WHERE value_cidr = '5.5.5.5/32' AND deleted_at IS NULL`
);
}
// ─────────────────────────────────────────────────────────────────────────────
// 17. Rate-limiter — превысить mutationLimiter (30 POST/min)
// ─────────────────────────────────────────────────────────────────────────────
console.log('\n── 17. Rate-limiter ──');
{
// Отправляем 35 POST /add подряд с заведомо невалидным CIDR (быстро)
// Rate-limiter (30/min) должен сработать и вернуть 429
let got429 = false;
for (let i = 0; i < 35; i++) {
const csrf = await getCsrfFromIndex(userAgent);
const res = await userAgent.post('/add').type('form')
.send({ value: 'not-an-ip', comment: `rate ${i}`, _csrf: csrf });
if (res.status === 429) { got429 = true; break; }
}
log(got429, 'rate-limiter: POST /add → 429 после 30 запросов');
}
// ─────────────────────────────────────────────────────────────────────────────
// Cleanup
// ─────────────────────────────────────────────────────────────────────────────