R2 Security: login rate-limiting + account lockout + secrets fail-fast - #65
Merged
Conversation
Akash29g
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Round 2 — Security half
Pairs with Akash's R2 CI/CD (Dependabot / npm audit / dotnet vuln + gitleaks diff-only + Trivy).
What
POST /api/v1/auth/login(5/min, FixedWindow), returns ourApiResponseenvelope with codeRATE_LIMITED(429 +Retry-After). Applied via[EnableRateLimiting("login")]— only the login action is throttled.login_attempts): 5 failures within 15 min → 15-min lock, keyed by normalized email, records IP. Survives restarts / spans multiple IPs. Counter cleared on successful login.INVALID_CREDENTIALS; failures are recorded either way.AddOptions<JwtSettings>().Validate(...).ValidateOnStart()(Key present, ≠ placeholder, ≥ 32 chars) + connection-string guard inProgram.cs. Newdocs/security-secrets.mddocuments required env vars.Pipeline / ordering
UseRateLimiter()placed after CORS, beforeUseAuthentication().UseForwardedHeaders()(R1).Tests
Login_returns_429_when_account_locked,Login_registers_failure_on_bad_password).LoginLockoutServicetests: lock-after-5, unlocked-at-4, reset, case/whitespace-insensitive, window re-arm, retry-after range).DB change
AddLoginAttempts(createslogin_attempts+ unique index onemail). Reviewer: rundotnet ef database update.Known finding (deferred to R4 — refresh tokens)
JwtTokenService.CreateTokenhardcodesexpires: DateTime.UtcNow.AddHours(8)and ignoresJwt:ExpiryMinutes. Access-token lifetime will be reworked when refresh tokens land (R4). Documented indocs/security-secrets.md.Watch-outs for reviewer (Akash)
Jwt:Key→ app refuses to start./auth/meand normal reads are NOT throttled.