@arcis/node 1.6.1 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/_third_party/rate-limit/abstract.d.ts +36 -0
- package/dist/_third_party/rate-limit/abstract.d.ts.map +1 -0
- package/dist/_third_party/rate-limit/bursty.d.ts +21 -0
- package/dist/_third_party/rate-limit/bursty.d.ts.map +1 -0
- package/dist/_third_party/rate-limit/index.d.ts +12 -0
- package/dist/_third_party/rate-limit/index.d.ts.map +1 -0
- package/dist/_third_party/rate-limit/memory-storage.d.ts +28 -0
- package/dist/_third_party/rate-limit/memory-storage.d.ts.map +1 -0
- package/dist/_third_party/rate-limit/memory.d.ts +23 -0
- package/dist/_third_party/rate-limit/memory.d.ts.map +1 -0
- package/dist/_third_party/rate-limit/record.d.ts +11 -0
- package/dist/_third_party/rate-limit/record.d.ts.map +1 -0
- package/dist/_third_party/rate-limit/types.d.ts +39 -0
- package/dist/_third_party/rate-limit/types.d.ts.map +1 -0
- package/dist/astro/index.js +405 -0
- package/dist/astro/index.js.map +1 -1
- package/dist/astro/index.mjs +405 -0
- package/dist/astro/index.mjs.map +1 -1
- package/dist/bun/index.js +405 -0
- package/dist/bun/index.js.map +1 -1
- package/dist/bun/index.mjs +405 -0
- package/dist/bun/index.mjs.map +1 -1
- package/dist/fastify/index.js +405 -0
- package/dist/fastify/index.js.map +1 -1
- package/dist/fastify/index.mjs +405 -0
- package/dist/fastify/index.mjs.map +1 -1
- package/dist/hono/index.js +405 -0
- package/dist/hono/index.js.map +1 -1
- package/dist/hono/index.mjs +405 -0
- package/dist/hono/index.mjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +754 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +754 -6
- package/dist/index.mjs.map +1 -1
- package/dist/koa/index.js +405 -0
- package/dist/koa/index.js.map +1 -1
- package/dist/koa/index.mjs +405 -0
- package/dist/koa/index.mjs.map +1 -1
- package/dist/middleware/brute-force.d.ts +69 -0
- package/dist/middleware/brute-force.d.ts.map +1 -0
- package/dist/middleware/index.js +702 -1
- package/dist/middleware/index.js.map +1 -1
- package/dist/middleware/index.mjs +702 -1
- package/dist/middleware/index.mjs.map +1 -1
- package/dist/middleware/nestjs.d.ts +50 -1
- package/dist/middleware/nestjs.d.ts.map +1 -1
- package/dist/middleware/protect.d.ts +9 -0
- package/dist/middleware/protect.d.ts.map +1 -1
- package/dist/nestjs/index.js +57 -2
- package/dist/nestjs/index.js.map +1 -1
- package/dist/nestjs/index.mjs +57 -3
- package/dist/nestjs/index.mjs.map +1 -1
- package/dist/nextjs/index.js +405 -0
- package/dist/nextjs/index.js.map +1 -1
- package/dist/nextjs/index.mjs +405 -0
- package/dist/nextjs/index.mjs.map +1 -1
- package/dist/nuxt/index.js +405 -0
- package/dist/nuxt/index.js.map +1 -1
- package/dist/nuxt/index.mjs +405 -0
- package/dist/nuxt/index.mjs.map +1 -1
- package/dist/sanitizers/index.js +2 -1
- package/dist/sanitizers/index.js.map +1 -1
- package/dist/sanitizers/index.mjs +2 -1
- package/dist/sanitizers/index.mjs.map +1 -1
- package/dist/sanitizers/ldap.d.ts.map +1 -1
- package/dist/sanitizers/prompt-injection.d.ts +3 -3
- package/dist/sanitizers/prompt-injection.d.ts.map +1 -1
- package/dist/sveltekit/index.js +405 -0
- package/dist/sveltekit/index.js.map +1 -1
- package/dist/sveltekit/index.mjs +405 -0
- package/dist/sveltekit/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arcis/node/middleware/brute-force
|
|
3
|
+
*
|
|
4
|
+
* Brute-force protection middleware built on the bursty limiter
|
|
5
|
+
* primitive. Designed for login + password-reset endpoints where the
|
|
6
|
+
* defense isn't just "X requests per minute" but "if this IP keeps
|
|
7
|
+
* trying after the rate-limit window resets, block it for longer".
|
|
8
|
+
*
|
|
9
|
+
* Two-tier semantics:
|
|
10
|
+
* - Steady-state: `fastPoints` consumes per `fastDuration` seconds.
|
|
11
|
+
* Once exhausted, normal traffic gets a 429 until the window
|
|
12
|
+
* resets.
|
|
13
|
+
* - Brute-force: `slowPoints` failed attempts over `slowDuration`
|
|
14
|
+
* seconds trips a `blockDuration` semi-permanent block.
|
|
15
|
+
*
|
|
16
|
+
* The middleware only consumes on `next()` by default, meaning every
|
|
17
|
+
* request counts, even successful ones. Pass `{ consumeOn: 'failure' }`
|
|
18
|
+
* plus a custom `failure` predicate to count only failed responses.
|
|
19
|
+
* The handler also exposes `req.arcisBruteForce.reward(key)` / `.delete(key)`
|
|
20
|
+
* to let the application reset counters on successful login.
|
|
21
|
+
*/
|
|
22
|
+
import type { Request, RequestHandler } from 'express';
|
|
23
|
+
import type { IRateLimiterRes } from '../_third_party/rate-limit';
|
|
24
|
+
export interface BruteForceOptions {
|
|
25
|
+
/** Points allowed in the fast window. */
|
|
26
|
+
fastPoints?: number;
|
|
27
|
+
/** Fast window length in seconds. */
|
|
28
|
+
fastDuration?: number;
|
|
29
|
+
/** Points allowed in the slow window. */
|
|
30
|
+
slowPoints?: number;
|
|
31
|
+
/** Slow window length in seconds. */
|
|
32
|
+
slowDuration?: number;
|
|
33
|
+
/** Seconds to semi-permanently block a key after slow-window exhaustion. */
|
|
34
|
+
blockDuration?: number;
|
|
35
|
+
/** Custom key resolver. Defaults to client IP. */
|
|
36
|
+
keyGenerator?: (req: Request) => string;
|
|
37
|
+
/** HTTP status to return when blocked. */
|
|
38
|
+
statusCode?: number;
|
|
39
|
+
/** Response message when blocked. */
|
|
40
|
+
message?: string;
|
|
41
|
+
/** Skip predicate. Return true to bypass the limiter for this request. */
|
|
42
|
+
skip?: (req: Request) => boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface BruteForceController {
|
|
45
|
+
/** Reset the failure counter for a key (call after successful auth). */
|
|
46
|
+
reward(key: string, points?: number): Promise<IRateLimiterRes>;
|
|
47
|
+
/** Drop the key entirely. */
|
|
48
|
+
delete(key: string): Promise<boolean>;
|
|
49
|
+
/** Inspect the current counter without consuming. */
|
|
50
|
+
get(key: string): Promise<IRateLimiterRes | null>;
|
|
51
|
+
/** Manually trip the block (e.g. after N suspicious logins). */
|
|
52
|
+
block(key: string, secDuration: number): Promise<IRateLimiterRes>;
|
|
53
|
+
}
|
|
54
|
+
declare global {
|
|
55
|
+
namespace Express {
|
|
56
|
+
interface Request {
|
|
57
|
+
arcisBruteForce?: BruteForceController;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Build a brute-force middleware backed by a bursty limiter. The
|
|
63
|
+
* returned function is an Express RequestHandler with a `controller`
|
|
64
|
+
* property exposing reward/delete/get/block for the application layer.
|
|
65
|
+
*/
|
|
66
|
+
export declare function bruteForceProtection(options?: BruteForceOptions): RequestHandler & {
|
|
67
|
+
controller: BruteForceController;
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=brute-force.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brute-force.d.ts","sourceRoot":"","sources":["../../src/middleware/brute-force.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAA0B,cAAc,EAAE,MAAM,SAAS,CAAC;AAE/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,MAAM,WAAW,iBAAiB;IAChC,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kDAAkD;IAClD,YAAY,CAAC,EAA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