Skip to content

harden: secure server.js (CWE-307) - #36

Open
anupamme wants to merge 3 commits into
forumlify:Litefrom
anupamme:fix-repo-public-cwe-307-auth-rate-limit
Open

anupamme wants to merge 3 commits into
forumlify:Litefrom
anupamme:fix-repo-public-cwe-307-auth-rate-limit

Conversation

@anupamme

Copy link
Copy Markdown

Rate limiting on authentication endpoints allows 20 attempts per 15 minutes per IP address, which is insufficient to prevent modern credential stuffing attacks. The IP-based limiting can be bypassed using proxy rotation or distributed attack infrastructure. No progressive delays, CAPTCHA challenges, or account-level rate limiting are implemented. This is defence-in-depth at server.js:55 rather than a vulnerability I can show is exploitable here — it makes the failure mode explicit and bounded. Close it freely if the pattern is intentional.

Reference: CWE-307

What changed

  • server.js

Verification

No automated check could be run against this repository, so this change is unverified beyond review. Please treat it as a suggestion.


Automated security fix by OrbisAI Security

Automated security fix generated by OrbisAI Security
@forumlify

forumlify Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Automated review has started. I am checking this pull request now.

⚙️ Runtime environment
  • Mode: GitHub Actions (pull_request_target / opened)
  • Runner: Linux / x64 · Node.js v24.20.0
  • goose: v1.46.0 · model deepseek-v4-flash-0731 · thinking effort medium
  • Review policy: allow · strictness normal · max patch 120000 chars
  • Automation: auto-merge off · conflict repair on
  • Cache: R2 enabled · repository knowledge enabled

🤖 Created By GHBot

@lezi-fun lezi-fun left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes

Blocking — the account key is unavailable at this middleware position

authLimiter is mounted before express.json() and express.urlencoded(), so req.body is not parsed when keyGenerator runs. For JSON login and registration requests, account is therefore empty and the new account-aware behavior is not applied.

Blocking — the combined key can bypass the IP limit

Even if body parsing is moved earlier, using IP plus a user-controlled email or username as one key lets an attacker rotate the account value and obtain a fresh bucket for every request. That weakens the previous per-IP protection instead of adding an independent account limit.

Please use separate limiters or a composite policy with independent per-IP and per-account counters. Add tests covering repeated attempts for one account, repeated attempts across many account values from one IP, successful requests, and requests with malformed or missing bodies.

…buckets

authLimiter was mounted before express.json()/urlencoded(), so its
keyGenerator read req.body while it was still unparsed, and combining IP
with a client-controlled account value into one key let an attacker rotate
the account to get a fresh bucket per request, bypassing the per-IP limit.
Replace it with authIpLimiter (unchanged position, IP-only key) and
authAccountLimiter (mounted after body parsing, account-only key), so
neither counter can be bypassed by manipulating the other's input.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@forumlify

forumlify Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Automated review could not complete for commit 381b98bf1f45. A maintainer can inspect the failed Actions run or comment /recheck after the problem is corrected.

⚙️ Runtime environment
  • Mode: GitHub Actions (pull_request_target / synchronize)
  • Runner: Linux / x64 · Node.js v24.20.0
  • goose: v1.46.0 · model grok-4.6 · thinking effort medium
  • Review policy: allow · strictness normal · max patch 120000 chars
  • Automation: auto-merge off · conflict repair on
  • Cache: R2 enabled · repository knowledge enabled

🤖 Created By GHBot

…-307-auth-rate-limit

# Conflicts:
#	server.js
@forumlify

forumlify Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Automated review could not complete for commit 3558247aac63. A maintainer can inspect the failed Actions run or comment /recheck after the problem is corrected.

⚙️ Runtime environment
  • Mode: GitHub Actions (pull_request_target / synchronize)
  • Runner: Linux / x64 · Node.js v24.20.0
  • goose: v1.46.0 · model grok-4.6 · thinking effort medium
  • Review policy: allow · strictness normal · max patch 120000 chars
  • Automation: auto-merge off · conflict repair on
  • Cache: R2 enabled · repository knowledge enabled

🤖 Created By GHBot

@anupamme

Copy link
Copy Markdown
Author

Request changes

Blocking — the account key is unavailable at this middleware position

authLimiter is mounted before express.json() and express.urlencoded(), so req.body is not parsed when keyGenerator runs. For JSON login and registration requests, account is therefore empty and the new account-aware behavior is not applied.

Blocking — the combined key can bypass the IP limit

Even if body parsing is moved earlier, using IP plus a user-controlled email or username as one key lets an attacker rotate the account value and obtain a fresh bucket for every request. That weakens the previous per-IP protection instead of adding an independent account limit.

Please use separate limiters or a composite policy with independent per-IP and per-account counters. Add tests covering repeated attempts for one account, repeated attempts across many account values from one IP, successful requests, and requests with malformed or missing bodies.

Addressed. Pls review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants