security: server-side CAPTCHA (HMAC-signed) + magic-byte upload sniff + pagination bounds

Port upstream ac4af62 + PR #14/#17:
- lib/captcha.js: HMAC(CAPTCHA_SECRET, id:answer) challenge; GET
  /api/captcha returns {id, text, sig}; register/createPost/createReply
  verify answer server-side (bad answer / forged sig rejected)
- Frontend (Modals/NewPost/ReplyList): fetch challenge from server,
  submit id+answer+sig; no more client-side answer check (was bypassable)
- Upload: sniff JPEG/PNG/GIF/WebP magic bytes (ignore client MIME), UUID
  filenames — blocks spoofed HTML-as-image (stored XSS)
- Posts pagination: limit cap 50, page cap (deep-pagination DoS)
- CAPTCHA_SECRET env (falls back to JWT_SECRET)
This commit is contained in:
lezi-fun committed 2026-08-11 20:25:16 +08:00
1 parent 2780dab8e2
commit 7188d07aea
12 files changed
+141 -51

No files matched your search

+1 -1
View File
@@ -38,7 +38,7 @@ export default function CaptchaImage({ captcha, onRefresh }) {
}
// 算式文字(每个字符轻微旋转/位移,增加识别难度)
const text = captcha.question.replace(' = ?', '');
const text = (captcha.text || captcha.question || '').replace(' = ?', '');
const chars = text.split('');
const fontSize = Math.floor(H * 0.52);
const step = W / (chars.length + 1);