TuKit implements layered protection against brute-force attacks usingDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/fredy-rizo/tukit/llms.txt
Use this file to discover all available pages before exploring further.
express-rate-limit with custom handlers that escalate penalties and persist blocked devices to MongoDB. Rather than applying a flat lockout, the system progressively widens the penalty window on each repeat violation for login attempts, while registration abuse triggers a permanent device-level block written to the BlockedIp collection. Every incoming request is also checked against that collection before reaching any route handler.
Login Rate Limiting
TheappLimiterLogin limiter guards the login endpoint against credential-stuffing and brute-force attacks.
Window
5 minutes (
windowMs: 5 * 60 * 1000)Attempt Limit
5 attempts per IP per window (
limit: 5)| Violation number | Extra wait (minutes) |
|---|---|
| 1st | 5 |
| 2nd | 10 |
| 3rd | 15 |
| nth | 5 + (n-1) * 5 |
Retry-After header (in seconds) and a 429 status:
ipKeyGenerator from express-rate-limit, so each IP address is tracked independently.
Registration Rate Limiting
TheappLimiterRegister limiter tracks registration attempts by a composite key of `IP address + deviceId cookie**:
Attempt is counted
Each request increments the in-memory counter for the
IP-deviceId key. The last 5 email addresses used from that device are kept in a rolling buffer.Limit reached (5 attempts)
When
entry.count >= 5, the middleware checks whether this IP+deviceId pair already exists in the BlockedIp MongoDB collection.New block is persisted
If no record exists, a new
BlockedIp document is created, capturing the IP, deviceId, email, the list of attempted emails, and the block timestamp.Block Checker Middleware
TheblockChecker middleware (blockCheckMiddleware) runs on every request that passes through the user router. It performs a MongoDB lookup to check whether the current IP and deviceId combination has been permanently banned:
next() is called and the request continues normally.
Reset Middleware
TheresetCounters middleware is applied at the top of the User router to perform in-memory housekeeping. On each request it iterates over the requestCounts and blockTimes Maps and removes any entries whose block window has expired:
BlockedIp Schema
Permanently blocked devices are stored in theBlockedIp MongoDB collection. The schema is defined as follows:
ip
The IPv4/IPv6 address of the blocked client, as resolved by Express.
deviceId
The value of the
deviceId cookie sent by the client at the time of blocking.The email address from the request body at the time of the final, blocking attempt.
emailsIntentados
A rolling array of up to 5 email addresses that were attempted from this device before the block was triggered.
blockTime
The
Date at which the block was created. Defaults to Date.now() at schema definition time; the timestamps option also adds createdAt and updatedAt.Rate Limit Response Headers
TuKit configuresexpress-rate-limit with:
| Header set | Behaviour |
|---|---|
RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset | Sent — standardHeaders: true enables RFC 6585-style headers on every rate-limited response. |
X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset | Suppressed — legacyHeaders: false disables the older X-RateLimit-* prefixed headers. |
RateLimit-Reset header (Unix epoch seconds) to know when their window resets, and Retry-After (seconds) on 429 responses to know how long to back off.