Harden login: rate limits, expiring tokens, no credentials in logs #3
Loading…
Reference in a new issue
No description provided.
Delete branch "armin-bot/impress-2020:claude/codebase-security-audit-3e2fxx"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Companion to OpenNeo/impress#13, from the same security audit. That PR rate-limits Classic DTI's login form, but Impress 2020's
loginGraphQL mutation checks the same passwords (sameopenneo_id.userstable), so without this, an attacker could just go around those limits.What's wrong today
login. Nothing limits attempts, and GraphQL aliases let one HTTP request carry hundreds oflogincalls ({a: login(…) b: login(…) …}), so per-request limits in nginx wouldn't help either.getUserIdFromTokendidauthToken.createdAt < oneWeekAgo, comparing an ISO string to aDate. That comparison is alwaysfalse("2020-01-01T…" < new Date()→false), so the one-week expiry never fired. Browsers drop the cookie after a week, but a token copied from a cookie or a log stayed valid forever.What this changes
getAuthToken: 10 attempts per account per 10 minutes, and 100 attempts overall per 10 minutes (per process, so pm2's cluster mode loosens this a few times over).utf8mb3_general_cicollation matchesvictim,VICTIM,Víctim… to the same row.awaitbetween checking a limit and counting the attempt, so concurrent aliased mutations can't all pass before any of them is counted.X-Forwarded-Foris entirely client-supplied.createdAtinto aDate, and reject tokens whose date doesn't parse.nullinstead of throwing.⚠️ Tradeoff to decide on
The overall limit is a deliberate tradeoff. It's the only way to slow down credential stuffing (many accounts, a few guesses each) without a trustworthy IP. But it also means someone could spam failed logins to pause Impress 2020 logins for everyone, 10 minutes at a time. Classic DTI's login isn't affected. If Impress 2020 logins barely get used anymore, that seems like a fine trade (and removing the
login/createAccountmutations entirely would be even better). If they do get real use, raise the limit or drop it.Testing
The repo's jest setup is stale (no
jestdependency, and thequery-testssetup dir is missing), so I didn't add tests here. Instead, I bundled the realauth-by-db.js+rate-limiter.jswith esbuild, against a stub DB, and checked:null, and non-object tokens returnnullwithout throwing.TooManyLoginAttemptsError. Even the correct password is refused while throttled.RateLimiter: window rollover, independent keys, and pruning of expired keys.I haven't run it end-to-end in a full Next/MySQL environment, so a quick login on staging/prod after deploy would be good.
🤖 Generated with Claude Code
https://claude.ai/code/session_014PWWd37NNMoRcoGZrnWKEs