@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.
Files changed (75) hide show
  1. package/README.md +5 -3
  2. package/dist/_third_party/rate-limit/abstract.d.ts +36 -0
  3. package/dist/_third_party/rate-limit/abstract.d.ts.map +1 -0
  4. package/dist/_third_party/rate-limit/bursty.d.ts +21 -0
  5. package/dist/_third_party/rate-limit/bursty.d.ts.map +1 -0
  6. package/dist/_third_party/rate-limit/index.d.ts +12 -0
  7. package/dist/_third_party/rate-limit/index.d.ts.map +1 -0
  8. package/dist/_third_party/rate-limit/memory-storage.d.ts +28 -0
  9. package/dist/_third_party/rate-limit/memory-storage.d.ts.map +1 -0
  10. package/dist/_third_party/rate-limit/memory.d.ts +23 -0
  11. package/dist/_third_party/rate-limit/memory.d.ts.map +1 -0
  12. package/dist/_third_party/rate-limit/record.d.ts +11 -0
  13. package/dist/_third_party/rate-limit/record.d.ts.map +1 -0
  14. package/dist/_third_party/rate-limit/types.d.ts +39 -0
  15. package/dist/_third_party/rate-limit/types.d.ts.map +1 -0
  16. package/dist/astro/index.js +405 -0
  17. package/dist/astro/index.js.map +1 -1
  18. package/dist/astro/index.mjs +405 -0
  19. package/dist/astro/index.mjs.map +1 -1
  20. package/dist/bun/index.js +405 -0
  21. package/dist/bun/index.js.map +1 -1
  22. package/dist/bun/index.mjs +405 -0
  23. package/dist/bun/index.mjs.map +1 -1
  24. package/dist/fastify/index.js +405 -0
  25. package/dist/fastify/index.js.map +1 -1
  26. package/dist/fastify/index.mjs +405 -0
  27. package/dist/fastify/index.mjs.map +1 -1
  28. package/dist/hono/index.js +405 -0
  29. package/dist/hono/index.js.map +1 -1
  30. package/dist/hono/index.mjs +405 -0
  31. package/dist/hono/index.mjs.map +1 -1
  32. package/dist/index.d.ts +2 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +754 -5
  35. package/dist/index.js.map +1 -1
  36. package/dist/index.mjs +754 -6
  37. package/dist/index.mjs.map +1 -1
  38. package/dist/koa/index.js +405 -0
  39. package/dist/koa/index.js.map +1 -1
  40. package/dist/koa/index.mjs +405 -0
  41. package/dist/koa/index.mjs.map +1 -1
  42. package/dist/middleware/brute-force.d.ts +69 -0
  43. package/dist/middleware/brute-force.d.ts.map +1 -0
  44. package/dist/middleware/index.js +702 -1
  45. package/dist/middleware/index.js.map +1 -1
  46. package/dist/middleware/index.mjs +702 -1
  47. package/dist/middleware/index.mjs.map +1 -1
  48. package/dist/middleware/nestjs.d.ts +50 -1
  49. package/dist/middleware/nestjs.d.ts.map +1 -1
  50. package/dist/middleware/protect.d.ts +9 -0
  51. package/dist/middleware/protect.d.ts.map +1 -1
  52. package/dist/nestjs/index.js +57 -2
  53. package/dist/nestjs/index.js.map +1 -1
  54. package/dist/nestjs/index.mjs +57 -3
  55. package/dist/nestjs/index.mjs.map +1 -1
  56. package/dist/nextjs/index.js +405 -0
  57. package/dist/nextjs/index.js.map +1 -1
  58. package/dist/nextjs/index.mjs +405 -0
  59. package/dist/nextjs/index.mjs.map +1 -1
  60. package/dist/nuxt/index.js +405 -0
  61. package/dist/nuxt/index.js.map +1 -1
  62. package/dist/nuxt/index.mjs +405 -0
  63. package/dist/nuxt/index.mjs.map +1 -1
  64. package/dist/sanitizers/index.js +2 -1
  65. package/dist/sanitizers/index.js.map +1 -1
  66. package/dist/sanitizers/index.mjs +2 -1
  67. package/dist/sanitizers/index.mjs.map +1 -1
  68. package/dist/sanitizers/ldap.d.ts.map +1 -1
  69. package/dist/sanitizers/prompt-injection.d.ts +3 -3
  70. package/dist/sanitizers/prompt-injection.d.ts.map +1 -1
  71. package/dist/sveltekit/index.js +405 -0
  72. package/dist/sveltekit/index.js.map +1 -1
  73. package/dist/sveltekit/index.mjs +405 -0
  74. package/dist/sveltekit/index.mjs.map +1 -1
  75. package/package.json +2 -2
