@webdecoy/node 0.18.1 → 0.18.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.
@@ -775,22 +775,73 @@ var DEFAULT_TRIPWIRE_PATHS = [
775
775
  "/actuator/env",
776
776
  "/.vscode/sftp.json"
777
777
  ];
778
- function normalizePath(path) {
779
- return path.split("?")[0].split("#")[0];
778
+ function canonicalizeTripwirePath(path) {
779
+ const noQuery = path.split("?")[0].split("#")[0];
780
+ return cleanSlashesAndDots(decodePercentAscii(noQuery));
781
+ }
782
+ function decodePercentAscii(s) {
783
+ for (let i = 0; i < 4; i++) {
784
+ const next = decodePercentAsciiOnce(s);
785
+ if (next === s) break;
786
+ s = next;
787
+ }
788
+ return s;
789
+ }
790
+ function decodePercentAsciiOnce(s) {
791
+ if (!s.includes("%")) return s;
792
+ let out = "";
793
+ for (let i = 0; i < s.length; i++) {
794
+ if (s[i] === "%" && i + 2 < s.length) {
795
+ const hi = unhexNibble(s.charCodeAt(i + 1));
796
+ const lo = unhexNibble(s.charCodeAt(i + 2));
797
+ if (hi >= 0 && lo >= 0) {
798
+ const v = hi << 4 | lo;
799
+ if (v < 128) {
800
+ out += String.fromCharCode(v);
801
+ i += 2;
802
+ continue;
803
+ }
804
+ }
805
+ }
806
+ out += s[i];
807
+ }
808
+ return out;
809
+ }
810
+ function unhexNibble(c) {
811
+ if (c >= 48 && c <= 57) return c - 48;
812
+ if (c >= 97 && c <= 102) return c - 97 + 10;
813
+ if (c >= 65 && c <= 70) return c - 65 + 10;
814
+ return -1;
815
+ }
816
+ function cleanSlashesAndDots(s) {
817
+ if (s === "") return s;
818
+ const hadTrailing = s.length > 1 && s[s.length - 1] === "/";
819
+ const stack = [];
820
+ for (const p of s.split("/")) {
821
+ if (p === "" || p === ".") continue;
822
+ if (p === "..") {
823
+ if (stack.length > 0) stack.pop();
824
+ continue;
825
+ }
826
+ stack.push(p);
827
+ }
828
+ let res = "/" + stack.join("/");
829
+ if (hadTrailing && res !== "/") res += "/";
830
+ return res;
780
831
  }
781
832
  var TripwireRule = class {
782
833
  constructor(config = {}) {
783
834
  this.name = "tripwire";
784
835
  const paths = [...config.paths ?? []];
785
836
  if (config.includeDefaults ?? true) paths.push(...DEFAULT_TRIPWIRE_PATHS);
786
- this.exact = new Set(paths);
787
- this.prefixes = config.prefixes ?? [];
837
+ this.exact = new Set(paths.map(canonicalizeTripwirePath));
838
+ this.prefixes = (config.prefixes ?? []).map(canonicalizeTripwirePath);
788
839
  this.patterns = config.patterns ?? [];
789
840
  this.action = config.action ?? "DENY";
790
841
  this.dryRun = config.dryRun ?? false;
791
842
  }
792
843
  evaluate(context) {
793
- const path = normalizePath(context.path);
844
+ const path = canonicalizeTripwirePath(context.path);
794
845
  const hit = this.exact.has(path) || this.prefixes.some((prefix) => path.startsWith(prefix)) || this.patterns.some((re) => re.test(path));
795
846
  if (hit) {
796
847
  return {
package/dist/index.js CHANGED
@@ -1180,22 +1180,73 @@ var DEFAULT_TRIPWIRE_PATHS = [
1180
1180
  "/actuator/env",
1181
1181
  "/.vscode/sftp.json"
1182
1182
  ];
1183
- function normalizePath(path) {
1184
- return path.split("?")[0].split("#")[0];
1183
+ function canonicalizeTripwirePath(path) {
1184
+ const noQuery = path.split("?")[0].split("#")[0];
1185
+ return cleanSlashesAndDots(decodePercentAscii(noQuery));
1186
+ }
1187
+ function decodePercentAscii(s) {
1188
+ for (let i = 0; i < 4; i++) {
1189
+ const next = decodePercentAsciiOnce(s);
1190
+ if (next === s) break;
1191
+ s = next;
1192
+ }
1193
+ return s;
1194
+ }
1195
+ function decodePercentAsciiOnce(s) {
1196
+ if (!s.includes("%")) return s;
1197
+ let out = "";
1198
+ for (let i = 0; i < s.length; i++) {
1199
+ if (s[i] === "%" && i + 2 < s.length) {
1200
+ const hi = unhexNibble(s.charCodeAt(i + 1));
1201
+ const lo = unhexNibble(s.charCodeAt(i + 2));
1202
+ if (hi >= 0 && lo >= 0) {
1203
+ const v = hi << 4 | lo;
1204
+ if (v < 128) {
1205
+ out += String.fromCharCode(v);
1206
+ i += 2;
1207
+ continue;
1208
+ }
1209
+ }
1210
+ }
1211
+ out += s[i];
1212
+ }
1213
+ return out;
1214
+ }
1215
+ function unhexNibble(c) {
1216
+ if (c >= 48 && c <= 57) return c - 48;
1217
+ if (c >= 97 && c <= 102) return c - 97 + 10;
1218
+ if (c >= 65 && c <= 70) return c - 65 + 10;
1219
+ return -1;
1220
+ }
1221
+ function cleanSlashesAndDots(s) {
1222
+ if (s === "") return s;
1223
+ const hadTrailing = s.length > 1 && s[s.length - 1] === "/";
1224
+ const stack = [];
1225
+ for (const p of s.split("/")) {
1226
+ if (p === "" || p === ".") continue;
1227
+ if (p === "..") {
1228
+ if (stack.length > 0) stack.pop();
1229
+ continue;
1230
+ }
1231
+ stack.push(p);
1232
+ }
1233
+ let res = "/" + stack.join("/");
1234
+ if (hadTrailing && res !== "/") res += "/";
1235
+ return res;
1185
1236
  }
1186
1237
  var TripwireRule = class {
1187
1238
  constructor(config = {}) {
1188
1239
  this.name = "tripwire";
1189
1240
  const paths = [...config.paths ?? []];
1190
1241
  if (config.includeDefaults ?? true) paths.push(...DEFAULT_TRIPWIRE_PATHS);
1191
- this.exact = new Set(paths);
1192
- this.prefixes = config.prefixes ?? [];
1242
+ this.exact = new Set(paths.map(canonicalizeTripwirePath));
1243
+ this.prefixes = (config.prefixes ?? []).map(canonicalizeTripwirePath);
1193
1244
  this.patterns = config.patterns ?? [];
1194
1245
  this.action = config.action ?? "DENY";
1195
1246
  this.dryRun = config.dryRun ?? false;
1196
1247
  }
1197
1248
  evaluate(context) {
1198
- const path = normalizePath(context.path);
1249
+ const path = canonicalizeTripwirePath(context.path);
1199
1250
  const hit = this.exact.has(path) || this.prefixes.some((prefix) => path.startsWith(prefix)) || this.patterns.some((re) => re.test(path));
1200
1251
  if (hit) {
1201
1252
  return {
package/dist/index.mjs CHANGED
@@ -54,7 +54,7 @@ import {
54
54
  tripwire,
55
55
  upstashRateLimitStore,
56
56
  webBotAuth
57
- } from "./chunk-JV5P2YEA.mjs";
57
+ } from "./chunk-QP3WOPWJ.mjs";
58
58
 
59
59
  // src/client-ip.ts
60
60
  var IPV4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
package/dist/testing.js CHANGED
@@ -445,22 +445,73 @@ var DEFAULT_TRIPWIRE_PATHS = [
445
445
  "/actuator/env",
446
446
  "/.vscode/sftp.json"
447
447
  ];
448
- function normalizePath(path) {
449
- return path.split("?")[0].split("#")[0];
448
+ function canonicalizeTripwirePath(path) {
449
+ const noQuery = path.split("?")[0].split("#")[0];
450
+ return cleanSlashesAndDots(decodePercentAscii(noQuery));
451
+ }
452
+ function decodePercentAscii(s) {
453
+ for (let i = 0; i < 4; i++) {
454
+ const next = decodePercentAsciiOnce(s);
455
+ if (next === s) break;
456
+ s = next;
457
+ }
458
+ return s;
459
+ }
460
+ function decodePercentAsciiOnce(s) {
461
+ if (!s.includes("%")) return s;
462
+ let out = "";
463
+ for (let i = 0; i < s.length; i++) {
464
+ if (s[i] === "%" && i + 2 < s.length) {
465
+ const hi = unhexNibble(s.charCodeAt(i + 1));
466
+ const lo = unhexNibble(s.charCodeAt(i + 2));
467
+ if (hi >= 0 && lo >= 0) {
468
+ const v = hi << 4 | lo;
469
+ if (v < 128) {
470
+ out += String.fromCharCode(v);
471
+ i += 2;
472
+ continue;
473
+ }
474
+ }
475
+ }
476
+ out += s[i];
477
+ }
478
+ return out;
479
+ }
480
+ function unhexNibble(c) {
481
+ if (c >= 48 && c <= 57) return c - 48;
482
+ if (c >= 97 && c <= 102) return c - 97 + 10;
483
+ if (c >= 65 && c <= 70) return c - 65 + 10;
484
+ return -1;
485
+ }
486
+ function cleanSlashesAndDots(s) {
487
+ if (s === "") return s;
488
+ const hadTrailing = s.length > 1 && s[s.length - 1] === "/";
489
+ const stack = [];
490
+ for (const p of s.split("/")) {
491
+ if (p === "" || p === ".") continue;
492
+ if (p === "..") {
493
+ if (stack.length > 0) stack.pop();
494
+ continue;
495
+ }
496
+ stack.push(p);
497
+ }
498
+ let res = "/" + stack.join("/");
499
+ if (hadTrailing && res !== "/") res += "/";
500
+ return res;
450
501
  }
451
502
  var TripwireRule = class {
452
503
  constructor(config = {}) {
453
504
  this.name = "tripwire";
454
505
  const paths = [...config.paths ?? []];
455
506
  if (config.includeDefaults ?? true) paths.push(...DEFAULT_TRIPWIRE_PATHS);
456
- this.exact = new Set(paths);
457
- this.prefixes = config.prefixes ?? [];
507
+ this.exact = new Set(paths.map(canonicalizeTripwirePath));
508
+ this.prefixes = (config.prefixes ?? []).map(canonicalizeTripwirePath);
458
509
  this.patterns = config.patterns ?? [];
459
510
  this.action = config.action ?? "DENY";
460
511
  this.dryRun = config.dryRun ?? false;
461
512
  }
462
513
  evaluate(context) {
463
- const path = normalizePath(context.path);
514
+ const path = canonicalizeTripwirePath(context.path);
464
515
  const hit = this.exact.has(path) || this.prefixes.some((prefix) => path.startsWith(prefix)) || this.patterns.some((re) => re.test(path));
465
516
  if (hit) {
466
517
  return {
package/dist/testing.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  WebDecoy,
3
3
  silentLogger
4
- } from "./chunk-JV5P2YEA.mjs";
4
+ } from "./chunk-QP3WOPWJ.mjs";
5
5
 
6
6
  // src/testing.ts
7
7
  function request(over = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webdecoy/node",
3
- "version": "0.18.1",
3
+ "version": "0.18.3",
4
4
  "description": "Web Decoy SDK for Node.js - Bot detection with TLS fingerprinting",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",