chore(security): resolve CodeQL findings — unbiased voucher RNG, linear email check, rate-limit query filter (v0.17.2-beta)

Address the open CodeQL code-scanning alerts:
- guestWifi voucher codes now use rejection sampling so the character
  distribution is uniform (fixes js/biased-cryptographic-random).
- Scheduled-report recipient validation replaced the backtracking email regex
  with a linear split-based check (fixes js/polynomial-redos).
- Add .github/codeql/codeql-config.yml excluding js/missing-rate-limiting:
  rate limiting is applied globally via app.use('/api', rateLimitRedis) plus
  per-route limiters, which CodeQL can't attribute to individual handlers, so
  that rule fired ~38 false positives.

Remaining alerts are dismissed as accepted/false-positive (RouterOS MD5 API
login and self-signed cert acceptance are protocol-mandated; log sites already
strip CRLF).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2GT-Rich
2026-07-18 09:56:18 -07:00
co-authored by Claude Opus 4.8
parent 3fe8341b71
commit b3ba2b98dc
8 changed files with 39 additions and 7 deletions
+12 -2
View File
@@ -87,9 +87,19 @@ router.post('/setup', requireWrite, async (req: Request, res: Response) => {
// Human-friendly voucher codes: no ambiguous chars (0/O, 1/I/L)
const CODE_CHARS = 'ABCDEFGHJKMNPQRSTUVWXYZ23456789';
function generateCode(len = 8): string {
const bytes = randomBytes(len);
const n = CODE_CHARS.length;
// Rejection sampling: discard bytes at or above the largest multiple of n so
// the modulo is uniform (avoids the slight bias of a raw byte % n).
const limit = Math.floor(256 / n) * n;
let out = '';
for (let i = 0; i < len; i++) out += CODE_CHARS[bytes[i] % CODE_CHARS.length];
while (out.length < len) {
for (const b of randomBytes(len)) {
if (b < limit) {
out += CODE_CHARS[b % n];
if (out.length === len) break;
}
}
}
return `${out.slice(0, 4)}-${out.slice(4)}`;
}