feat: implement secure email verification flow with token hashing and expiration logic#109
Merged
Merged
Conversation
… expiration logic
Collaborator
|
Resolve conflict |
|
I will take this issue. Strong full-stack background, clean PR coming shortly. |
|
I'd like to work on this issue. I have background in full-stack and will submit a PR ASAP. |
Contributor
Author
|
Conflicts have been resolved and the pr is ready for merging. Apologies about the delay |
22 tasks
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.
The implementation is successful. Here's a summary of everything
implemented:
Schema (
prisma/schema.prisma)DateTime?, failedVerifyAttempts Int @default(0) to User
action, tokenHash, ipAddress, userAgent)
Token security (
src/utils/crypto.ts)crypto.randomBytes(32).toString('base64url')
(existing sha256() method used)
Email templates (
src/templates/verify-email.{html,txt}){{verificationLink}}, {{year}} placeholders
Auth service (
src/services/auth.service.ts)(non-blocking), logs SENT, returns userId only (no
handles lockout after 10 failed attempts, logs
VERIFIED/EXPIRED/FAILED
rate limit (3/hour), generates fresh token, logs RESENT,
email-existence not revealed
EMAIL_NOT_VERIFIED code and resendUrl
verificationExpiry, failedVerifyAttempts from all responses
New endpoints (
src/routes/auth.routes.ts)IP-level rate limiter + per-email Redis limiter
requireVerifiedmiddleware (src/middleware/auth.ts)'EMAIL_NOT_VERIFIED', resendUrl } if false
/beneficiaries/:id/kyc
Tests
format, hash storage, expiry, rate limits, lockout,
sanitization
(tests/integration/email.verification.flow.test.ts) — full
register→verify→login flow, expired tokens, resend rate
limits, security properties, email delivery content
closes #68