@@ -945,9 +945,10 @@ function detectXxe(input) {
945
945
  // src/sanitizers/ldap.ts
946
946
  var LDAP_DETECT_PATTERN = /[*()\\\x00]/;
947
947
  var LDAP_INJECTION_PATTERN = /\)\s*\(|\*\s*\)\s*\(/;
948
+ var LDAP_NOT_BYPASS_PATTERN = /\)\s*\(\s*!|&\s*\(\s*!|\|\s*\(\s*!/;
948
949
  function detectLdapInjection(input) {
949
950
  if (typeof input !== "string") return false;
950
- return LDAP_DETECT_PATTERN.test(input) || LDAP_INJECTION_PATTERN.test(input);
951
+ return LDAP_DETECT_PATTERN.test(input) || LDAP_INJECTION_PATTERN.test(input) || LDAP_NOT_BYPASS_PATTERN.test(input);
951
952
  }
952
953
 
953
954
  // src/sanitizers/xpath.ts
@@ -8274,6 +8275,411 @@ var bot_patterns_default = [
8274
8275
  "ZuperlistBot\\/"
8275
8276
  ],
8276
8277
  forbidden: []
8278
+ },
8279
+ {
8280
+ id: "ext-ahrefsbotsiteaudit",
8281
+ name: "ahrefsbotsiteaudit",
8282
+ category: "SEO",
8283
+ patterns: [
8284
+ "Ahrefs(Bot|SiteAudit)"
8285
+ ],
8286
+ forbidden: []
8287
+ },
8288
+ {
8289
+ id: "ext-amazonproductdiscovery",
8290
+ name: "amazonproductdiscovery",
8291
+ category: "SEARCH_ENGINE",
8292
+ patterns: [
8293
+ "AmazonProductDiscovery"
8294
+ ],
8295
+ forbidden: []
8296
+ },
8297
+ {
8298
+ id: "ext-amazonsellerinitiatedlisting",
8299
+ name: "amazonsellerinitiatedlisting",
8300
+ category: "SEARCH_ENGINE",
8301
+ patterns: [
8302
+ "AmazonSellerInitiatedListing"
8303
+ ],
8304
+ forbidden: []
8305
+ },
8306
+ {
8307
+ id: "ext-cclaudebbot",
8308
+ name: "cclaudebbot",
8309
+ category: "GENERIC",
8310
+ patterns: [
8311
+ "[cC]laude[bB]ot"
8312
+ ],
8313
+ forbidden: []
8314
+ },
8315
+ {
8316
+ id: "ext-meta-externalagent",
8317
+ name: "meta-externalagent",
8318
+ category: "GENERIC",
8319
+ patterns: [
8320
+ "meta-externalagent\\/"
8321
+ ],
8322
+ forbidden: []
8323
+ },
8324
+ {
8325
+ id: "ext-meta-externalfetcher",
8326
+ name: "meta-externalfetcher",
8327
+ category: "GENERIC",
8328
+ patterns: [
8329
+ "meta-externalfetcher\\/"
8330
+ ],
8331
+ forbidden: []
8332
+ },
8333
+ {
8334
+ id: "ext-hydrozenio",
8335
+ name: "hydrozenio",
8336
+ category: "MONITORING",
8337
+ patterns: [
8338
+ "Hydrozen\\.io"
8339
+ ],
8340
+ forbidden: []
8341
+ },
8342
+ {
8343
+ id: "ext-yextbot",
8344
+ name: "yextbot",
8345
+ category: "SEO",
8346
+ patterns: [
8347
+ "YextBot\\/"
8348
+ ],
8349
+ forbidden: []
8350
+ },
8351
+ {
8352
+ id: "ext-datadogsynthetics",
8353
+ name: "datadogsynthetics",
8354
+ category: "MONITORING",
8355
+ patterns: [
8356
+ "DatadogSynthetics"
8357
+ ],
8358
+ forbidden: []
8359
+ },
8360
+ {
8361
+ id: "ext-observepoint",
8362
+ name: "observepoint",
8363
+ category: "MONITORING",
8364
+ patterns: [
8365
+ "ObservePoint"
8366
+ ],
8367
+ forbidden: []
8368
+ },
8369
+ {
8370
+ id: "ext-checkly",
8371
+ name: "checkly",
8372
+ category: "MONITORING",
8373
+ patterns: [
8374
+ "Checkly"
8375
+ ],
8376
+ forbidden: []
8377
+ },
8378
+ {
8379
+ id: "ext-alittleclient",
8380
+ name: "alittleclient",
8381
+ category: "GENERIC",
8382
+ patterns: [
8383
+ "ALittle Client"
8384
+ ],
8385
+ forbidden: []
8386
+ },
8387
+ {
8388
+ id: "ext-aliyunsecbot",
8389
+ name: "aliyunsecbot",
8390
+ category: "GENERIC",
8391
+ patterns: [
8392
+ "AliyunSecBot"
8393
+ ],
8394
+ forbidden: []
8395
+ },
8396
+ {
8397
+ id: "ext-claude-web",
8398
+ name: "claude-web",
8399
+ category: "GENERIC",
8400
+ patterns: [
8401
+ "Claude-Web"
8402
+ ],
8403
+ forbidden: []
8404
+ },
8405
+ {
8406
+ id: "ext-google-extended",
8407
+ name: "google-extended",
8408
+ category: "GENERIC",
8409
+ patterns: [
8410
+ "Google-Extended"
8411
+ ],
8412
+ forbidden: []
8413
+ },
8414
+ {
8415
+ id: "ext-serankingbacklinksbot",
8416
+ name: "serankingbacklinksbot",
8417
+ category: "SEO",
8418
+ patterns: [
8419
+ "SERankingBacklinksBot"
8420
+ ],
8421
+ forbidden: []
8422
+ },
8423
+ {
8424
+ id: "ext-cmschecker",
8425
+ name: "cmschecker",
8426
+ category: "SEO",
8427
+ patterns: [
8428
+ "CMSChecker"
8429
+ ],
8430
+ forbidden: []
8431
+ },
8432
+ {
8433
+ id: "ext-wayback",
8434
+ name: "wayback",
8435
+ category: "GENERIC",
8436
+ patterns: [
8437
+ "Wayback"
8438
+ ],
8439
+ forbidden: []
8440
+ },
8441
+ {
8442
+ id: "ext-playwright",
8443
+ name: "playwright",
8444
+ category: "GENERIC",
8445
+ patterns: [
8446
+ "Playwright"
8447
+ ],
8448
+ forbidden: []
8449
+ },
8450
+ {
8451
+ id: "ext-puppeteer",
8452
+ name: "puppeteer",
8453
+ category: "GENERIC",
8454
+ patterns: [
8455
+ "Puppeteer"
8456
+ ],
8457
+ forbidden: []
8458
+ },
8459
+ {
8460
+ id: "ext-selenium",
8461
+ name: "selenium",
8462
+ category: "GENERIC",
8463
+ patterns: [
8464
+ "Selenium"
8465
+ ],
8466
+ forbidden: []
8467
+ },
8468
+ {
8469
+ id: "ext-nikto",
8470
+ name: "nikto",
8471
+ category: "GENERIC",
8472
+ patterns: [
8473
+ "Nikto"
8474
+ ],
8475
+ forbidden: []
8476
+ },
8477
+ {
8478
+ id: "ext-sqlmap",
8479
+ name: "sqlmap",
8480
+ category: "GENERIC",
8481
+ patterns: [
8482
+ "sqlmap"
8483
+ ],
8484
+ forbidden: []
8485
+ },
8486
+ {
8487
+ id: "ext-zmeu",
8488
+ name: "zmeu",
8489
+ category: "GENERIC",
8490
+ patterns: [
8491
+ "ZmEu"
8492
+ ],
8493
+ forbidden: []
8494
+ },
8495
+ {
8496
+ id: "ext-masscan",
8497
+ name: "masscan",
8498
+ category: "GENERIC",
8499
+ patterns: [
8500
+ "masscan"
8501
+ ],
8502
+ forbidden: []
8503
+ },
8504
+ {
8505
+ id: "ext-wpscan",
8506
+ name: "wpscan",
8507
+ category: "GENERIC",
8508
+ patterns: [
8509
+ "WPScan"
8510
+ ],
8511
+ forbidden: []
8512
+ },
8513
+ {
8514
+ id: "ext-aacunetix",
8515
+ name: "aacunetix",
8516
+ category: "GENERIC",
8517
+ patterns: [
8518
+ "[aA]cunetix"
8519
+ ],
8520
+ forbidden: []
8521
+ },
8522
+ {
8523
+ id: "ext-nessus",
8524
+ name: "nessus",
8525
+ category: "GENERIC",
8526
+ patterns: [
8527
+ "Nessus"
8528
+ ],
8529
+ forbidden: []
8530
+ },
8531
+ {
8532
+ id: "ext-ddirbbuster",
8533
+ name: "ddirbbuster",
8534
+ category: "GENERIC",
8535
+ patterns: [
8536
+ "[dD]ir[Bb]uster"
8537
+ ],
8538
+ forbidden: []
8539
+ },
8540
+ {
8541
+ id: "ext-colly",
8542
+ name: "colly",
8543
+ category: "GENERIC",
8544
+ patterns: [
8545
+ "colly"
8546
+ ],
8547
+ forbidden: []
8548
+ },
8549
+ {
8550
+ id: "ext-mmechanize",
8551
+ name: "mmechanize",
8552
+ category: "GENERIC",
8553
+ patterns: [
8554
+ "[mM]echanize"
8555
+ ],
8556
+ forbidden: []
8557
+ },
8558
+ {
8559
+ id: "ext-airaiscanning",
8560
+ name: "airaiscanning",
8561
+ category: "GENERIC",
8562
+ patterns: [
8563
+ "air\\.ai\\/scanning"
8564
+ ],
8565
+ forbidden: []
8566
+ },
8567
+ {
8568
+ id: "ext-asnriskscorer",
8569
+ name: "asnriskscorer",
8570
+ category: "GENERIC",
8571
+ patterns: [
8572
+ "asnriskscorer"
8573
+ ],
8574
+ forbidden: []
8575
+ },
8576
+ {
8577
+ id: "ext-oicrawler",
8578
+ name: "oicrawler",
8579
+ category: "SEARCH_ENGINE",
8580
+ patterns: [
8581
+ "OICrawler"
8582
+ ],
8583
+ forbidden: []
8584
+ },
8585
+ {
8586
+ id: "ext-l9scan",
8587
+ name: "l9scan",
8588
+ category: "GENERIC",
8589
+ patterns: [
8590
+ "l9scan"
8591
+ ],
8592
+ forbidden: []
8593
+ },
8594
+ {
8595
+ id: "ext-slaccalebot",
8596
+ name: "slaccalebot",
8597
+ category: "SEO",
8598
+ patterns: [
8599
+ "SlaccaleBot"
8600
+ ],
8601
+ forbidden: []
8602
+ },
8603
+ {
8604
+ id: "ext-customasynchttpclient",
8605
+ name: "customasynchttpclient",
8606
+ category: "GENERIC",
8607
+ patterns: [
8608
+ "CustomAsyncHttpClient"
8609
+ ],
8610
+ forbidden: []
8611
+ },
8612
+ {
8613
+ id: "ext-gemini-deep-research",
8614
+ name: "gemini-deep-research",
8615
+ category: "SEARCH_ENGINE",
8616
+ patterns: [
8617
+ "Gemini-Deep-Research"
8618
+ ],
8619
+ forbidden: []
8620
+ },
8621
+ {
8622
+ id: "ext-perplexity-user",
8623
+ name: "perplexity-user",
8624
+ category: "SEARCH_ENGINE",
8625
+ patterns: [
8626
+ "Perplexity-User"
8627
+ ],
8628
+ forbidden: []
8629
+ },
8630
+ {
8631
+ id: "ext-perplexityuser",
8632
+ name: "perplexityuser",
8633
+ category: "SEARCH_ENGINE",
8634
+ patterns: [
8635
+ "PerplexityUser"
8636
+ ],
8637
+ forbidden: []
8638
+ },
8639
+ {
8640
+ id: "ext-meta-webindexer",
8641
+ name: "meta-webindexer",
8642
+ category: "GENERIC",
8643
+ patterns: [
8644
+ "meta-webindexer"
8645
+ ],
8646
+ forbidden: []
8647
+ },
8648
+ {
8649
+ id: "ext-duckassistbot",
8650
+ name: "duckassistbot",
8651
+ category: "SEARCH_ENGINE",
8652
+ patterns: [
8653
+ "DuckAssistBot"
8654
+ ],
8655
+ forbidden: []
8656
+ },
8657
+ {
8658
+ id: "ext-mistralai-user",
8659
+ name: "mistralai-user",
8660
+ category: "GENERIC",
8661
+ patterns: [
8662
+ "MistralAI-User"
8663
+ ],
8664
+ forbidden: []
8665
+ },
8666
+ {
8667
+ id: "ext-webzio",
8668
+ name: "webzio",
8669
+ category: "SEO",
8670
+ patterns: [
8671
+ "webzio"
8672
+ ],
8673
+ forbidden: []
8674
+ },
8675
+ {
8676
+ id: "ext-newsai",
8677
+ name: "newsai",
8678
+ category: "GENERIC",
8679
+ patterns: [
8680
+ "newsai\\/"
8681
+ ],
8682
+ forbidden: []
8277
8683
  }
8278
8684
  ];
8279
8685
 
@@ -8810,6 +9216,297 @@ function massAssign(options) {
8810
9216
  };
8811
9217
  }
