@arcis/node 1.1.0 → 1.2.0

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 (50) hide show
  1. package/README.md +156 -211
  2. package/dist/core/index.d.mts +4 -4
  3. package/dist/core/index.d.ts +4 -4
  4. package/dist/core/index.js +13 -2
  5. package/dist/core/index.js.map +1 -1
  6. package/dist/core/index.mjs +13 -2
  7. package/dist/core/index.mjs.map +1 -1
  8. package/dist/{index-CslcoZUN.d.mts → index-A-m-pPeW.d.mts} +1 -1
  9. package/dist/{index-CCcPuTBo.d.mts → index-CgK94hY_.d.mts} +96 -2
  10. package/dist/{index-iCOw8Fcg.d.ts → index-Co5kPRZz.d.ts} +1 -1
  11. package/dist/{index-BvcFpoR3.d.ts → index-D_bdJcF0.d.ts} +96 -2
  12. package/dist/index.d.mts +4 -4
  13. package/dist/index.d.ts +4 -4
  14. package/dist/index.js +553 -5
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +540 -7
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/logging/index.d.mts +1 -1
  19. package/dist/logging/index.d.ts +1 -1
  20. package/dist/logging/index.js +12 -1
  21. package/dist/logging/index.js.map +1 -1
  22. package/dist/logging/index.mjs +12 -1
  23. package/dist/logging/index.mjs.map +1 -1
  24. package/dist/middleware/index.d.mts +2 -2
  25. package/dist/middleware/index.d.ts +2 -2
  26. package/dist/middleware/index.js +146 -4
  27. package/dist/middleware/index.js.map +1 -1
  28. package/dist/middleware/index.mjs +143 -5
  29. package/dist/middleware/index.mjs.map +1 -1
  30. package/dist/{headers-DBQedhrb.d.mts → pii-CXcHMlnX.d.mts} +156 -2
  31. package/dist/{headers-BJq2OA0i.d.ts → pii-DhNpl7M3.d.ts} +156 -2
  32. package/dist/sanitizers/index.d.mts +2 -2
  33. package/dist/sanitizers/index.d.ts +2 -2
  34. package/dist/sanitizers/index.js +331 -3
  35. package/dist/sanitizers/index.js.map +1 -1
  36. package/dist/sanitizers/index.mjs +321 -4
  37. package/dist/sanitizers/index.mjs.map +1 -1
  38. package/dist/stores/index.d.mts +1 -1
  39. package/dist/stores/index.d.ts +1 -1
  40. package/dist/stores/index.js.map +1 -1
  41. package/dist/stores/index.mjs.map +1 -1
  42. package/dist/{types-BOdL3ZWo.d.mts → types-CsOFHoD9.d.mts} +6 -1
  43. package/dist/{types-BOdL3ZWo.d.ts → types-CsOFHoD9.d.ts} +6 -1
  44. package/dist/validation/index.d.mts +2 -2
  45. package/dist/validation/index.d.ts +2 -2
  46. package/dist/validation/index.js +105 -3
  47. package/dist/validation/index.js.map +1 -1
  48. package/dist/validation/index.mjs +105 -3
  49. package/dist/validation/index.mjs.map +1 -1
  50. package/package.json +114 -114
