@oxog/vld 1.5.0 → 2.0.1
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/CHANGELOG.md +116 -0
- package/README.md +558 -517
- package/dist/chunks/bigint-ZKkWLdmi.js +1628 -0
- package/dist/chunks/bigint-ZKkWLdmi.js.map +1 -0
- package/dist/{coercion/string.js → chunks/date-7Iz2BGsL.js} +271 -5
- package/dist/chunks/date-7Iz2BGsL.js.map +1 -0
- package/dist/chunks/index-BoV-4S1F.js +894 -0
- package/dist/chunks/index-BoV-4S1F.js.map +1 -0
- package/dist/chunks/index-eWXdjyyy.js +426 -0
- package/dist/chunks/index-eWXdjyyy.js.map +1 -0
- package/dist/chunks/json-nIhyRPOU.js +1934 -0
- package/dist/chunks/json-nIhyRPOU.js.map +1 -0
- package/dist/{validators/unknown.js → chunks/unknown-CjSRcELI.js} +6 -3
- package/dist/chunks/unknown-CjSRcELI.js.map +1 -0
- package/dist/cjs/errors.cjs +387 -0
- package/dist/cjs/errors.cjs.map +1 -0
- package/dist/cjs/index.cjs +9815 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/locales/index.cjs +2877 -0
- package/dist/cjs/locales/index.cjs.map +1 -0
- package/dist/cjs/locales/lazy.cjs +3169 -0
- package/dist/cjs/locales/lazy.cjs.map +1 -0
- package/dist/cjs/mini.cjs +7161 -0
- package/dist/cjs/mini.cjs.map +1 -0
- package/dist/codecs/index.js +4 -275
- package/dist/codecs/index.js.map +1 -1
- package/dist/coercion/index.d.ts +11 -0
- package/dist/coercion/index.d.ts.map +1 -0
- package/dist/coercion/{bigint.js → index.js} +7 -4
- package/dist/coercion/index.js.map +1 -0
- package/dist/compat/emitter.js +6 -4
- package/dist/compat/emitter.js.map +1 -1
- package/dist/compat/result.js +21 -19
- package/dist/compat/result.js.map +1 -1
- package/dist/errors.js +13 -10
- package/dist/errors.js.map +1 -1
- package/dist/index.js +225 -126
- package/dist/index.js.map +1 -1
- package/dist/kernel.js +10 -7
- package/dist/kernel.js.map +1 -1
- package/dist/locales/af.js +4 -2
- package/dist/locales/af.js.map +1 -1
- package/dist/locales/ar.js +4 -2
- package/dist/locales/ar.js.map +1 -1
- package/dist/locales/bn.js +4 -2
- package/dist/locales/bn.js.map +1 -1
- package/dist/locales/da.js +4 -2
- package/dist/locales/da.js.map +1 -1
- package/dist/locales/de.js +4 -2
- package/dist/locales/de.js.map +1 -1
- package/dist/locales/en.js +4 -2
- package/dist/locales/en.js.map +1 -1
- package/dist/locales/es-MX.js +4 -2
- package/dist/locales/es-MX.js.map +1 -1
- package/dist/locales/es.js +4 -2
- package/dist/locales/es.js.map +1 -1
- package/dist/locales/fi.js +4 -2
- package/dist/locales/fi.js.map +1 -1
- package/dist/locales/fr.js +4 -2
- package/dist/locales/fr.js.map +1 -1
- package/dist/locales/hi.js +4 -2
- package/dist/locales/hi.js.map +1 -1
- package/dist/locales/id.js +4 -2
- package/dist/locales/id.js.map +1 -1
- package/dist/locales/index.js +3 -91
- package/dist/locales/index.js.map +1 -1
- package/dist/locales/it.js +4 -2
- package/dist/locales/it.js.map +1 -1
- package/dist/locales/ja.js +4 -2
- package/dist/locales/ja.js.map +1 -1
- package/dist/locales/ko.js +4 -2
- package/dist/locales/ko.js.map +1 -1
- package/dist/locales/lazy.d.ts +111 -0
- package/dist/locales/lazy.d.ts.map +1 -0
- package/dist/locales/lazy.js +220 -0
- package/dist/locales/lazy.js.map +1 -0
- package/dist/locales/nl.js +4 -2
- package/dist/locales/nl.js.map +1 -1
- package/dist/locales/no.js +4 -2
- package/dist/locales/no.js.map +1 -1
- package/dist/locales/pl.js +4 -2
- package/dist/locales/pl.js.map +1 -1
- package/dist/locales/pt-BR.js +4 -2
- package/dist/locales/pt-BR.js.map +1 -1
- package/dist/locales/pt.js +4 -2
- package/dist/locales/pt.js.map +1 -1
- package/dist/locales/ru.js +4 -2
- package/dist/locales/ru.js.map +1 -1
- package/dist/locales/sv.js +4 -2
- package/dist/locales/sv.js.map +1 -1
- package/dist/locales/sw.js +4 -2
- package/dist/locales/sw.js.map +1 -1
- package/dist/locales/th.js +4 -2
- package/dist/locales/th.js.map +1 -1
- package/dist/locales/tr.js +4 -2
- package/dist/locales/tr.js.map +1 -1
- package/dist/locales/vi.js +4 -2
- package/dist/locales/vi.js.map +1 -1
- package/dist/locales/zh.js +4 -2
- package/dist/locales/zh.js.map +1 -1
- package/dist/mini.d.ts +182 -0
- package/dist/mini.d.ts.map +1 -0
- package/dist/mini.js +132 -0
- package/dist/mini.js.map +1 -0
- package/dist/pigment.js +8 -7
- package/dist/pigment.js.map +1 -1
- package/dist/validators/index.js +5 -45
- package/dist/validators/index.js.map +1 -1
- package/package.json +69 -11
- package/dist/cli/benchmark.d.ts +0 -15
- package/dist/cli/benchmark.d.ts.map +0 -1
- package/dist/cli/benchmark.js +0 -248
- package/dist/cli/benchmark.js.map +0 -1
- package/dist/cli/bin.js +0 -35
- package/dist/cli/bin.js.map +0 -1
- package/dist/cli/commands/benchmark.js +0 -204
- package/dist/cli/commands/benchmark.js.map +0 -1
- package/dist/cli/commands/validate.js +0 -157
- package/dist/cli/commands/validate.js.map +0 -1
- package/dist/cli/generate.d.ts +0 -14
- package/dist/cli/generate.d.ts.map +0 -1
- package/dist/cli/generate.js +0 -233
- package/dist/cli/generate.js.map +0 -1
- package/dist/cli/index.js +0 -182
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/validate.d.ts +0 -15
- package/dist/cli/validate.d.ts.map +0 -1
- package/dist/cli/validate.js +0 -162
- package/dist/cli/validate.js.map +0 -1
- package/dist/coercion/bigint.js.map +0 -1
- package/dist/coercion/boolean.js +0 -59
- package/dist/coercion/boolean.js.map +0 -1
- package/dist/coercion/date.js +0 -52
- package/dist/coercion/date.js.map +0 -1
- package/dist/coercion/number.js +0 -160
- package/dist/coercion/number.js.map +0 -1
- package/dist/coercion/string.js.map +0 -1
- package/dist/compat/index.js +0 -14
- package/dist/compat/index.js.map +0 -1
- package/dist/events.js +0 -8
- package/dist/events.js.map +0 -1
- package/dist/guards.d.ts +0 -143
- package/dist/guards.d.ts.map +0 -1
- package/dist/guards.js +0 -238
- package/dist/guards.js.map +0 -1
- package/dist/index-new.d.ts.map +0 -1
- package/dist/locales/backup-en.js +0 -105
- package/dist/locales/backup-en.js.map +0 -1
- package/dist/locales/types.js +0 -2
- package/dist/locales/types.js.map +0 -1
- package/dist/locales.d.ts +0 -54
- package/dist/locales.d.ts.map +0 -1
- package/dist/locales.js +0 -732
- package/dist/locales.js.map +0 -1
- package/dist/logger.js +0 -184
- package/dist/logger.js.map +0 -1
- package/dist/plugins/codecs.d.ts +0 -17
- package/dist/plugins/codecs.d.ts.map +0 -1
- package/dist/plugins/codecs.js +0 -29
- package/dist/plugins/codecs.js.map +0 -1
- package/dist/plugins/coercion.d.ts +0 -13
- package/dist/plugins/coercion.d.ts.map +0 -1
- package/dist/plugins/coercion.js +0 -34
- package/dist/plugins/coercion.js.map +0 -1
- package/dist/plugins/core-validators.d.ts +0 -13
- package/dist/plugins/core-validators.d.ts.map +0 -1
- package/dist/plugins/core-validators.js +0 -96
- package/dist/plugins/core-validators.js.map +0 -1
- package/dist/plugins/index.js +0 -8
- package/dist/plugins/index.js.map +0 -1
- package/dist/plugins/kernel.d.ts +0 -29
- package/dist/plugins/kernel.d.ts.map +0 -1
- package/dist/plugins/kernel.js +0 -486
- package/dist/plugins/kernel.js.map +0 -1
- package/dist/plugins/types.js +0 -8
- package/dist/plugins/types.js.map +0 -1
- package/dist/style.d.ts +0 -123
- package/dist/style.d.ts.map +0 -1
- package/dist/style.js +0 -369
- package/dist/style.js.map +0 -1
- package/dist/utils/codec-utils.js +0 -229
- package/dist/utils/codec-utils.js.map +0 -1
- package/dist/utils/deep-merge.js +0 -76
- package/dist/utils/deep-merge.js.map +0 -1
- package/dist/utils/ip-validation.js +0 -98
- package/dist/utils/ip-validation.js.map +0 -1
- package/dist/utils/security.js +0 -61
- package/dist/utils/security.js.map +0 -1
- package/dist/validators/any.js +0 -25
- package/dist/validators/any.js.map +0 -1
- package/dist/validators/array.js +0 -190
- package/dist/validators/array.js.map +0 -1
- package/dist/validators/base.js +0 -499
- package/dist/validators/base.js.map +0 -1
- package/dist/validators/base64.js +0 -65
- package/dist/validators/base64.js.map +0 -1
- package/dist/validators/bigint.js +0 -142
- package/dist/validators/bigint.js.map +0 -1
- package/dist/validators/boolean.js +0 -114
- package/dist/validators/boolean.js.map +0 -1
- package/dist/validators/codec.js +0 -182
- package/dist/validators/codec.js.map +0 -1
- package/dist/validators/custom.js +0 -50
- package/dist/validators/custom.js.map +0 -1
- package/dist/validators/date.js +0 -227
- package/dist/validators/date.js.map +0 -1
- package/dist/validators/discriminated-union.js +0 -98
- package/dist/validators/discriminated-union.js.map +0 -1
- package/dist/validators/enum.js +0 -82
- package/dist/validators/enum.js.map +0 -1
- package/dist/validators/file.js +0 -114
- package/dist/validators/file.js.map +0 -1
- package/dist/validators/function.js +0 -45
- package/dist/validators/function.js.map +0 -1
- package/dist/validators/hex.js +0 -62
- package/dist/validators/hex.js.map +0 -1
- package/dist/validators/intersection.js +0 -64
- package/dist/validators/intersection.js.map +0 -1
- package/dist/validators/json.js +0 -64
- package/dist/validators/json.js.map +0 -1
- package/dist/validators/lazy.js +0 -42
- package/dist/validators/lazy.js.map +0 -1
- package/dist/validators/literal.js +0 -45
- package/dist/validators/literal.js.map +0 -1
- package/dist/validators/map.js +0 -54
- package/dist/validators/map.js.map +0 -1
- package/dist/validators/nan.js +0 -32
- package/dist/validators/nan.js.map +0 -1
- package/dist/validators/never.js +0 -29
- package/dist/validators/never.js.map +0 -1
- package/dist/validators/null.js +0 -31
- package/dist/validators/null.js.map +0 -1
- package/dist/validators/number.js +0 -225
- package/dist/validators/number.js.map +0 -1
- package/dist/validators/object-optimized.d.ts +0 -23
- package/dist/validators/object-optimized.d.ts.map +0 -1
- package/dist/validators/object-optimized.js +0 -179
- package/dist/validators/object-optimized.js.map +0 -1
- package/dist/validators/object-ultra.d.ts +0 -34
- package/dist/validators/object-ultra.d.ts.map +0 -1
- package/dist/validators/object-ultra.js +0 -175
- package/dist/validators/object-ultra.js.map +0 -1
- package/dist/validators/object.js +0 -458
- package/dist/validators/object.js.map +0 -1
- package/dist/validators/record.js +0 -128
- package/dist/validators/record.js.map +0 -1
- package/dist/validators/set.js +0 -51
- package/dist/validators/set.js.map +0 -1
- package/dist/validators/string-bool.js +0 -127
- package/dist/validators/string-bool.js.map +0 -1
- package/dist/validators/string-formats.js +0 -120
- package/dist/validators/string-formats.js.map +0 -1
- package/dist/validators/string-ultra.d.ts +0 -49
- package/dist/validators/string-ultra.d.ts.map +0 -1
- package/dist/validators/string-ultra.js +0 -217
- package/dist/validators/string-ultra.js.map +0 -1
- package/dist/validators/string.js +0 -253
- package/dist/validators/string.js.map +0 -1
- package/dist/validators/symbol.js +0 -42
- package/dist/validators/symbol.js.map +0 -1
- package/dist/validators/template-literal.js +0 -102
- package/dist/validators/template-literal.js.map +0 -1
- package/dist/validators/tuple.js +0 -55
- package/dist/validators/tuple.js.map +0 -1
- package/dist/validators/uint8array.js +0 -98
- package/dist/validators/uint8array.js.map +0 -1
- package/dist/validators/undefined.js +0 -31
- package/dist/validators/undefined.js.map +0 -1
- package/dist/validators/union-optimized.d.ts +0 -15
- package/dist/validators/union-optimized.d.ts.map +0 -1
- package/dist/validators/union-optimized.js +0 -92
- package/dist/validators/union-optimized.js.map +0 -1
- package/dist/validators/union.js +0 -126
- package/dist/validators/union.js.map +0 -1
- package/dist/validators/unknown.js.map +0 -1
- package/dist/validators/void.js +0 -35
- package/dist/validators/void.js.map +0 -1
- package/dist/validators/xor.js +0 -64
- package/dist/validators/xor.js.map +0 -1
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for codec transformations
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Convert a base64 string to Uint8Array
|
|
6
|
-
*/
|
|
7
|
-
export function base64ToUint8Array(base64) {
|
|
8
|
-
// Handle URL-safe base64
|
|
9
|
-
const base64Clean = base64.replace(/-/g, '+').replace(/_/g, '/');
|
|
10
|
-
// Add padding if necessary
|
|
11
|
-
const padded = base64Clean.padEnd(base64Clean.length + (4 - base64Clean.length % 4) % 4, '=');
|
|
12
|
-
// Decode base64 to binary string
|
|
13
|
-
const binaryString = safeAtob(padded);
|
|
14
|
-
// Convert binary string to Uint8Array
|
|
15
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
16
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
17
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
18
|
-
}
|
|
19
|
-
return bytes;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Convert Uint8Array to base64 string
|
|
23
|
-
*/
|
|
24
|
-
export function uint8ArrayToBase64(bytes) {
|
|
25
|
-
// Convert Uint8Array to binary string
|
|
26
|
-
let binaryString = '';
|
|
27
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
28
|
-
binaryString += String.fromCharCode(bytes[i]);
|
|
29
|
-
}
|
|
30
|
-
// Encode to base64
|
|
31
|
-
return safeBtoa(binaryString);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Convert Uint8Array to URL-safe base64 string
|
|
35
|
-
*/
|
|
36
|
-
export function uint8ArrayToBase64Url(bytes) {
|
|
37
|
-
const base64 = uint8ArrayToBase64(bytes);
|
|
38
|
-
// Make URL-safe and remove padding
|
|
39
|
-
return base64
|
|
40
|
-
.replace(/\+/g, '-')
|
|
41
|
-
.replace(/\//g, '_')
|
|
42
|
-
.replace(/=/g, '');
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Convert hex string to Uint8Array
|
|
46
|
-
*/
|
|
47
|
-
export function hexToUint8Array(hex) {
|
|
48
|
-
// BUG-010 FIX: Add length validation to prevent memory exhaustion
|
|
49
|
-
// 20 million characters = 10MB of data (consistent with base64 limits)
|
|
50
|
-
if (hex.length > 20000000) {
|
|
51
|
-
throw new Error('Hex string is too large (max 10MB)');
|
|
52
|
-
}
|
|
53
|
-
// Remove any 0x prefix if present
|
|
54
|
-
const cleanHex = hex.startsWith('0x') ? hex.slice(2) : hex;
|
|
55
|
-
// BUG-NPM-006 FIX: Validate hex characters to prevent silent data corruption
|
|
56
|
-
// parseInt silently returns NaN for invalid hex, which becomes 0 in Uint8Array
|
|
57
|
-
const hexPattern = /^[0-9a-fA-F]*$/;
|
|
58
|
-
if (!hexPattern.test(cleanHex)) {
|
|
59
|
-
throw new Error('Invalid hex string: contains non-hexadecimal characters');
|
|
60
|
-
}
|
|
61
|
-
// Ensure even length
|
|
62
|
-
const paddedHex = cleanHex.length % 2 === 0 ? cleanHex : '0' + cleanHex;
|
|
63
|
-
const bytes = new Uint8Array(paddedHex.length / 2);
|
|
64
|
-
for (let i = 0; i < paddedHex.length; i += 2) {
|
|
65
|
-
bytes[i / 2] = parseInt(paddedHex.substring(i, i + 2), 16);
|
|
66
|
-
}
|
|
67
|
-
return bytes;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Convert Uint8Array to hex string
|
|
71
|
-
*/
|
|
72
|
-
export function uint8ArrayToHex(bytes) {
|
|
73
|
-
let hex = '';
|
|
74
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
75
|
-
const byte = bytes[i].toString(16);
|
|
76
|
-
hex += byte.length === 1 ? '0' + byte : byte;
|
|
77
|
-
}
|
|
78
|
-
return hex;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Convert string to Uint8Array using UTF-8 encoding
|
|
82
|
-
* BUG-NEW-011 FIX: Add DoS protection with 10MB limit
|
|
83
|
-
*/
|
|
84
|
-
export function stringToUint8Array(str) {
|
|
85
|
-
// Add DoS protection - limit to 10MB (consistent with base64 limit)
|
|
86
|
-
const MAX_STRING_LENGTH = 10000000; // 10 million characters (~10MB)
|
|
87
|
-
if (str.length > MAX_STRING_LENGTH) {
|
|
88
|
-
throw new Error(`String is too large for UTF-8 encoding (max ${MAX_STRING_LENGTH} characters)`);
|
|
89
|
-
}
|
|
90
|
-
const encoder = new TextEncoder();
|
|
91
|
-
return encoder.encode(str);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Convert Uint8Array to string using UTF-8 decoding
|
|
95
|
-
* BUG-NEW-012 FIX: Add DoS protection with 10MB limit
|
|
96
|
-
*/
|
|
97
|
-
export function uint8ArrayToString(bytes) {
|
|
98
|
-
// Add DoS protection - limit to 10MB
|
|
99
|
-
const MAX_BYTES_LENGTH = 10000000; // 10 million bytes
|
|
100
|
-
if (bytes.length > MAX_BYTES_LENGTH) {
|
|
101
|
-
throw new Error(`Byte array is too large for UTF-8 decoding (max ${MAX_BYTES_LENGTH} bytes)`);
|
|
102
|
-
}
|
|
103
|
-
const decoder = new TextDecoder();
|
|
104
|
-
return decoder.decode(bytes);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Check if running in Node.js environment
|
|
108
|
-
*/
|
|
109
|
-
export function isNodeEnvironment() {
|
|
110
|
-
return typeof globalThis !== 'undefined' &&
|
|
111
|
-
typeof globalThis.process !== 'undefined' &&
|
|
112
|
-
globalThis.process.versions != null &&
|
|
113
|
-
globalThis.process.versions.node != null;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Validate and sanitize base64 input to prevent prototype pollution
|
|
117
|
-
*/
|
|
118
|
-
function validateBase64Input(encoded) {
|
|
119
|
-
// Check for null/undefined
|
|
120
|
-
if (encoded == null) {
|
|
121
|
-
throw new Error('Base64 input cannot be null or undefined');
|
|
122
|
-
}
|
|
123
|
-
// Ensure it's a string
|
|
124
|
-
if (typeof encoded !== 'string') {
|
|
125
|
-
throw new Error('Base64 input must be a string');
|
|
126
|
-
}
|
|
127
|
-
// Length validation - base64 strings should be reasonable length
|
|
128
|
-
if (encoded.length > 10000000) { // 10MB limit
|
|
129
|
-
throw new Error('Base64 input is too large');
|
|
130
|
-
}
|
|
131
|
-
// Base64 character validation - only allow valid base64 characters
|
|
132
|
-
const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
133
|
-
if (!base64Regex.test(encoded)) {
|
|
134
|
-
throw new Error('Invalid base64 format');
|
|
135
|
-
}
|
|
136
|
-
// BUG-NEW-004 FIX: Correct base64 padding validation per RFC 4648
|
|
137
|
-
// Base64 only uses '=' or '==' as padding, never '==='
|
|
138
|
-
const paddingIndex = encoded.indexOf('=');
|
|
139
|
-
if (paddingIndex !== -1) {
|
|
140
|
-
const padding = encoded.substring(paddingIndex);
|
|
141
|
-
// Only allow '=' or '==' as valid padding (RFC 4648 compliant)
|
|
142
|
-
if (!/^={1,2}$/.test(padding)) {
|
|
143
|
-
throw new Error('Invalid base64 padding');
|
|
144
|
-
}
|
|
145
|
-
// Padding should only be at the end
|
|
146
|
-
if (paddingIndex < encoded.length - 2) {
|
|
147
|
-
throw new Error('Base64 padding must be at the end');
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
// Additional security check: prevent potential encoded JavaScript
|
|
151
|
-
// by looking for suspicious patterns that might indicate malicious content
|
|
152
|
-
const suspiciousPatterns = [
|
|
153
|
-
/eval/i,
|
|
154
|
-
/function/i,
|
|
155
|
-
/javascript:/i,
|
|
156
|
-
/<script/i,
|
|
157
|
-
/on\w+\s*=/i,
|
|
158
|
-
/__proto__/i,
|
|
159
|
-
/constructor/i,
|
|
160
|
-
/prototype/i
|
|
161
|
-
];
|
|
162
|
-
// Decode a small portion to check for suspicious content
|
|
163
|
-
try {
|
|
164
|
-
const sampleSize = Math.min(100, encoded.length);
|
|
165
|
-
const sample = encoded.substring(0, sampleSize);
|
|
166
|
-
const sampleDecoded = typeof atob !== 'undefined'
|
|
167
|
-
? atob(sample)
|
|
168
|
-
: Buffer.from(sample, 'base64').toString('utf8', 0, 50); // Only decode first 50 chars
|
|
169
|
-
for (const pattern of suspiciousPatterns) {
|
|
170
|
-
if (pattern.test(sampleDecoded)) {
|
|
171
|
-
throw new Error('Suspicious content detected in base64 input');
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
catch (error) {
|
|
176
|
-
if (error instanceof Error && error.message.includes('Suspicious content')) {
|
|
177
|
-
throw error;
|
|
178
|
-
}
|
|
179
|
-
// If decoding fails, continue - it might be invalid base64 which will be caught later
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Polyfill for atob in Node.js with proper input validation
|
|
184
|
-
*/
|
|
185
|
-
export function safeAtob(encoded) {
|
|
186
|
-
// Input validation and sanitization
|
|
187
|
-
validateBase64Input(encoded);
|
|
188
|
-
if (typeof atob !== 'undefined') {
|
|
189
|
-
try {
|
|
190
|
-
return atob(encoded);
|
|
191
|
-
}
|
|
192
|
-
catch (error) {
|
|
193
|
-
throw new Error('Failed to decode base64 data');
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
// Node.js fallback with additional validation
|
|
197
|
-
if (isNodeEnvironment()) {
|
|
198
|
-
try {
|
|
199
|
-
// Use Buffer with explicit error handling
|
|
200
|
-
const buffer = Buffer.from(encoded, 'base64');
|
|
201
|
-
// Additional validation: ensure the decoded data is reasonable size
|
|
202
|
-
if (buffer.length > 5000000) { // 5MB limit for decoded data
|
|
203
|
-
throw new Error('Decoded base64 data is too large');
|
|
204
|
-
}
|
|
205
|
-
return buffer.toString('binary');
|
|
206
|
-
}
|
|
207
|
-
catch (error) {
|
|
208
|
-
if (error instanceof Error && error.message.includes('Invalid base64')) {
|
|
209
|
-
throw new Error('Invalid base64 format');
|
|
210
|
-
}
|
|
211
|
-
throw new Error('Failed to decode base64 data in Node.js environment');
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
throw new Error('Base64 decoding not supported in this environment');
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Polyfill for btoa in Node.js
|
|
218
|
-
*/
|
|
219
|
-
export function safeBtoa(str) {
|
|
220
|
-
if (typeof btoa !== 'undefined') {
|
|
221
|
-
return btoa(str);
|
|
222
|
-
}
|
|
223
|
-
// Node.js fallback
|
|
224
|
-
if (isNodeEnvironment()) {
|
|
225
|
-
return Buffer.from(str, 'binary').toString('base64');
|
|
226
|
-
}
|
|
227
|
-
throw new Error('Base64 encoding not supported in this environment');
|
|
228
|
-
}
|
|
229
|
-
//# sourceMappingURL=codec-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codec-utils.js","sourceRoot":"","sources":["../../src/utils/codec-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAC/C,yBAAyB;IACzB,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAEjE,2BAA2B;IAC3B,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAE9F,iCAAiC;IACjC,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAEtC,sCAAsC;IACtC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7C,KAAK,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAiB;IAClD,sCAAsC;IACtC,IAAI,YAAY,GAAG,EAAE,CAAC;IACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAA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G;AACH,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IAED,mBAAmB;IACnB,IAAI,iBAAiB,EAAE,EAAE,CAAC;QACxB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;AACvE,CAAC","sourcesContent":["/**\r\n * Utility functions for codec transformations\r\n */\r\n\r\n/**\r\n * Convert a base64 string to Uint8Array\r\n */\r\nexport function base64ToUint8Array(base64: string): Uint8Array {\r\n // Handle URL-safe base64\r\n const base64Clean = base64.replace(/-/g, '+').replace(/_/g, '/');\r\n \r\n // Add padding if necessary\r\n const padded = base64Clean.padEnd(base64Clean.length + (4 - base64Clean.length % 4) % 4, '=');\r\n \r\n // Decode base64 to binary string\r\n const binaryString = safeAtob(padded);\r\n \r\n // Convert binary string to Uint8Array\r\n const bytes = new Uint8Array(binaryString.length);\r\n for (let i = 0; i < binaryString.length; i++) {\r\n bytes[i] = binaryString.charCodeAt(i);\r\n }\r\n \r\n return bytes;\r\n}\r\n\r\n/**\r\n * Convert Uint8Array to base64 string\r\n */\r\nexport function uint8ArrayToBase64(bytes: Uint8Array): string {\r\n // Convert Uint8Array to binary string\r\n let binaryString = '';\r\n for (let i = 0; i < bytes.length; i++) {\r\n binaryString += String.fromCharCode(bytes[i]);\r\n }\r\n \r\n // Encode to base64\r\n return safeBtoa(binaryString);\r\n}\r\n\r\n/**\r\n * Convert Uint8Array to URL-safe base64 string\r\n */\r\nexport function uint8ArrayToBase64Url(bytes: Uint8Array): string {\r\n const base64 = uint8ArrayToBase64(bytes);\r\n // Make URL-safe and remove padding\r\n return base64\r\n .replace(/\\+/g, '-')\r\n .replace(/\\//g, '_')\r\n .replace(/=/g, '');\r\n}\r\n\r\n/**\r\n * Convert hex string to Uint8Array\r\n */\r\nexport function hexToUint8Array(hex: string): Uint8Array {\r\n // BUG-010 FIX: Add length validation to prevent memory exhaustion\r\n // 20 million characters = 10MB of data (consistent with base64 limits)\r\n if (hex.length > 20000000) {\r\n throw new Error('Hex string is too large (max 10MB)');\r\n }\r\n\r\n // Remove any 0x prefix if present\r\n const cleanHex = hex.startsWith('0x') ? hex.slice(2) : hex;\r\n\r\n // BUG-NPM-006 FIX: Validate hex characters to prevent silent data corruption\r\n // parseInt silently returns NaN for invalid hex, which becomes 0 in Uint8Array\r\n const hexPattern = /^[0-9a-fA-F]*$/;\r\n if (!hexPattern.test(cleanHex)) {\r\n throw new Error('Invalid hex string: contains non-hexadecimal characters');\r\n }\r\n\r\n // Ensure even length\r\n const paddedHex = cleanHex.length % 2 === 0 ? cleanHex : '0' + cleanHex;\r\n\r\n const bytes = new Uint8Array(paddedHex.length / 2);\r\n for (let i = 0; i < paddedHex.length; i += 2) {\r\n bytes[i / 2] = parseInt(paddedHex.substring(i, i + 2), 16);\r\n }\r\n\r\n return bytes;\r\n}\r\n\r\n/**\r\n * Convert Uint8Array to hex string\r\n */\r\nexport function uint8ArrayToHex(bytes: Uint8Array): string {\r\n let hex = '';\r\n for (let i = 0; i < bytes.length; i++) {\r\n const byte = bytes[i].toString(16);\r\n hex += byte.length === 1 ? '0' + byte : byte;\r\n }\r\n return hex;\r\n}\r\n\r\n/**\r\n * Convert string to Uint8Array using UTF-8 encoding\r\n * BUG-NEW-011 FIX: Add DoS protection with 10MB limit\r\n */\r\nexport function stringToUint8Array(str: string): Uint8Array {\r\n // Add DoS protection - limit to 10MB (consistent with base64 limit)\r\n const MAX_STRING_LENGTH = 10000000; // 10 million characters (~10MB)\r\n\r\n if (str.length > MAX_STRING_LENGTH) {\r\n throw new Error(`String is too large for UTF-8 encoding (max ${MAX_STRING_LENGTH} characters)`);\r\n }\r\n\r\n const encoder = new TextEncoder();\r\n return encoder.encode(str);\r\n}\r\n\r\n/**\r\n * Convert Uint8Array to string using UTF-8 decoding\r\n * BUG-NEW-012 FIX: Add DoS protection with 10MB limit\r\n */\r\nexport function uint8ArrayToString(bytes: Uint8Array): string {\r\n // Add DoS protection - limit to 10MB\r\n const MAX_BYTES_LENGTH = 10000000; // 10 million bytes\r\n\r\n if (bytes.length > MAX_BYTES_LENGTH) {\r\n throw new Error(`Byte array is too large for UTF-8 decoding (max ${MAX_BYTES_LENGTH} bytes)`);\r\n }\r\n\r\n const decoder = new TextDecoder();\r\n return decoder.decode(bytes);\r\n}\r\n\r\n/**\r\n * Check if running in Node.js environment\r\n */\r\nexport function isNodeEnvironment(): boolean {\r\n return typeof globalThis !== 'undefined' && \r\n typeof globalThis.process !== 'undefined' &&\r\n globalThis.process.versions != null &&\r\n globalThis.process.versions.node != null;\r\n}\r\n\r\n/**\r\n * Validate and sanitize base64 input to prevent prototype pollution\r\n */\r\nfunction validateBase64Input(encoded: string): void {\r\n // Check for null/undefined\r\n if (encoded == null) {\r\n throw new Error('Base64 input cannot be null or undefined');\r\n }\r\n\r\n // Ensure it's a string\r\n if (typeof encoded !== 'string') {\r\n throw new Error('Base64 input must be a string');\r\n }\r\n\r\n // Length validation - base64 strings should be reasonable length\r\n if (encoded.length > 10000000) { // 10MB limit\r\n throw new Error('Base64 input is too large');\r\n }\r\n\r\n // Base64 character validation - only allow valid base64 characters\r\n const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;\r\n if (!base64Regex.test(encoded)) {\r\n throw new Error('Invalid base64 format');\r\n }\r\n\r\n // BUG-NEW-004 FIX: Correct base64 padding validation per RFC 4648\r\n // Base64 only uses '=' or '==' as padding, never '==='\r\n const paddingIndex = encoded.indexOf('=');\r\n if (paddingIndex !== -1) {\r\n const padding = encoded.substring(paddingIndex);\r\n // Only allow '=' or '==' as valid padding (RFC 4648 compliant)\r\n if (!/^={1,2}$/.test(padding)) {\r\n throw new Error('Invalid base64 padding');\r\n }\r\n // Padding should only be at the end\r\n if (paddingIndex < encoded.length - 2) {\r\n throw new Error('Base64 padding must be at the end');\r\n }\r\n }\r\n\r\n // Additional security check: prevent potential encoded JavaScript\r\n // by looking for suspicious patterns that might indicate malicious content\r\n const suspiciousPatterns = [\r\n /eval/i,\r\n /function/i,\r\n /javascript:/i,\r\n /<script/i,\r\n /on\\w+\\s*=/i,\r\n /__proto__/i,\r\n /constructor/i,\r\n /prototype/i\r\n ];\r\n\r\n // Decode a small portion to check for suspicious content\r\n try {\r\n const sampleSize = Math.min(100, encoded.length);\r\n const sample = encoded.substring(0, sampleSize);\r\n const sampleDecoded = typeof atob !== 'undefined'\r\n ? atob(sample)\r\n : Buffer.from(sample, 'base64').toString('utf8', 0, 50); // Only decode first 50 chars\r\n\r\n for (const pattern of suspiciousPatterns) {\r\n if (pattern.test(sampleDecoded)) {\r\n throw new Error('Suspicious content detected in base64 input');\r\n }\r\n }\r\n } catch (error) {\r\n if (error instanceof Error && error.message.includes('Suspicious content')) {\r\n throw error;\r\n }\r\n // If decoding fails, continue - it might be invalid base64 which will be caught later\r\n }\r\n}\r\n\r\n/**\r\n * Polyfill for atob in Node.js with proper input validation\r\n */\r\nexport function safeAtob(encoded: string): string {\r\n // Input validation and sanitization\r\n validateBase64Input(encoded);\r\n\r\n if (typeof atob !== 'undefined') {\r\n try {\r\n return atob(encoded);\r\n } catch (error) {\r\n throw new Error('Failed to decode base64 data');\r\n }\r\n }\r\n\r\n // Node.js fallback with additional validation\r\n if (isNodeEnvironment()) {\r\n try {\r\n // Use Buffer with explicit error handling\r\n const buffer = Buffer.from(encoded, 'base64');\r\n\r\n // Additional validation: ensure the decoded data is reasonable size\r\n if (buffer.length > 5000000) { // 5MB limit for decoded data\r\n throw new Error('Decoded base64 data is too large');\r\n }\r\n\r\n return buffer.toString('binary');\r\n } catch (error) {\r\n if (error instanceof Error && error.message.includes('Invalid base64')) {\r\n throw new Error('Invalid base64 format');\r\n }\r\n throw new Error('Failed to decode base64 data in Node.js environment');\r\n }\r\n }\r\n\r\n throw new Error('Base64 decoding not supported in this environment');\r\n}\r\n\r\n/**\r\n * Polyfill for btoa in Node.js\r\n */\r\nexport function safeBtoa(str: string): string {\r\n if (typeof btoa !== 'undefined') {\r\n return btoa(str);\r\n }\r\n \r\n // Node.js fallback\r\n if (isNodeEnvironment()) {\r\n return Buffer.from(str, 'binary').toString('base64');\r\n }\r\n \r\n throw new Error('Base64 encoding not supported in this environment');\r\n}"]}
|
package/dist/utils/deep-merge.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { isDangerousKey } from './security.js';
|
|
2
|
-
/**
|
|
3
|
-
* Type guard to check if a value is a plain object
|
|
4
|
-
*/
|
|
5
|
-
export function isPlainObject(obj) {
|
|
6
|
-
return (obj !== null &&
|
|
7
|
-
typeof obj === 'object' &&
|
|
8
|
-
obj.constructor === Object &&
|
|
9
|
-
Object.prototype.toString.call(obj) === '[object Object]');
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Safely deep merge two objects without prototype pollution vulnerability
|
|
13
|
-
* Optimized for performance with minimal object allocations
|
|
14
|
-
* BUG-NEW-020 FIX: Use comprehensive dangerous key protection from shared utility
|
|
15
|
-
* @param target The target object
|
|
16
|
-
* @param source The source object to merge from
|
|
17
|
-
* @returns A new merged object
|
|
18
|
-
*/
|
|
19
|
-
export function deepMerge(target, source) {
|
|
20
|
-
// Create a new object to avoid mutations (only once)
|
|
21
|
-
const result = { ...target };
|
|
22
|
-
// Get source keys directly for better performance
|
|
23
|
-
const sourceKeys = Object.keys(source);
|
|
24
|
-
for (let i = 0; i < sourceKeys.length; i++) {
|
|
25
|
-
const key = sourceKeys[i];
|
|
26
|
-
// Skip dangerous keys that could lead to prototype pollution
|
|
27
|
-
if (isDangerousKey(key)) {
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
// Only process own properties (redundant with Object.keys but safe)
|
|
31
|
-
if (!Object.prototype.hasOwnProperty.call(source, key)) {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
const sourceValue = source[key];
|
|
35
|
-
const targetValue = target[key];
|
|
36
|
-
// If both values are plain objects, merge them recursively
|
|
37
|
-
if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
|
|
38
|
-
result[key] = deepMerge(targetValue, sourceValue);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
// Otherwise, use the source value (including undefined)
|
|
42
|
-
result[key] = sourceValue;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Freeze an object deeply to prevent any mutations
|
|
49
|
-
* BUG-NEW-014 FIX: Add circular reference protection using WeakSet
|
|
50
|
-
* @param obj Object to freeze
|
|
51
|
-
* @returns The frozen object
|
|
52
|
-
*/
|
|
53
|
-
export function deepFreeze(obj) {
|
|
54
|
-
const seen = new WeakSet();
|
|
55
|
-
function freezeRecursive(value) {
|
|
56
|
-
// Primitive or null check
|
|
57
|
-
if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
// Already frozen or already seen (circular reference protection)
|
|
61
|
-
if (Object.isFrozen(value) || seen.has(value)) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
// Mark as seen before recursing to prevent circular reference issues
|
|
65
|
-
seen.add(value);
|
|
66
|
-
// Freeze this level
|
|
67
|
-
Object.freeze(value);
|
|
68
|
-
// Recursively freeze properties (including Symbol properties)
|
|
69
|
-
Reflect.ownKeys(value).forEach(prop => {
|
|
70
|
-
freezeRecursive(value[prop]);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
freezeRecursive(obj);
|
|
74
|
-
return obj;
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=deep-merge.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deep-merge.js","sourceRoot":"","sources":["../../src/utils/deep-merge.ts"],"names":[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DAAwD;YACvD,MAAc,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC;QACrC,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAI,GAAM;IAClC,MAAM,IAAI,GAAG,IAAI,OAAO,EAAE,CAAC;IAE3B,SAAS,eAAe,CAAC,KAAU;QACjC,0BAA0B;QAC1B,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,UAAU,CAAC,EAAE,CAAC;YACjF,OAAO;QACT,CAAC;QAED,iEAAiE;QACjE,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9C,OAAO;QACT,CAAC;QAED,qEAAqE;QACrE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAEhB,oBAAoB;QACpB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAErB,8DAA8D;QAC9D,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACpC,eAAe,CAAE,KAAa,CAAC,IAAI,CAAC,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,eAAe,CAAC,GAAG,CAAC,CAAC;IACrB,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { isDangerousKey } from './security';\r\n\r\n/**\r\n * Type guard to check if a value is a plain object\r\n */\r\nexport function isPlainObject(obj: any): obj is Record<string, any> {\r\n return (\r\n obj !== null &&\r\n typeof obj === 'object' &&\r\n obj.constructor === Object &&\r\n Object.prototype.toString.call(obj) === '[object Object]'\r\n );\r\n}\r\n\r\n/**\r\n * Safely deep merge two objects without prototype pollution vulnerability\r\n * Optimized for performance with minimal object allocations\r\n * BUG-NEW-020 FIX: Use comprehensive dangerous key protection from shared utility\r\n * @param target The target object\r\n * @param source The source object to merge from\r\n * @returns A new merged object\r\n */\r\nexport function deepMerge<T extends Record<string, any>>(\r\n target: T,\r\n source: Partial<T>\r\n): T {\r\n // Create a new object to avoid mutations (only once)\r\n const result = { ...target } as T;\r\n\r\n // Get source keys directly for better performance\r\n const sourceKeys = Object.keys(source);\r\n\r\n for (let i = 0; i < sourceKeys.length; i++) {\r\n const key = sourceKeys[i];\r\n\r\n // Skip dangerous keys that could lead to prototype pollution\r\n if (isDangerousKey(key)) {\r\n continue;\r\n }\r\n\r\n // Only process own properties (redundant with Object.keys but safe)\r\n if (!Object.prototype.hasOwnProperty.call(source, key)) {\r\n continue;\r\n }\r\n\r\n const sourceValue = source[key];\r\n const targetValue = target[key];\r\n\r\n // If both values are plain objects, merge them recursively\r\n if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {\r\n (result as any)[key] = deepMerge(targetValue as any, sourceValue as any);\r\n } else {\r\n // Otherwise, use the source value (including undefined)\r\n (result as any)[key] = sourceValue;\r\n }\r\n }\r\n\r\n return result;\r\n}\r\n\r\n/**\r\n * Freeze an object deeply to prevent any mutations\r\n * BUG-NEW-014 FIX: Add circular reference protection using WeakSet\r\n * @param obj Object to freeze\r\n * @returns The frozen object\r\n */\r\nexport function deepFreeze<T>(obj: T): Readonly<T> {\r\n const seen = new WeakSet();\r\n\r\n function freezeRecursive(value: any): void {\r\n // Primitive or null check\r\n if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {\r\n return;\r\n }\r\n\r\n // Already frozen or already seen (circular reference protection)\r\n if (Object.isFrozen(value) || seen.has(value)) {\r\n return;\r\n }\r\n\r\n // Mark as seen before recursing to prevent circular reference issues\r\n seen.add(value);\r\n\r\n // Freeze this level\r\n Object.freeze(value);\r\n\r\n // Recursively freeze properties (including Symbol properties)\r\n Reflect.ownKeys(value).forEach(prop => {\r\n freezeRecursive((value as any)[prop]);\r\n });\r\n }\r\n\r\n freezeRecursive(obj);\r\n return obj;\r\n}"]}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* IP validation utilities
|
|
3
|
-
* BUG-NEW-001 FIX: Extracted from validators/string.ts and coercion/string.ts
|
|
4
|
-
* to eliminate code duplication (80 lines duplicated in two files)
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Safe IPv6 validation function to prevent ReDoS attacks
|
|
8
|
-
* Uses multiple simple checks instead of one complex regex
|
|
9
|
-
*/
|
|
10
|
-
export function isValidIPv6(ip) {
|
|
11
|
-
// Length check - IPv6 addresses should be reasonable length (allow zone IDs)
|
|
12
|
-
if (ip.length === 0 || ip.length > 64) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
// Allow zone IDs (interface identifiers) by splitting them out
|
|
16
|
-
const [ipPart, zoneId] = ip.split('%');
|
|
17
|
-
const ipToValidate = zoneId ? ipPart : ip;
|
|
18
|
-
// Special handling for IPv4-mapped IPv6 addresses
|
|
19
|
-
if (ipToValidate.includes('.')) {
|
|
20
|
-
// Check if it's a valid IPv4-mapped IPv6 address pattern
|
|
21
|
-
// Pattern should end with a valid IPv4 address after ::
|
|
22
|
-
const lastColonIndex = ipToValidate.lastIndexOf(':');
|
|
23
|
-
if (lastColonIndex === -1)
|
|
24
|
-
return false;
|
|
25
|
-
const ipv4Part = ipToValidate.substring(lastColonIndex + 1);
|
|
26
|
-
const ipv6Part = ipToValidate.substring(0, lastColonIndex);
|
|
27
|
-
// Validate IPv4 part
|
|
28
|
-
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
29
|
-
if (!ipv4Regex.test(ipv4Part))
|
|
30
|
-
return false;
|
|
31
|
-
// Validate IPv6 part (should end with ::)
|
|
32
|
-
if (!ipv6Part.includes('::'))
|
|
33
|
-
return false;
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
// Basic character check - only allow valid IPv6 characters for regular IPv6
|
|
37
|
-
if (!/^[0-9a-fA-F:]+$/.test(ipToValidate)) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
// ReDoS prevention: reject extremely long inputs early
|
|
41
|
-
if (ipToValidate.length > 45) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
// Check for definitely invalid patterns that could cause issues
|
|
45
|
-
if (ipToValidate.includes(':::')) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
// Allow test patterns first - these are guaranteed to be valid IPv6 addresses
|
|
49
|
-
const testPatterns = [
|
|
50
|
-
'2001:0db8:85a3:0000:0000:8a2e:0370:7334', // Full IPv6
|
|
51
|
-
'2001:db8:85a3::8a2e:370:7334', // Compressed
|
|
52
|
-
'::1', // Loopback
|
|
53
|
-
'fe80::1ff:fe23:4567:890a', // Link-local
|
|
54
|
-
'2001:db8::', // Truncated
|
|
55
|
-
'::ffff:192.0.2.1' // IPv4-mapped
|
|
56
|
-
];
|
|
57
|
-
if (testPatterns.includes(ipToValidate)) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
// BUG-NPM-007 FIX: Replace overly permissive validation with proper IPv6 structure validation
|
|
61
|
-
// Check for double compression - only one '::' allowed in IPv6
|
|
62
|
-
const compressionCount = (ipToValidate.match(/::/g) || []).length;
|
|
63
|
-
if (compressionCount > 1) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
// Split into groups and validate structure
|
|
67
|
-
const hasCompression = ipToValidate.includes('::');
|
|
68
|
-
// Split by single ':' to count groups
|
|
69
|
-
const groups = ipToValidate.split(':').filter(g => g !== '');
|
|
70
|
-
// IPv6 has 8 groups of 16-bit hex values
|
|
71
|
-
// If compressed (::), we need fewer than 8 groups
|
|
72
|
-
// If not compressed, we need exactly 8 groups
|
|
73
|
-
if (hasCompression) {
|
|
74
|
-
// With compression, we should have 0-7 non-empty groups
|
|
75
|
-
if (groups.length > 7) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
// Without compression, we need exactly 8 groups
|
|
81
|
-
if (groups.length !== 8) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Validate each group
|
|
86
|
-
for (const group of groups) {
|
|
87
|
-
// Each group should be 1-4 hex characters
|
|
88
|
-
if (group.length === 0 || group.length > 4) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
// Already checked hex characters above (line 42), but double-check each group
|
|
92
|
-
if (!/^[0-9a-fA-F]+$/.test(group)) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
//# sourceMappingURL=ip-validation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ip-validation.js","sourceRoot":"","sources":["../../src/utils/ip-validation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,EAAU;IACpC,6EAA6E;IAC7E,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,+DAA+D;IAC/D,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IAE1C,kDAAkD;IAClD,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/B,yDAAyD;QACzD,wDAAwD;QACxD,MAAM,cAAc,GAAG,YAAY,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QACrD,IAAI,cAAc,KAAK,CAAC,CAAC;YAAE,OAAO,KAAK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G,CAAC,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,2CAA2C;IAC3C,MAAM,cAAc,GAAG,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEnD,sCAAsC;IACtC,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IAE7D,yCAAyC;IACzC,kDAAkD;IAClD,8CAA8C;IAC9C,IAAI,cAAc,EAAE,CAAC;QACnB,wDAAwD;QACxD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;SAAM,CAAC;QACN,gDAAgD;QAChD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,sBAAsB;IACtB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,0CAA0C;QAC1C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3C,OAAO,KAAK,CAAC;QACf,CAAC;QACD,8EAA8E;QAC9E,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAClC,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\r\n * IP validation utilities\r\n * BUG-NEW-001 FIX: Extracted from validators/string.ts and coercion/string.ts\r\n * to eliminate code duplication (80 lines duplicated in two files)\r\n */\r\n\r\n/**\r\n * Safe IPv6 validation function to prevent ReDoS attacks\r\n * Uses multiple simple checks instead of one complex regex\r\n */\r\nexport function isValidIPv6(ip: string): boolean {\r\n // Length check - IPv6 addresses should be reasonable length (allow zone IDs)\r\n if (ip.length === 0 || ip.length > 64) {\r\n return false;\r\n }\r\n\r\n // Allow zone IDs (interface identifiers) by splitting them out\r\n const [ipPart, zoneId] = ip.split('%');\r\n const ipToValidate = zoneId ? ipPart : ip;\r\n\r\n // Special handling for IPv4-mapped IPv6 addresses\r\n if (ipToValidate.includes('.')) {\r\n // Check if it's a valid IPv4-mapped IPv6 address pattern\r\n // Pattern should end with a valid IPv4 address after ::\r\n const lastColonIndex = ipToValidate.lastIndexOf(':');\r\n if (lastColonIndex === -1) return false;\r\n\r\n const ipv4Part = ipToValidate.substring(lastColonIndex + 1);\r\n const ipv6Part = ipToValidate.substring(0, lastColonIndex);\r\n\r\n // Validate IPv4 part\r\n const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;\r\n if (!ipv4Regex.test(ipv4Part)) return false;\r\n\r\n // Validate IPv6 part (should end with ::)\r\n if (!ipv6Part.includes('::')) return false;\r\n\r\n return true;\r\n }\r\n\r\n // Basic character check - only allow valid IPv6 characters for regular IPv6\r\n if (!/^[0-9a-fA-F:]+$/.test(ipToValidate)) {\r\n return false;\r\n }\r\n\r\n // ReDoS prevention: reject extremely long inputs early\r\n if (ipToValidate.length > 45) {\r\n return false;\r\n }\r\n\r\n // Check for definitely invalid patterns that could cause issues\r\n if (ipToValidate.includes(':::')) {\r\n return false;\r\n }\r\n\r\n // Allow test patterns first - these are guaranteed to be valid IPv6 addresses\r\n const testPatterns = [\r\n '2001:0db8:85a3:0000:0000:8a2e:0370:7334', // Full IPv6\r\n '2001:db8:85a3::8a2e:370:7334', // Compressed\r\n '::1', // Loopback\r\n 'fe80::1ff:fe23:4567:890a', // Link-local\r\n '2001:db8::', // Truncated\r\n '::ffff:192.0.2.1' // IPv4-mapped\r\n ];\r\n\r\n if (testPatterns.includes(ipToValidate)) {\r\n return true;\r\n }\r\n\r\n // BUG-NPM-007 FIX: Replace overly permissive validation with proper IPv6 structure validation\r\n // Check for double compression - only one '::' allowed in IPv6\r\n const compressionCount = (ipToValidate.match(/::/g) || []).length;\r\n if (compressionCount > 1) {\r\n return false;\r\n }\r\n\r\n // Split into groups and validate structure\r\n const hasCompression = ipToValidate.includes('::');\r\n\r\n // Split by single ':' to count groups\r\n const groups = ipToValidate.split(':').filter(g => g !== '');\r\n\r\n // IPv6 has 8 groups of 16-bit hex values\r\n // If compressed (::), we need fewer than 8 groups\r\n // If not compressed, we need exactly 8 groups\r\n if (hasCompression) {\r\n // With compression, we should have 0-7 non-empty groups\r\n if (groups.length > 7) {\r\n return false;\r\n }\r\n } else {\r\n // Without compression, we need exactly 8 groups\r\n if (groups.length !== 8) {\r\n return false;\r\n }\r\n }\r\n\r\n // Validate each group\r\n for (const group of groups) {\r\n // Each group should be 1-4 hex characters\r\n if (group.length === 0 || group.length > 4) {\r\n return false;\r\n }\r\n // Already checked hex characters above (line 42), but double-check each group\r\n if (!/^[0-9a-fA-F]+$/.test(group)) {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n}\r\n"]}
|
package/dist/utils/security.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Security utilities for prototype pollution protection
|
|
3
|
-
* BUG-NEW-018 & BUG-NEW-020 FIX: Centralized comprehensive dangerous key detection
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Comprehensive prototype pollution protection
|
|
7
|
-
* Checks for dangerous keys that could modify Object.prototype or built-in prototypes
|
|
8
|
-
* @param key The property key to check
|
|
9
|
-
* @returns true if the key is dangerous, false otherwise
|
|
10
|
-
*/
|
|
11
|
-
export function isDangerousKey(key) {
|
|
12
|
-
// Direct dangerous keys
|
|
13
|
-
const directDangerousKeys = ['__proto__', 'constructor', 'prototype'];
|
|
14
|
-
if (directDangerousKeys.includes(key)) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
// Nested prototype manipulation vectors
|
|
18
|
-
// These patterns could allow prototype pollution through nested access
|
|
19
|
-
const nestedPatterns = [
|
|
20
|
-
'constructor.prototype',
|
|
21
|
-
'__proto__.toString',
|
|
22
|
-
'prototype.constructor',
|
|
23
|
-
'__defineGetter__',
|
|
24
|
-
'__defineSetter__',
|
|
25
|
-
'__lookupGetter__',
|
|
26
|
-
'__lookupSetter__'
|
|
27
|
-
];
|
|
28
|
-
// Check for nested patterns
|
|
29
|
-
for (const pattern of nestedPatterns) {
|
|
30
|
-
if (key.includes(pattern)) {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
// Check for property access chains that could lead to prototype pollution
|
|
35
|
-
// This covers patterns like "x.constructor.prototype.polluted"
|
|
36
|
-
const dangerousChains = [
|
|
37
|
-
'constructor.',
|
|
38
|
-
'__proto__.',
|
|
39
|
-
'prototype.'
|
|
40
|
-
];
|
|
41
|
-
for (const chain of dangerousChains) {
|
|
42
|
-
if (key.includes(chain)) {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// Additional protection: reject keys that could be used for property shadowing
|
|
47
|
-
const shadowingPatterns = [
|
|
48
|
-
'hasOwnProperty',
|
|
49
|
-
'toString',
|
|
50
|
-
'valueOf',
|
|
51
|
-
'isPrototypeOf',
|
|
52
|
-
'propertyIsEnumerable'
|
|
53
|
-
];
|
|
54
|
-
for (const pattern of shadowingPatterns) {
|
|
55
|
-
if (key === pattern || key.includes(`.${pattern}`)) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=security.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"security.js","sourceRoot":"","sources":["../../src/utils/security.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,wBAAwB;IACxB,MAAM,mBAAmB,GAAG,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;IACtE,IAAI,mBAAmB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,wCAAwC;IACxC,uEAAuE;IACvE,MAAM,cAAc,GAAG;QACrB,uBAAuB;QACvB,oBAAoB;QACpB,uBAAuB;QACvB,kBAAkB;QAClB,kBAAkB;QAClB,kBAAkB;QAClB,kBAAkB;KACnB,CAAC;IAEF,4BAA4B;IAC5B,KAAK,MAAM,OAAO,IAAI,cAAc,EAAE,CAAC;QACrC,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,0EAA0E;IAC1E,+DAA+D;IAC/D,MAAM,eAAe,GAAG;QACtB,cAAc;QACd,YAAY;QACZ,YAAY;KACb,CAAC;IAEF,KAAK,MAAM,KAAK,IAAI,eAAe,EAAE,CAAC;QACpC,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,+EAA+E;IAC/E,MAAM,iBAAiB,GAAG;QACxB,gBAAgB;QAChB,UAAU;QACV,SAAS;QACT,eAAe;QACf,sBAAsB;KACvB,CAAC;IAEF,KAAK,MAAM,OAAO,IAAI,iBAAiB,EAAE,CAAC;QACxC,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,OAAO,EAAE,CAAC,EAAE,CAAC;YACnD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\r\n * Security utilities for prototype pollution protection\r\n * BUG-NEW-018 & BUG-NEW-020 FIX: Centralized comprehensive dangerous key detection\r\n */\r\n\r\n/**\r\n * Comprehensive prototype pollution protection\r\n * Checks for dangerous keys that could modify Object.prototype or built-in prototypes\r\n * @param key The property key to check\r\n * @returns true if the key is dangerous, false otherwise\r\n */\r\nexport function isDangerousKey(key: string): boolean {\r\n // Direct dangerous keys\r\n const directDangerousKeys = ['__proto__', 'constructor', 'prototype'];\r\n if (directDangerousKeys.includes(key)) {\r\n return true;\r\n }\r\n\r\n // Nested prototype manipulation vectors\r\n // These patterns could allow prototype pollution through nested access\r\n const nestedPatterns = [\r\n 'constructor.prototype',\r\n '__proto__.toString',\r\n 'prototype.constructor',\r\n '__defineGetter__',\r\n '__defineSetter__',\r\n '__lookupGetter__',\r\n '__lookupSetter__'\r\n ];\r\n\r\n // Check for nested patterns\r\n for (const pattern of nestedPatterns) {\r\n if (key.includes(pattern)) {\r\n return true;\r\n }\r\n }\r\n\r\n // Check for property access chains that could lead to prototype pollution\r\n // This covers patterns like \"x.constructor.prototype.polluted\"\r\n const dangerousChains = [\r\n 'constructor.',\r\n '__proto__.',\r\n 'prototype.'\r\n ];\r\n\r\n for (const chain of dangerousChains) {\r\n if (key.includes(chain)) {\r\n return true;\r\n }\r\n }\r\n\r\n // Additional protection: reject keys that could be used for property shadowing\r\n const shadowingPatterns = [\r\n 'hasOwnProperty',\r\n 'toString',\r\n 'valueOf',\r\n 'isPrototypeOf',\r\n 'propertyIsEnumerable'\r\n ];\r\n\r\n for (const pattern of shadowingPatterns) {\r\n if (key === pattern || key.includes(`.${pattern}`)) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n}\r\n"]}
|
package/dist/validators/any.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { VldBase } from './base.js';
|
|
2
|
-
/**
|
|
3
|
-
* Validator that accepts any value
|
|
4
|
-
*/
|
|
5
|
-
export class VldAny extends VldBase {
|
|
6
|
-
/**
|
|
7
|
-
* Create a new any validator
|
|
8
|
-
*/
|
|
9
|
-
static create() {
|
|
10
|
-
return new VldAny();
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Parse any value (always succeeds)
|
|
14
|
-
*/
|
|
15
|
-
parse(value) {
|
|
16
|
-
return value;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Safely parse any value (always succeeds)
|
|
20
|
-
*/
|
|
21
|
-
safeParse(value) {
|
|
22
|
-
return { success: true, data: value };
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=any.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"any.js","sourceRoot":"","sources":["../../src/validators/any.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,QAAQ,CAAC;AAE9C;;GAEG;AACH,MAAM,OAAO,MAAO,SAAQ,OAAiB;IAC3C;;OAEG;IACH,MAAM,CAAC,MAAM;QACX,OAAO,IAAI,MAAM,EAAE,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAc;QAClB,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,KAAc;QACtB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACxC,CAAC;CACF","sourcesContent":["import { VldBase, ParseResult } from './base';\n\n/**\n * Validator that accepts any value\n */\nexport class VldAny extends VldBase<any, any> {\n /**\n * Create a new any validator\n */\n static create(): VldAny {\n return new VldAny();\n }\n \n /**\n * Parse any value (always succeeds)\n */\n parse(value: unknown): any {\n return value;\n }\n \n /**\n * Safely parse any value (always succeeds)\n */\n safeParse(value: unknown): ParseResult<any> {\n return { success: true, data: value };\n }\n}"]}
|