Skip to content

fix(security): add dedicated auth endpoint rate limiting#550

Open
Namraa310806 wants to merge 1 commit into
FireFistisDead:masterfrom
Namraa310806:fix/auth-endpoint-rate-limiting
Open

fix(security): add dedicated auth endpoint rate limiting#550
Namraa310806 wants to merge 1 commit into
FireFistisDead:masterfrom
Namraa310806:fix/auth-endpoint-rate-limiting

Conversation

@Namraa310806

@Namraa310806 Namraa310806 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR introduces dedicated rate limiting for authentication endpoints to strengthen protection against brute-force attacks, credential stuffing, password spraying, and automated account creation abuse.

Previously, authentication routes relied on general application protections and did not enforce authentication-specific request throttling. This allowed repeated login and signup attempts from the same source without sufficient restrictions.

The update adds dedicated authentication rate limiters, configurable security settings, abuse-detection integration, and regression tests.


Changes Made

Authentication-Specific Rate Limiting

Added dedicated rate limiting controls for:

POST /api/auth/login
POST /api/auth/signup

New configuration options:

AUTH_RATE_LIMIT_WINDOW_MS
AUTH_RATE_LIMIT_MAX
AUTH_SIGNUP_RATE_LIMIT_MAX

These limits operate independently from the global API rate limiter.


Login Endpoint Protection

Implemented a dedicated login rate limiter to reduce the risk of:

  • Brute-force password attacks
  • Credential stuffing attacks
  • Password spraying attempts
  • Automated login abuse

When the configured threshold is exceeded, the endpoint returns:

HTTP 429 Too Many Requests

Signup Endpoint Protection

Implemented a dedicated signup rate limiter to reduce the risk of:

  • Automated account creation
  • Registration flooding
  • Bot-driven abuse
  • Resource exhaustion through mass signups

When the configured threshold is exceeded, the endpoint returns:

HTTP 429 Too Many Requests

Abuse Protection Integration

Integrated authentication rate-limit violations with the existing abuse detection and IP tracking mechanisms where applicable.

This allows repeated offenders to be identified and restricted more effectively.


Configuration Documentation

Added documentation and environment configuration examples for:

  • Login request limits
  • Signup request limits
  • Authentication security tuning

This enables operators to adjust limits according to deployment requirements.


Regression Tests

Added automated tests covering:

  • Login rate limiting
  • Signup rate limiting
  • Limit threshold enforcement
  • Authentication endpoint abuse scenarios
  • Rate-limit response validation

These tests help prevent future regressions.


Security Impact

This change reduces the risk of:

  • Credential stuffing attacks
  • Brute-force password guessing
  • Password spraying attacks
  • Automated account creation abuse
  • Authentication endpoint resource exhaustion

Files Modified

server.js
.env.example
Authentication test suite

Verification Checklist

  • Login rate limiting implemented
  • Signup rate limiting implemented
  • Configurable security thresholds added
  • Abuse protection integrated
  • Environment documentation updated
  • Regression tests added
  • Existing authentication functionality preserved
  • No breaking API changes introduced

Related Issue

Fixes: #501

Summary by CodeRabbit

Release Notes

  • New Features

    • Implemented rate limiting for authentication endpoints (login and signup). Excessive requests will now return HTTP 429 status, preventing brute-force attacks while allowing legitimate users to retry after a configured time window.
  • Tests

    • Added comprehensive tests for authentication rate limiting, verifying that limits are enforced correctly and that service access resumes after the configured window expires.

@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

@Namraa310806 is attempting to deploy a commit to the firefistisdead's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds dedicated sliding-window rate limiting to POST /api/auth/login and POST /api/auth/signup. Three new environment variables (AUTH_RATE_LIMIT_WINDOW_MS, AUTH_RATE_LIMIT_MAX, AUTH_SIGNUP_RATE_LIMIT_MAX) are declared in .env.example, parsed in server.js, and used to construct authLoginLimiter and authSignupLimiter middlewares. The generic authRoutes router mount is replaced with explicit rate-limited routes. module.exports is trimmed to expose only app and the two limiters. Tests verify 429 responses and window-expiry recovery.