@@ -74,7 +74,11 @@ var SQL_PATTERNS = [
74
74
  /** Time-based blind: SLEEP() */
75
75
  /\bSLEEP\s*\(\s*\d+\s*\)/gi,
76
76
  /** Time-based blind: BENCHMARK() */
77
- /\bBENCHMARK\s*\(/gi
77
+ /\bBENCHMARK\s*\(/gi,
78
+ /** Time-based blind: PostgreSQL pg_sleep() */
79
+ /\bpg_sleep\s*\(/gi,
80
+ /** Time-based blind: MSSQL WAITFOR DELAY */
81
+ /\bWAITFOR\s+DELAY\b/gi
78
82
  ];
79
83
  var PATH_PATTERNS = [
80
84
  /** Unix path traversal */
@@ -92,6 +96,10 @@ var PATH_PATTERNS = [
92
96
  /\.%2e[\\/]/gi,
93
97
  /** Fully URL-encoded: %2e%2e%2f */
94
98
  /%2e%2e%2f/gi,
99
+ /** Double URL-encoded forward slash: %252f */
100
+ /%252f/gi,
101
+ /** Dotdotslash bypass: ....// or ....\\ */
102
+ /\.{2,}[/\\]{2,}/g,
95
103
  /** Null byte injection in paths */
96
104
  /\0/g
97
105
  ];
@@ -107,7 +115,9 @@ var COMMAND_PATTERNS = [
107
115
  */
108
116
  /[;&|`]/g,
109
117
  /** Command substitution: $( ... ) — matched as a pair to reduce false positives */
110
- /\$\(/g
118
+ /\$\(/g,
119
+ /** URL-encoded newline/carriage-return injection (%0a, %0d) */
120
+ /%0[ad]/gi
111
121
  ];
112
122
  var DANGEROUS_PROTO_KEYS = /* @__PURE__ */ new Set([
113
123
  "__proto__",
@@ -141,6 +151,7 @@ var NOSQL_DANGEROUS_KEYS = /* @__PURE__ */ new Set([
141
151
  "$expr",
142
152
  "$mod",
143
153
  "$text",
154
+ "$jsonSchema",
144
155
  // Array
145
156
  "$elemMatch",
146
157
  "$all",
@@ -430,7 +441,8 @@ function sanitizeObject(obj, options = {}) {
430
441
  if (typeof obj === "string") return sanitizeString(obj, options);
431
442
  if (typeof obj !== "object") return obj;
432
443
  if (Array.isArray(obj)) return obj.map((item) => sanitizeObject(item, options));
433
- return sanitizeObjectDepth(obj, options, 0);
444
+ const result = sanitizeObjectDepth(obj, options, 0);
445
+ return options.freeze ? Object.freeze(result) : result;
434
446
  }
435
447
  function sanitizeObjectDepth(obj, options, depth) {
436
448
  if (depth >= INPUT.MAX_RECURSION_DEPTH) return obj;
@@ -533,6 +545,179 @@ function getDangerousProtoKeys() {
533
545
  return Array.from(DANGEROUS_PROTO_KEYS);
534
546
  }
535
547
 
548
+ // src/sanitizers/ssti.ts
549
+ var SSTI_DETECT_PATTERNS = [
550
+ /** Jinja2 / Twig / Nunjucks: {{ ... }} */
551
+ /\{\{.*?\}\}/g,
552
+ /** Freemarker / Thymeleaf / Spring EL: ${ ... } */
553
+ /\$\{.*?\}/g,
554
+ /** ERB / EJS: <%= ... %> or <% ... %> */
555
+ /<%[=\-]?.*?%>/gs,
556
+ /** Pug / Jade / Slim: #{ ... } */
557
+ /#\{.*?\}/g,
558
+ /** Python dunder sandbox escape */
559
+ /__(?:class|mro|subclasses|globals|builtins|import)__/gi,
560
+ /** Jinja2 config leak: {{config.X}} or {{config['X']}} */
561
+ /\{\{\s*config[.\[]/gi,
562
+ /** Jinja2 built-in objects */
563
+ /\{\{\s*(?:self|request|lipsum|cycler|joiner|namespace|range)\b/gi
564
+ ];
565
+ var SSTI_REMOVE_PATTERNS = [
566
+ /\{\{.*?\}\}/g,
567
+ /\$\{.*?\}/g,
568
+ /<%[=\-]?.*?%>/gs,
569
+ /#\{.*?\}/g,
570
+ /__(?:class|mro|subclasses|globals|builtins|import)__/gi
571
+ ];
572
+ function sanitizeSsti(input, collectThreats = false) {
573
+ if (typeof input !== "string") {
574
+ return collectThreats ? { value: String(input), wasSanitized: false, threats: [] } : String(input);
575
+ }
576
+ const threats = [];
577
+ let value = input;
578
+ let wasSanitized = false;
579
+ for (const pattern of SSTI_REMOVE_PATTERNS) {
580
+ pattern.lastIndex = 0;
581
+ if (pattern.test(value)) {
582
+ pattern.lastIndex = 0;
583
+ if (collectThreats) {
584
+ const matches = value.match(pattern);
585
+ if (matches) {
586
+ for (const match of matches) {
587
+ threats.push({
588
+ type: "ssti",
589
+ pattern: pattern.source,
590
+ original: match
591
+ });
592
+ }
593
+ }
594
+ }
595
+ value = value.replace(pattern, "");
596
+ wasSanitized = true;
597
+ }
598
+ }
599
+ if (collectThreats) {
600
+ return { value, wasSanitized, threats };
601
+ }
602
+ return value;
603
+ }
604
+ function detectSsti(input) {
605
+ if (typeof input !== "string") return false;
606
+ for (const pattern of SSTI_DETECT_PATTERNS) {
607
+ pattern.lastIndex = 0;
608
+ if (pattern.test(input)) {
609
+ return true;
610
+ }
611
+ }
612
+ return false;
613
+ }
614
+
615
+ // src/sanitizers/xxe.ts
616
+ var XXE_DETECT_PATTERNS = [
617
+ /** DOCTYPE declaration */
618
+ /<!DOCTYPE\b/gi,
619
+ /** ENTITY declaration */
620
+ /<!ENTITY\b/gi,
621
+ /** SYSTEM keyword with URI */
622
+ /\bSYSTEM\s+["']/gi,
623
+ /** PUBLIC keyword with URI */
624
+ /\bPUBLIC\s+["']/gi,
625
+ /** Parameter entity reference (%entity;) */
626
+ /%\s*\w+\s*;/g,
627
+ /** CDATA section (often used to smuggle payloads) */
628
+ /<!\[CDATA\[/gi
629
+ ];
630
+ var XXE_REMOVE_PATTERNS = [
631
+ /** Full DOCTYPE block with optional internal subset: <!DOCTYPE ... [...]> */
632
+ /<!DOCTYPE\s[^[>]*(?:\[[^\]]*\]\s*)?>|<!DOCTYPE\s[^>]*>/gi,
633
+ /** Full ENTITY declaration: <!ENTITY ... > */
634
+ /<!ENTITY[^>]*>/gi,
635
+ /** CDATA sections: <![CDATA[ ... ]]> */
636
+ /<!\[CDATA\[[\s\S]*?\]\]>/gi
637
+ ];
638
+ function sanitizeXxe(input, collectThreats = false) {
639
+ if (typeof input !== "string") {
640
+ return collectThreats ? { value: String(input), wasSanitized: false, threats: [] } : String(input);
641
+ }
642
+ const threats = [];
643
+ let value = input;
644
+ let wasSanitized = false;
645
+ for (const pattern of XXE_REMOVE_PATTERNS) {
646
+ pattern.lastIndex = 0;
647
+ if (pattern.test(value)) {
648
+ pattern.lastIndex = 0;
649
+ if (collectThreats) {
650
+ const matches = value.match(pattern);
651
+ if (matches) {
652
+ for (const match of matches) {
653
+ threats.push({
654
+ type: "xxe",
655
+ pattern: pattern.source,
656
+ original: match
657
+ });
658
+ }
659
+ }
660
+ }
661
+ value = value.replace(pattern, "");
662
+ wasSanitized = true;
663
+ }
664
+ }
665
+ if (collectThreats) {
666
+ return { value, wasSanitized, threats };
667
+ }
668
+ return value;
669
+ }
670
+ function detectXxe(input) {
671
+ if (typeof input !== "string") return false;
672
+ for (const pattern of XXE_DETECT_PATTERNS) {
673
+ pattern.lastIndex = 0;
674
+ if (pattern.test(input)) {
675
+ return true;
676
+ }
677
+ }
678
+ return false;
679
+ }
680
+
681
+ // src/sanitizers/jsonp.ts
682
+ var SAFE_CALLBACK_PATTERN = /^[a-zA-Z_$][a-zA-Z0-9_$.[\]]*$/;
683
+ var DANGEROUS_CALLBACK_PATTERNS = [
684
+ /\.\./,
685
+ // prototype chain traversal
686
+ /\[\s*\]/
687
+ // empty bracket access
688
+ ];
689
+ function sanitizeJsonpCallback(callback, maxLength = 128) {
690
+ if (typeof callback !== "string" || callback.length === 0) {
691
+ return null;
692
+ }
693
+ if (callback.length > maxLength) {
694
+ return null;
695
+ }
696
+ if (!SAFE_CALLBACK_PATTERN.test(callback)) {
697
+ return null;
698
+ }
699
+ for (const pattern of DANGEROUS_CALLBACK_PATTERNS) {
700
+ if (pattern.test(callback)) {
701
+ return null;
702
+ }
703
+ }
704
+ return callback;
705
+ }
706
+ function detectJsonpInjection(callback) {
707
+ if (typeof callback !== "string" || callback.length === 0) {
708
+ return false;
709
+ }
710
+ if (!SAFE_CALLBACK_PATTERN.test(callback)) {
711
+ return true;
712
+ }
713
+ for (const pattern of DANGEROUS_CALLBACK_PATTERNS) {
714
+ if (pattern.test(callback)) {
715
+ return true;
716
+ }
717
+ }
718
+ return false;
719
+ }
720
+
536
721
  // src/sanitizers/headers.ts
537
722
  var HEADER_INJECTION_PATTERN = /\r\n|\r|\n|\0/g;
538
723
  function sanitizeHeaderValue(input, collectThreats = false) {
@@ -582,6 +767,138 @@ function detectHeaderInjection(input) {
582
767
  return HEADER_INJECTION_PATTERN.test(input);
583
768
  }
584
769
 
585
- export { createSanitizer, detectCommandInjection, detectHeaderInjection, detectNoSqlInjection, detectPathTraversal, detectPrototypePollution, detectSql, detectXss, encodeHtmlEntities, getDangerousOperators, getDangerousProtoKeys, isDangerousNoSqlKey, isDangerousProtoKey, isPlainObject, sanitizeCommand, sanitizeHeaderValue, sanitizeHeaders, sanitizeObject, sanitizePath, sanitizeSql, sanitizeString, sanitizeXss };
770
+ // src/sanitizers/pii.ts
771
+ var EMAIL_RE = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z]{2,})+/g;
772
+ var PHONE_RE = /(?:\+?1[-.\s]?)?\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}/g;
773
+ var CREDIT_CARD_RE = /\b(?:\d[ -]*?){13,19}\b/g;
774
+ var SSN_RE = /\b\d{3}[-\s]\d{2}[-\s]\d{4}\b/g;
775
+ var IPV4_RE = /\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b/g;
776
+ var IPV6_RE = /\b(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\b|\b(?:[0-9a-fA-F]{1,4}:){1,7}:|::(?:[0-9a-fA-F]{1,4}:){0,5}[0-9a-fA-F]{1,4}\b/g;
777
+ var PATTERN_MAP = {
778
+ email: [EMAIL_RE],
779
+ phone: [PHONE_RE],
780
+ credit_card: [CREDIT_CARD_RE],
781
+ ssn: [SSN_RE],
782
+ ip_address: [IPV4_RE, IPV6_RE]
783
+ };
784
+ var ALL_TYPES = ["email", "phone", "credit_card", "ssn", "ip_address"];
785
+ var TYPE_LABELS = {
786
+ email: "[EMAIL]",
787
+ phone: "[PHONE]",
788
+ credit_card: "[CREDIT_CARD]",
789
+ ssn: "[SSN]",
790
+ ip_address: "[IP_ADDRESS]"
791
+ };
792
+ function luhnCheck(value) {
793
+ const digits = value.replace(/[\s-]/g, "");
794
+ if (!/^\d{13,19}$/.test(digits)) return false;
795
+ let sum = 0;
796
+ let alternate = false;
797
+ for (let i = digits.length - 1; i >= 0; i--) {
798
+ let n = parseInt(digits[i], 10);
799
+ if (alternate) {
800
+ n *= 2;
801
+ if (n > 9) n -= 9;
802
+ }
803
+ sum += n;
804
+ alternate = !alternate;
805
+ }
806
+ return sum % 10 === 0;
807
+ }
808
+ function scanPii(input, options = {}) {
809
+ if (!input || typeof input !== "string") return [];
810
+ const types = options.types ?? ALL_TYPES;
811
+ const matches = [];
812
+ for (const type of types) {
813
+ const patterns = PATTERN_MAP[type];
814
+ if (!patterns) continue;
815
+ for (const pattern of patterns) {
816
+ const re = new RegExp(pattern.source, pattern.flags);
817
+ let match;
818
+ while ((match = re.exec(input)) !== null) {
819
+ const value = match[0];
820
+ if (type === "credit_card" && !luhnCheck(value)) continue;
821
+ if (type === "ssn") {
822
+ const area = parseInt(value.substring(0, 3), 10);
823
+ if (area === 0 || area === 666 || area >= 900) continue;
824
+ }
825
+ matches.push({
826
+ type,
827
+ value,
828
+ start: match.index,
829
+ end: match.index + value.length
830
+ });
831
+ }
832
+ }
833
+ }
834
+ matches.sort((a, b) => a.start - b.start);
835
+ return matches;
836
+ }
837
+ function detectPii(input, options = {}) {
838
+ return scanPii(input, options).length > 0;
839
+ }
840
+ function redactPii(input, options = {}) {
841
+ if (!input || typeof input !== "string") return input;
842
+ const matches = scanPii(input, options);
843
+ if (matches.length === 0) return input;
844
+ const replacement = options.replacement ?? "[REDACTED]";
845
+ let result = input;
846
+ for (let i = matches.length - 1; i >= 0; i--) {
847
+ const m = matches[i];
848
+ const label = options.typeLabels ? TYPE_LABELS[m.type] : replacement;
849
+ result = result.substring(0, m.start) + label + result.substring(m.end);
850
+ }
851
+ return result;
852
+ }
853
+ function scanObjectPii(obj, options = {}, path = "") {
854
+ const results = [];
855
+ if (!obj || typeof obj !== "object") return results;
856
+ for (const [key, value] of Object.entries(obj)) {
857
+ const fieldPath = path ? `${path}.${key}` : key;
858
+ if (typeof value === "string") {
859
+ const matches = scanPii(value, options);
860
+ for (const m of matches) {
861
+ results.push({ ...m, field: fieldPath });
862
+ }
863
+ } else if (value && typeof value === "object" && !Array.isArray(value)) {
864
+ results.push(...scanObjectPii(value, options, fieldPath));
865
+ } else if (Array.isArray(value)) {
866
+ for (let i = 0; i < value.length; i++) {
867
+ const item = value[i];
868
+ if (typeof item === "string") {
869
+ const matches = scanPii(item, options);
870
+ for (const m of matches) {
871
+ results.push({ ...m, field: `${fieldPath}[${i}]` });
872
+ }
873
+ } else if (item && typeof item === "object") {
874
+ results.push(...scanObjectPii(item, options, `${fieldPath}[${i}]`));
875
+ }
876
+ }
877
+ }
878
+ }
879
+ return results;
880
+ }
881
+ function redactObjectPii(obj, options = {}) {
882
+ if (!obj || typeof obj !== "object") return obj;
883
+ const result = {};
884
+ for (const [key, value] of Object.entries(obj)) {
885
+ if (typeof value === "string") {
886
+ result[key] = redactPii(value, options);
887
+ } else if (Array.isArray(value)) {
888
+ result[key] = value.map((item) => {
889
+ if (typeof item === "string") return redactPii(item, options);
890
+ if (item && typeof item === "object") return redactObjectPii(item, options);
891
+ return item;
892
+ });
893
+ } else if (value && typeof value === "object") {
894
+ result[key] = redactObjectPii(value, options);
895
+ } else {
896
+ result[key] = value;
897
+ }
898
+ }
899
+ return result;
900
+ }
901
+
902
+ export { createSanitizer, detectCommandInjection, detectHeaderInjection, detectJsonpInjection, detectNoSqlInjection, detectPathTraversal, detectPii, detectPrototypePollution, detectSql, detectSsti, detectXss, detectXxe, encodeHtmlEntities, getDangerousOperators, getDangerousProtoKeys, isDangerousNoSqlKey, isDangerousProtoKey, isPlainObject, redactObjectPii, redactPii, sanitizeCommand, sanitizeHeaderValue, sanitizeHeaders, sanitizeJsonpCallback, sanitizeObject, sanitizePath, sanitizeSql, sanitizeSsti, sanitizeString, sanitizeXss, sanitizeXxe, scanObjectPii, scanPii };
586
903
  //# sourceMappingURL=index.mjs.map
587
904
  //# sourceMappingURL=index.mjs.map