8812
9218
 
9219
+ // src/_third_party/rate-limit/abstract.ts
9220
+ var AbstractLimiter = class {
9221
+ constructor(opts) {
9222
+ if (!Number.isFinite(opts.points)) {
9223
+ throw new Error("points must be a finite number");
9224
+ }
9225
+ if (!Number.isFinite(opts.duration) || opts.duration < 0) {
9226
+ throw new Error("duration must be a finite, non-negative number");
9227
+ }
9228
+ this._points = opts.points;
9229
+ this._duration = opts.duration;
9230
+ this._blockDuration = typeof opts.blockDuration === "undefined" ? 0 : opts.blockDuration;
9231
+ this._execEvenly = Boolean(opts.execEvenly);
9232
+ this._execEvenlyMinDelayMs = typeof opts.execEvenlyMinDelayMs === "undefined" ? Math.ceil(this._duration * 1e3 / Math.max(this._points, 1)) : opts.execEvenlyMinDelayMs;
9233
+ if (typeof opts.keyPrefix === "undefined") {
9234
+ this._keyPrefix = "arcis";
9235
+ } else if (typeof opts.keyPrefix !== "string") {
9236
+ throw new Error("keyPrefix must be a string");
9237
+ } else {
9238
+ this._keyPrefix = opts.keyPrefix;
9239
+ }
9240
+ }
9241
+ get points() {
9242
+ return this._points;
9243
+ }
9244
+ get duration() {
9245
+ return this._duration;
9246
+ }
9247
+ get msDuration() {
9248
+ return this._duration * 1e3;
9249
+ }
9250
+ get blockDuration() {
9251
+ return this._blockDuration;
9252
+ }
9253
+ get msBlockDuration() {
9254
+ return this._blockDuration * 1e3;
9255
+ }
9256
+ get execEvenly() {
9257
+ return this._execEvenly;
9258
+ }
9259
+ get execEvenlyMinDelayMs() {
9260
+ return this._execEvenlyMinDelayMs;
9261
+ }
9262
+ get keyPrefix() {
9263
+ return this._keyPrefix;
9264
+ }
9265
+ _getKeySecDuration(options = {}) {
9266
+ return typeof options.customDuration === "number" && options.customDuration >= 0 ? options.customDuration : this._duration;
9267
+ }
9268
+ _getKey(key) {
9269
+ return this._keyPrefix.length > 0 ? `${this._keyPrefix}:${key}` : key;
9270
+ }
9271
+ };
9272
+
9273
+ // src/_third_party/rate-limit/types.ts
9274
+ var LimiterResult = class {
9275
+ constructor(remainingPoints = 0, msBeforeNext = 0, consumedPoints = 0, isFirstInDuration = false) {
9276
+ this.remainingPoints = remainingPoints;
9277
+ this.msBeforeNext = msBeforeNext;
9278
+ this.consumedPoints = consumedPoints;
9279
+ this.isFirstInDuration = isFirstInDuration;
9280
+ }
9281
+ };
9282
+
9283
+ // src/_third_party/rate-limit/record.ts
9284
+ var StorageRecord = class {
9285
+ constructor(value, expiresAt, timeoutId = null) {
9286
+ this.value = Math.trunc(value);
9287
+ this.expiresAt = expiresAt;
9288
+ this.timeoutId = timeoutId;
9289
+ }
9290
+ };
9291
+
9292
+ // src/_third_party/rate-limit/memory-storage.ts
9293
+ var MemoryStorage = class {
9294
+ constructor() {
9295
+ this._storage = /* @__PURE__ */ new Map();
9296
+ }
9297
+ /**
9298
+ * Increment the counter for `key` by `value`. If the key has no record
9299
+ * (or its TTL has expired), a new record is created with `durationSec`
9300
+ * lifetime.
9301
+ */
9302
+ incrby(key, value, durationSec) {
9303
+ const record = this._storage.get(key);
9304
+ if (record) {
9305
+ const msBeforeExpires = record.expiresAt ? record.expiresAt - Date.now() : -1;
9306
+ if (!record.expiresAt || msBeforeExpires > 0) {
9307
+ record.value = record.value + value;
9308
+ return new LimiterResult(0, msBeforeExpires, record.value, false);
9309
+ }
9310
+ return this.set(key, value, durationSec);
9311
+ }
9312
+ return this.set(key, value, durationSec);
9313
+ }
9314
+ /**
9315
+ * Write the counter for `key` to `value`, replacing any existing
9316
+ * record. `durationSec` of 0 means "never expires".
9317
+ */
9318
+ set(key, value, durationSec) {
9319
+ const durationMs = durationSec * 1e3;
9320
+ const existing = this._storage.get(key);
9321
+ if (existing && existing.timeoutId) {
9322
+ clearTimeout(existing.timeoutId);
9323
+ }
9324
+ const record = new StorageRecord(value, durationMs > 0 ? Date.now() + durationMs : null);
9325
+ this._storage.set(key, record);
9326
+ if (durationMs > 0) {
9327
+ record.timeoutId = setTimeout(() => {
9328
+ this._storage.delete(key);
9329
+ }, durationMs);
9330
+ if (typeof record.timeoutId.unref === "function") {
9331
+ record.timeoutId.unref();
9332
+ }
9333
+ }
9334
+ return new LimiterResult(0, durationMs === 0 ? -1 : durationMs, record.value, true);
9335
+ }
9336
+ get(key) {
9337
+ const record = this._storage.get(key);
9338
+ if (!record) return null;
9339
+ const msBeforeExpires = record.expiresAt ? record.expiresAt - Date.now() : -1;
9340
+ return new LimiterResult(0, msBeforeExpires, record.value, false);
9341
+ }
9342
+ delete(key) {
9343
+ const record = this._storage.get(key);
9344
+ if (!record) return false;
9345
+ if (record.timeoutId) {
9346
+ clearTimeout(record.timeoutId);
9347
+ }
9348
+ this._storage.delete(key);
9349
+ return true;
9350
+ }
9351
+ /** Inspect the underlying map. Test-only and not part of the public API. */
9352
+ _dump() {
9353
+ return this._storage.entries();
9354
+ }
9355
+ /** Clear all records. Used by tests and by `Limiter.dispose()`. */
9356
+ clear() {
9357
+ for (const record of this._storage.values()) {
9358
+ if (record.timeoutId) clearTimeout(record.timeoutId);
9359
+ }
9360
+ this._storage.clear();
9361
+ }
9362
+ };
9363
+
9364
+ // src/_third_party/rate-limit/memory.ts
9365
+ var MemoryLimiter = class extends AbstractLimiter {
9366
+ constructor(opts) {
9367
+ super(opts);
9368
+ this._storage = new MemoryStorage();
9369
+ }
9370
+ consume(key, pointsToConsume = 1, options = {}) {
9371
+ return new Promise((resolve2, reject) => {
9372
+ const rlKey = this._getKey(key);
9373
+ const secDuration = this._getKeySecDuration(options);
9374
+ let res = this._storage.incrby(rlKey, pointsToConsume, secDuration);
9375
+ res.remainingPoints = Math.max(this._points - res.consumedPoints, 0);
9376
+ if (res.consumedPoints > this._points) {
9377
+ if (this._blockDuration > 0 && res.consumedPoints <= this._points + pointsToConsume) {
9378
+ res = this._storage.set(rlKey, res.consumedPoints, this._blockDuration);
9379
+ }
9380
+ reject(res);
9381
+ return;
9382
+ }
9383
+ if (this._execEvenly && res.msBeforeNext > 0 && !res.isFirstInDuration) {
9384
+ let delay = Math.ceil(res.msBeforeNext / (res.remainingPoints + 2));
9385
+ if (delay < this._execEvenlyMinDelayMs) {
9386
+ delay = res.consumedPoints * this._execEvenlyMinDelayMs;
9387
+ }
9388
+ res.msBeforeNext = Math.max(res.msBeforeNext - delay, 0);
9389
+ setTimeout(resolve2, delay, res);
9390
+ return;
9391
+ }
9392
+ resolve2(res);
9393
+ });
9394
+ }
9395
+ penalty(key, points = 1, options = {}) {
9396
+ const rlKey = this._getKey(key);
9397
+ const secDuration = this._getKeySecDuration(options);
9398
+ const res = this._storage.incrby(rlKey, points, secDuration);
9399
+ res.remainingPoints = Math.max(this._points - res.consumedPoints, 0);
9400
+ return Promise.resolve(res);
9401
+ }
9402
+ reward(key, points = 1, options = {}) {
9403
+ const rlKey = this._getKey(key);
9404
+ const secDuration = this._getKeySecDuration(options);
9405
+ const res = this._storage.incrby(rlKey, -points, secDuration);
9406
+ res.remainingPoints = Math.max(this._points - res.consumedPoints, 0);
9407
+ return Promise.resolve(res);
9408
+ }
9409
+ block(key, secDuration) {
9410
+ const msDuration = secDuration * 1e3;
9411
+ const initPoints = this._points + 1;
9412
+ this._storage.set(this._getKey(key), initPoints, secDuration);
9413
+ return Promise.resolve(new LimiterResult(0, msDuration === 0 ? -1 : msDuration, initPoints, false));
9414
+ }
9415
+ get(key) {
9416
+ const res = this._storage.get(this._getKey(key));
9417
+ if (res !== null) {
9418
+ res.remainingPoints = Math.max(this._points - res.consumedPoints, 0);
9419
+ }
9420
+ return Promise.resolve(res);
9421
+ }
9422
+ delete(key) {
9423
+ return Promise.resolve(this._storage.delete(this._getKey(key)));
9424
+ }
9425
+ /** Test/teardown helper. Drops every key and clears timers. */
9426
+ dispose() {
9427
+ this._storage.clear();
9428
+ }
9429
+ };
9430
+
9431
+ // src/middleware/brute-force.ts
9432
+ function defaultKeyGenerator(req) {
9433
+ const xff = req.headers["x-forwarded-for"];
9434
+ if (typeof xff === "string" && xff.length > 0) {
9435
+ const first = xff.split(",")[0]?.trim();
9436
+ if (first) return first;
9437
+ }
9438
+ if (typeof req.ip === "string" && req.ip.length > 0) return req.ip;
9439
+ const remote = req.socket?.remoteAddress;
9440
+ return typeof remote === "string" && remote.length > 0 ? remote : "unknown";
9441
+ }
9442
+ function bruteForceProtection(options = {}) {
9443
+ const fastPoints = options.fastPoints ?? 5;
9444
+ const fastDuration = options.fastDuration ?? 60;
9445
+ const slowPoints = options.slowPoints ?? 20;
9446
+ const slowDuration = options.slowDuration ?? 900;
9447
+ const blockDuration = options.blockDuration ?? 900;
9448
+ const keyGenerator = options.keyGenerator ?? defaultKeyGenerator;
9449
+ const statusCode = options.statusCode ?? 429;
9450
+ const message = options.message ?? "Too many login attempts. Please try again later.";
9451
+ const skip = options.skip;
9452
+ const fast = new MemoryLimiter({
9453
+ points: fastPoints,
9454
+ duration: fastDuration,
9455
+ keyPrefix: "arcis:bf:fast"
9456
+ });
9457
+ const slow = new MemoryLimiter({
9458
+ points: slowPoints,
9459
+ duration: slowDuration,
9460
+ blockDuration,
9461
+ keyPrefix: "arcis:bf:slow"
9462
+ });
9463
+ const controller = {
9464
+ reward: (key, points = 1) => slow.reward(key, points),
9465
+ delete: async (key) => {
9466
+ const a = await fast.delete(key);
9467
+ const b = await slow.delete(key);
9468
+ return a || b;
9469
+ },
9470
+ get: (key) => slow.get(key),
9471
+ block: (key, secDuration) => slow.block(key, secDuration)
9472
+ };
9473
+ const handler = async (req, res, next) => {
9474
+ try {
9475
+ if (skip?.(req)) return next();
9476
+ const key = keyGenerator(req);
9477
+ req.arcisBruteForce = controller;
9478
+ const slowRes = await slow.consume(key, 1);
9479
+ const fastRes = await fast.consume(key, 1);
9480
+ res.setHeader("X-RateLimit-Limit", String(slowPoints));
9481
+ res.setHeader(
9482
+ "X-RateLimit-Remaining",
9483
+ String(Math.min(fastRes.remainingPoints, slowRes.remainingPoints))
9484
+ );
9485
+ res.setHeader(
9486
+ "X-RateLimit-Reset",
9487
+ String(Math.ceil(Math.max(slowRes.msBeforeNext, fastRes.msBeforeNext) / 1e3))
9488
+ );
9489
+ next();
9490
+ } catch (rejection) {
9491
+ if (rejection instanceof LimiterResult || isLimiterResultShape(rejection)) {
9492
+ const retryAfter = Math.ceil(rejection.msBeforeNext / 1e3);
9493
+ res.setHeader("X-RateLimit-Limit", String(slowPoints));
9494
+ res.setHeader("X-RateLimit-Remaining", "0");
9495
+ res.setHeader("X-RateLimit-Reset", String(retryAfter));
9496
+ res.setHeader("Retry-After", String(retryAfter));
9497
+ res.status(statusCode).json({ error: message, retryAfter });
9498
+ return;
9499
+ }
9500
+ console.error("[arcis] brute-force middleware error:", rejection);
9501
+ next();
9502
+ }
9503
+ };
9504
+ return Object.assign(handler, { controller });
9505
+ }
9506
+ function isLimiterResultShape(x) {
9507
+ return typeof x === "object" && x !== null && typeof x.consumedPoints === "number" && typeof x.msBeforeNext === "number";
9508
+ }
9509
+
8813
9510
  // src/middleware/protect.ts
8814
9511
  function getClientIp(req) {
8815
9512
  const xff = req?.headers?.["x-forwarded-for"] ?? req?.headers?.["X-Forwarded-For"];
@@ -8860,6 +9557,10 @@ function protectLogin(options = {}) {
8860
9557
  const middlewares = [];
8861
9558
  const rl = resolve(options.rateLimit, { max: 5, windowMs: 6e4 });
8862
9559
  if (rl) middlewares.push(createRateLimiter(rl));
9560
+ if (options.bruteForce) {
9561
+ const bfOpts = options.bruteForce === true ? {} : options.bruteForce;
9562
+ middlewares.push(bruteForceProtection(bfOpts));
9563
+ }
8863
9564
  const bot = resolve(options.bot, {
8864
9565
  deny: ["AUTOMATED"],
8865
9566
  statusCode: 403,