Changes

Auth Endpoint Rate Limiting

Layer / File(s) Summary
Env var config and parsing
.env.example, server.js
Declares AUTH_RATE_LIMIT_WINDOW_MS, AUTH_RATE_LIMIT_MAX, and AUTH_SIGNUP_RATE_LIMIT_MAX in the example env file and parses them with defaults in server.js.
Limiter definitions, route wiring, and exports
server.js
Defines authLoginLimiter and authSignupLimiter with per-key namespaces, replaces the generic app.use("/api/auth", authRoutes) mount with explicit POST /api/auth/login and POST /api/auth/signup routes that apply the limiters, and trims module.exports to { app, authLoginLimiter, authSignupLimiter }.
Rate limit tests and test fixture data
server.test.js, src/data/users.json
Adds isolated-server tests for login and signup 429 enforcement and a window-expiry regression test for login; inserts test@example.com and additional testuser/testuser2 records with bcrypt hashes into users.json to support those tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

fix, type:security, backend, type:testing, type:docs

Poem

🐇 Hop, hop — the login door now locks,
Too many knocks? A 429 blocks!
Signup too has guards in place,
Brute-force bots must slow their pace.
The window turns, the limiter resets,
Safe credentials, no regrets! 🔒

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Out of Scope Changes check ❓ Inconclusive The PR introduces changes to server.js exports (removing multiple exports and keeping only app, authLoginLimiter, authSignupLimiter) that appear broader than rate limiting. While potentially justified by refactoring, the significant reduction in exported symbols warrants verification that this doesn't break dependent code. Verify that the removal of previously exported symbols (schemas, helper functions, credential/session utilities) does not break any dependent code or tests in the codebase.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(security): add dedicated auth endpoint rate limiting' clearly and concisely summarizes the main change—implementing rate limiting for authentication endpoints to address security vulnerabilities.
Description check ✅ Passed The PR description is comprehensive, including a detailed summary, changes made, security impact, files modified, verification checklist, and related issue. However, the testing section checklist is not explicitly completed in the template format provided.
Linked Issues check ✅ Passed The PR successfully addresses all major objectives from issue #501: implements dedicated rate limiting for /api/auth/login and /api/auth/signup, adds configurable environment variables, returns HTTP 429 responses, includes regression tests, and preserves existing functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added backend Express or API gateway work docs Documentation only documentation Improvements or additions to documentation enhancement New feature or request feature A new feature or improvement fix A targeted fix or cleanup frontend Frontend-related work type:docs type:security type:testing labels Jun 15, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server.js`:
- Around line 1765-1770: The first module.exports assignment (exporting app,
authLoginLimiter, and authSignupLimiter) is being overridden by a second
module.exports statement later in the file, causing the rate limiters to not be
exported. Consolidate these exports by either moving authLoginLimiter and
authSignupLimiter to the second module.exports block at the end of the file, or
by combining all exports into a single module.exports statement. Ensure the
final exported object includes app, authLoginLimiter, and authSignupLimiter.

In `@src/data/users.json`:
- Around line 67-92: Remove all the test user accounts from src/data/users.json
that were added during development. These test accounts (with emails like
testuser-1781551499289@example.com, testuser2-1781551499516@example.com, etc.
and their associated bcrypt hashed passwords) should not be committed to the
runtime user store since authController.js reads this file directly at runtime,
creating unnecessary credential exposure and test-data drift in the
production-facing auth datastore. Keep only the original legitimate user
entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: aa8cc65e-d35c-4ef8-98f1-968b428f2d9a

📥 Commits

Reviewing files that changed from the base of the PR and between 5590b87 and 6fa9bb0.

📒 Files selected for processing (4)
  • .env.example
  • server.js
  • server.test.js
  • src/data/users.json

Comment thread server.js
Comment thread src/data/users.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Express or API gateway work docs Documentation only documentation Improvements or additions to documentation enhancement New feature or request feature A new feature or improvement fix A targeted fix or cleanup frontend Frontend-related work type:docs type:security type:testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Authentication Endpoints Lack Rate Limiting Protection Against Brute-Force Attacks

1 participant