@mainwp/control 1.0.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.
- package/LICENSE +674 -0
- package/README.md +583 -0
- package/bin/_exit.js +12 -0
- package/bin/dev.js +7 -0
- package/bin/run.js +7 -0
- package/dist/chat/chat-engine.d.ts +213 -0
- package/dist/chat/chat-engine.d.ts.map +1 -0
- package/dist/chat/chat-engine.js +636 -0
- package/dist/chat/chat-engine.js.map +1 -0
- package/dist/chat/index.d.ts +10 -0
- package/dist/chat/index.d.ts.map +1 -0
- package/dist/chat/index.js +14 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat/providers/anthropic.d.ts +52 -0
- package/dist/chat/providers/anthropic.d.ts.map +1 -0
- package/dist/chat/providers/anthropic.js +292 -0
- package/dist/chat/providers/anthropic.js.map +1 -0
- package/dist/chat/providers/gemini.d.ts +52 -0
- package/dist/chat/providers/gemini.d.ts.map +1 -0
- package/dist/chat/providers/gemini.js +284 -0
- package/dist/chat/providers/gemini.js.map +1 -0
- package/dist/chat/providers/index.d.ts +19 -0
- package/dist/chat/providers/index.d.ts.map +1 -0
- package/dist/chat/providers/index.js +23 -0
- package/dist/chat/providers/index.js.map +1 -0
- package/dist/chat/providers/local.d.ts +37 -0
- package/dist/chat/providers/local.d.ts.map +1 -0
- package/dist/chat/providers/local.js +130 -0
- package/dist/chat/providers/local.js.map +1 -0
- package/dist/chat/providers/openai-compatible.d.ts +155 -0
- package/dist/chat/providers/openai-compatible.d.ts.map +1 -0
- package/dist/chat/providers/openai-compatible.js +264 -0
- package/dist/chat/providers/openai-compatible.js.map +1 -0
- package/dist/chat/providers/openai.d.ts +24 -0
- package/dist/chat/providers/openai.d.ts.map +1 -0
- package/dist/chat/providers/openai.js +62 -0
- package/dist/chat/providers/openai.js.map +1 -0
- package/dist/chat/providers/openrouter.d.ts +26 -0
- package/dist/chat/providers/openrouter.d.ts.map +1 -0
- package/dist/chat/providers/openrouter.js +65 -0
- package/dist/chat/providers/openrouter.js.map +1 -0
- package/dist/chat/providers/provider-fetch.d.ts +15 -0
- package/dist/chat/providers/provider-fetch.d.ts.map +1 -0
- package/dist/chat/providers/provider-fetch.js +35 -0
- package/dist/chat/providers/provider-fetch.js.map +1 -0
- package/dist/chat/providers/provider.d.ts +214 -0
- package/dist/chat/providers/provider.d.ts.map +1 -0
- package/dist/chat/providers/provider.js +166 -0
- package/dist/chat/providers/provider.js.map +1 -0
- package/dist/chat/providers/sse-reader.d.ts +21 -0
- package/dist/chat/providers/sse-reader.d.ts.map +1 -0
- package/dist/chat/providers/sse-reader.js +48 -0
- package/dist/chat/providers/sse-reader.js.map +1 -0
- package/dist/chat/system-prompt.d.ts +33 -0
- package/dist/chat/system-prompt.d.ts.map +1 -0
- package/dist/chat/system-prompt.js +166 -0
- package/dist/chat/system-prompt.js.map +1 -0
- package/dist/chat/tool-envelope.d.ts +72 -0
- package/dist/chat/tool-envelope.d.ts.map +1 -0
- package/dist/chat/tool-envelope.js +263 -0
- package/dist/chat/tool-envelope.js.map +1 -0
- package/dist/commands/abilities/info.d.ts +21 -0
- package/dist/commands/abilities/info.d.ts.map +1 -0
- package/dist/commands/abilities/info.js +80 -0
- package/dist/commands/abilities/info.js.map +1 -0
- package/dist/commands/abilities/list.d.ts +19 -0
- package/dist/commands/abilities/list.d.ts.map +1 -0
- package/dist/commands/abilities/list.js +98 -0
- package/dist/commands/abilities/list.js.map +1 -0
- package/dist/commands/abilities/run.d.ts +75 -0
- package/dist/commands/abilities/run.d.ts.map +1 -0
- package/dist/commands/abilities/run.js +468 -0
- package/dist/commands/abilities/run.js.map +1 -0
- package/dist/commands/chat.d.ts +54 -0
- package/dist/commands/chat.d.ts.map +1 -0
- package/dist/commands/chat.js +384 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/config/show.d.ts +54 -0
- package/dist/commands/config/show.d.ts.map +1 -0
- package/dist/commands/config/show.js +324 -0
- package/dist/commands/config/show.js.map +1 -0
- package/dist/commands/doctor.d.ts +77 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +412 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/jobs/watch.d.ts +50 -0
- package/dist/commands/jobs/watch.d.ts.map +1 -0
- package/dist/commands/jobs/watch.js +269 -0
- package/dist/commands/jobs/watch.js.map +1 -0
- package/dist/commands/login.d.ts +25 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +165 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/profile/delete.d.ts +22 -0
- package/dist/commands/profile/delete.d.ts.map +1 -0
- package/dist/commands/profile/delete.js +57 -0
- package/dist/commands/profile/delete.js.map +1 -0
- package/dist/commands/profile/list.d.ts +19 -0
- package/dist/commands/profile/list.d.ts.map +1 -0
- package/dist/commands/profile/list.js +53 -0
- package/dist/commands/profile/list.js.map +1 -0
- package/dist/commands/profile/use.d.ts +22 -0
- package/dist/commands/profile/use.d.ts.map +1 -0
- package/dist/commands/profile/use.js +46 -0
- package/dist/commands/profile/use.js.map +1 -0
- package/dist/config/fs-utils.d.ts +14 -0
- package/dist/config/fs-utils.d.ts.map +1 -0
- package/dist/config/fs-utils.js +31 -0
- package/dist/config/fs-utils.js.map +1 -0
- package/dist/config/keychain.d.ts +53 -0
- package/dist/config/keychain.d.ts.map +1 -0
- package/dist/config/keychain.js +175 -0
- package/dist/config/keychain.js.map +1 -0
- package/dist/config/profile-store.d.ts +85 -0
- package/dist/config/profile-store.d.ts.map +1 -0
- package/dist/config/profile-store.js +228 -0
- package/dist/config/profile-store.js.map +1 -0
- package/dist/config/settings.d.ts +71 -0
- package/dist/config/settings.d.ts.map +1 -0
- package/dist/config/settings.js +151 -0
- package/dist/config/settings.js.map +1 -0
- package/dist/core/abilities-executor.d.ts +126 -0
- package/dist/core/abilities-executor.d.ts.map +1 -0
- package/dist/core/abilities-executor.js +264 -0
- package/dist/core/abilities-executor.js.map +1 -0
- package/dist/core/batch-manager.d.ts +113 -0
- package/dist/core/batch-manager.d.ts.map +1 -0
- package/dist/core/batch-manager.js +244 -0
- package/dist/core/batch-manager.js.map +1 -0
- package/dist/core/http-client.d.ts +111 -0
- package/dist/core/http-client.d.ts.map +1 -0
- package/dist/core/http-client.js +329 -0
- package/dist/core/http-client.js.map +1 -0
- package/dist/core/safety-controller.d.ts +114 -0
- package/dist/core/safety-controller.d.ts.map +1 -0
- package/dist/core/safety-controller.js +229 -0
- package/dist/core/safety-controller.js.map +1 -0
- package/dist/hooks/command-not-found.d.ts +12 -0
- package/dist/hooks/command-not-found.d.ts.map +1 -0
- package/dist/hooks/command-not-found.js +58 -0
- package/dist/hooks/command-not-found.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/base-command.d.ts +123 -0
- package/dist/lib/base-command.d.ts.map +1 -0
- package/dist/lib/base-command.js +285 -0
- package/dist/lib/base-command.js.map +1 -0
- package/dist/output/formatter.d.ts +48 -0
- package/dist/output/formatter.d.ts.map +1 -0
- package/dist/output/formatter.js +138 -0
- package/dist/output/formatter.js.map +1 -0
- package/dist/output/json-envelope.d.ts +43 -0
- package/dist/output/json-envelope.d.ts.map +1 -0
- package/dist/output/json-envelope.js +73 -0
- package/dist/output/json-envelope.js.map +1 -0
- package/dist/utils/audit-logger.d.ts +97 -0
- package/dist/utils/audit-logger.d.ts.map +1 -0
- package/dist/utils/audit-logger.js +169 -0
- package/dist/utils/audit-logger.js.map +1 -0
- package/dist/utils/colors.d.ts +29 -0
- package/dist/utils/colors.d.ts.map +1 -0
- package/dist/utils/colors.js +36 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/errors.d.ts +107 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +149 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/exit-codes.d.ts +21 -0
- package/dist/utils/exit-codes.d.ts.map +1 -0
- package/dist/utils/exit-codes.js +20 -0
- package/dist/utils/exit-codes.js.map +1 -0
- package/dist/utils/format.d.ts +64 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +69 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/prompt.d.ts +34 -0
- package/dist/utils/prompt.d.ts.map +1 -0
- package/dist/utils/prompt.js +132 -0
- package/dist/utils/prompt.js.map +1 -0
- package/dist/utils/retry.d.ts +59 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +96 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/terminal-sanitizer.d.ts +60 -0
- package/dist/utils/terminal-sanitizer.d.ts.map +1 -0
- package/dist/utils/terminal-sanitizer.js +166 -0
- package/dist/utils/terminal-sanitizer.js.map +1 -0
- package/dist/validation/input-sanitizer.d.ts +76 -0
- package/dist/validation/input-sanitizer.d.ts.map +1 -0
- package/dist/validation/input-sanitizer.js +199 -0
- package/dist/validation/input-sanitizer.js.map +1 -0
- package/dist/validation/schema-validator.d.ts +75 -0
- package/dist/validation/schema-validator.d.ts.map +1 -0
- package/dist/validation/schema-validator.js +147 -0
- package/dist/validation/schema-validator.js.map +1 -0
- package/oclif.manifest.json +857 -0
- package/package.json +101 -0
- package/scripts/completions/README.md +221 -0
- package/scripts/completions/mainwpcontrol.bash +193 -0
- package/scripts/completions/mainwpcontrol.zsh +267 -0
- package/scripts/completions/profile-completer.sh +35 -0
- package/scripts/completions/regenerate.sh +78 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal Output Sanitizer for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* Security utility to strip ANSI escape sequences and control characters
|
|
5
|
+
* from untrusted data before rendering to terminal output.
|
|
6
|
+
*
|
|
7
|
+
* Prevents:
|
|
8
|
+
* - Terminal escape sequence injection
|
|
9
|
+
* - Fake prompt attacks
|
|
10
|
+
* - Screen manipulation/overwriting
|
|
11
|
+
* - OSC command execution
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Regular expressions for matching escape sequences
|
|
15
|
+
*/
|
|
16
|
+
const ESCAPE_PATTERNS = {
|
|
17
|
+
// ANSI escape sequences: ESC [ ... (CSI sequences)
|
|
18
|
+
// Matches: colors, cursor movement, screen clearing, etc.
|
|
19
|
+
csi: /\x1b\[[0-9;]*[A-Za-z]/g,
|
|
20
|
+
// Operating System Command sequences: ESC ] ... ST
|
|
21
|
+
// Used for setting window titles, clipboard, etc.
|
|
22
|
+
osc: /\x1b\][\s\S]*?(?:\x07|\x1b\\)/g,
|
|
23
|
+
// Single-character escape sequences: ESC followed by single char
|
|
24
|
+
singleEsc: /\x1b[^[\]]/g,
|
|
25
|
+
// C1 control characters (0x80-0x9F)
|
|
26
|
+
c1: /[\x80-\x9f]/g,
|
|
27
|
+
// Device Control Strings: ESC P ... ST
|
|
28
|
+
dcs: /\x1bP[\s\S]*?(?:\x1b\\)/g,
|
|
29
|
+
// Application Program Command: ESC _ ... ST
|
|
30
|
+
apc: /\x1b_[\s\S]*?(?:\x1b\\)/g,
|
|
31
|
+
// Privacy Message: ESC ^ ... ST
|
|
32
|
+
pm: /\x1b\^[\s\S]*?(?:\x1b\\)/g,
|
|
33
|
+
// Start of String: ESC X ... ST
|
|
34
|
+
sos: /\x1bX[\s\S]*?(?:\x1b\\)/g,
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* C0 control characters to remove (0x00-0x1F)
|
|
38
|
+
* Preserves: \t (0x09), \n (0x0A), \r (0x0D)
|
|
39
|
+
*/
|
|
40
|
+
const C0_UNSAFE = /[\x00-\x08\x0b\x0c\x0e-\x1f]/g;
|
|
41
|
+
/**
|
|
42
|
+
* Strip all ANSI escape sequences and control characters from a string.
|
|
43
|
+
*
|
|
44
|
+
* This is the core sanitization function that removes:
|
|
45
|
+
* - ANSI CSI sequences (colors, cursor movement, screen control)
|
|
46
|
+
* - OSC sequences (window titles, clipboard commands)
|
|
47
|
+
* - Other escape sequences (DCS, APC, PM, SOS)
|
|
48
|
+
* - C0 control characters (except tab, newline, carriage return)
|
|
49
|
+
* - C1 control characters
|
|
50
|
+
*
|
|
51
|
+
* @param str - The string to sanitize
|
|
52
|
+
* @returns The sanitized string with all escape sequences removed
|
|
53
|
+
*/
|
|
54
|
+
export function stripControlChars(str) {
|
|
55
|
+
if (typeof str !== 'string') {
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
58
|
+
let result = str;
|
|
59
|
+
// Remove all escape sequence types
|
|
60
|
+
result = result.replace(ESCAPE_PATTERNS.osc, '');
|
|
61
|
+
result = result.replace(ESCAPE_PATTERNS.dcs, '');
|
|
62
|
+
result = result.replace(ESCAPE_PATTERNS.apc, '');
|
|
63
|
+
result = result.replace(ESCAPE_PATTERNS.pm, '');
|
|
64
|
+
result = result.replace(ESCAPE_PATTERNS.sos, '');
|
|
65
|
+
result = result.replace(ESCAPE_PATTERNS.csi, '');
|
|
66
|
+
result = result.replace(ESCAPE_PATTERNS.singleEsc, '');
|
|
67
|
+
// Remove control characters
|
|
68
|
+
result = result.replace(ESCAPE_PATTERNS.c1, '');
|
|
69
|
+
result = result.replace(C0_UNSAFE, '');
|
|
70
|
+
// Remove any remaining bare ESC characters
|
|
71
|
+
result = result.replace(/\x1b/g, '');
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Recursively sanitize a value for safe terminal output.
|
|
76
|
+
*
|
|
77
|
+
* Handles:
|
|
78
|
+
* - Strings: strips control characters
|
|
79
|
+
* - Arrays: recursively sanitizes each element
|
|
80
|
+
* - Objects: recursively sanitizes each value
|
|
81
|
+
* - Other types: converted to string and sanitized
|
|
82
|
+
*
|
|
83
|
+
* @param value - The value to sanitize
|
|
84
|
+
* @returns A sanitized copy of the value (original is not modified)
|
|
85
|
+
*/
|
|
86
|
+
export function sanitizeForTerminal(value) {
|
|
87
|
+
if (value === null || value === undefined) {
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
if (typeof value === 'string') {
|
|
91
|
+
return stripControlChars(value);
|
|
92
|
+
}
|
|
93
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
if (Array.isArray(value)) {
|
|
97
|
+
return value.map((item) => sanitizeForTerminal(item));
|
|
98
|
+
}
|
|
99
|
+
if (typeof value === 'object') {
|
|
100
|
+
const sanitized = {};
|
|
101
|
+
for (const [key, val] of Object.entries(value)) {
|
|
102
|
+
// Sanitize both keys and values
|
|
103
|
+
const sanitizedKey = stripControlChars(key);
|
|
104
|
+
sanitized[sanitizedKey] = sanitizeForTerminal(val);
|
|
105
|
+
}
|
|
106
|
+
return sanitized;
|
|
107
|
+
}
|
|
108
|
+
// For other types (functions, symbols, etc.), convert to string and sanitize
|
|
109
|
+
return stripControlChars(String(value));
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Sanitize a string for safe display, preserving safe content.
|
|
113
|
+
*
|
|
114
|
+
* This is a convenience wrapper that handles non-string inputs
|
|
115
|
+
* by converting them to JSON first.
|
|
116
|
+
*
|
|
117
|
+
* @param value - The value to sanitize for display
|
|
118
|
+
* @returns A safe string suitable for terminal output
|
|
119
|
+
*/
|
|
120
|
+
export function safeString(value) {
|
|
121
|
+
if (value === null) {
|
|
122
|
+
return 'null';
|
|
123
|
+
}
|
|
124
|
+
if (value === undefined) {
|
|
125
|
+
return 'undefined';
|
|
126
|
+
}
|
|
127
|
+
if (typeof value === 'string') {
|
|
128
|
+
return stripControlChars(value);
|
|
129
|
+
}
|
|
130
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
131
|
+
return String(value);
|
|
132
|
+
}
|
|
133
|
+
// For objects and arrays, sanitize then stringify
|
|
134
|
+
const sanitized = sanitizeForTerminal(value);
|
|
135
|
+
return JSON.stringify(sanitized);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Check if a string contains potentially dangerous escape sequences.
|
|
139
|
+
*
|
|
140
|
+
* Useful for logging or debugging when you want to detect
|
|
141
|
+
* but not necessarily remove escape sequences.
|
|
142
|
+
*
|
|
143
|
+
* @param str - The string to check
|
|
144
|
+
* @returns True if the string contains escape sequences
|
|
145
|
+
*/
|
|
146
|
+
export function containsEscapeSequences(str) {
|
|
147
|
+
if (typeof str !== 'string') {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
// Reset lastIndex on global regexes before test() to avoid
|
|
151
|
+
// alternating true/false results from stateful .test() calls
|
|
152
|
+
ESCAPE_PATTERNS.csi.lastIndex = 0;
|
|
153
|
+
ESCAPE_PATTERNS.osc.lastIndex = 0;
|
|
154
|
+
ESCAPE_PATTERNS.singleEsc.lastIndex = 0;
|
|
155
|
+
ESCAPE_PATTERNS.c1.lastIndex = 0;
|
|
156
|
+
ESCAPE_PATTERNS.dcs.lastIndex = 0;
|
|
157
|
+
C0_UNSAFE.lastIndex = 0;
|
|
158
|
+
return (ESCAPE_PATTERNS.csi.test(str) ||
|
|
159
|
+
ESCAPE_PATTERNS.osc.test(str) ||
|
|
160
|
+
ESCAPE_PATTERNS.singleEsc.test(str) ||
|
|
161
|
+
ESCAPE_PATTERNS.c1.test(str) ||
|
|
162
|
+
ESCAPE_PATTERNS.dcs.test(str) ||
|
|
163
|
+
C0_UNSAFE.test(str) ||
|
|
164
|
+
str.includes('\x1b'));
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=terminal-sanitizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-sanitizer.js","sourceRoot":"","sources":["../../src/utils/terminal-sanitizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;GAEG;AACH,MAAM,eAAe,GAAG;IACtB,mDAAmD;IACnD,0DAA0D;IAC1D,GAAG,EAAE,wBAAwB;IAE7B,mDAAmD;IACnD,kDAAkD;IAClD,GAAG,EAAE,gCAAgC;IAErC,iEAAiE;IACjE,SAAS,EAA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QAC5B,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;QAC7B,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;QACnB,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CACrB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input Sanitizer for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* Security sanitization for inputs:
|
|
5
|
+
* - Input limits (string length, array elements, object depth)
|
|
6
|
+
* - Error sanitization (path redaction, credential stripping)
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Default limits for input sanitization
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEFAULT_LIMITS: {
|
|
12
|
+
/** Maximum string length */
|
|
13
|
+
readonly maxStringLength: 65536;
|
|
14
|
+
/** Maximum array elements */
|
|
15
|
+
readonly maxArrayElements: 1000;
|
|
16
|
+
/** Maximum object depth */
|
|
17
|
+
readonly maxObjectDepth: 10;
|
|
18
|
+
/** Maximum object keys */
|
|
19
|
+
readonly maxObjectKeys: 100;
|
|
20
|
+
/** Maximum total input size (approximate) */
|
|
21
|
+
readonly maxInputSize: 1048576;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Sanitization options
|
|
25
|
+
*/
|
|
26
|
+
export interface SanitizeOptions {
|
|
27
|
+
maxStringLength?: number;
|
|
28
|
+
maxArrayElements?: number;
|
|
29
|
+
maxObjectDepth?: number;
|
|
30
|
+
maxObjectKeys?: number;
|
|
31
|
+
maxInputSize?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Input Sanitizer class
|
|
35
|
+
*/
|
|
36
|
+
export declare class InputSanitizer {
|
|
37
|
+
private readonly limits;
|
|
38
|
+
constructor(options?: SanitizeOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Sanitize and validate input
|
|
41
|
+
*
|
|
42
|
+
* @param input - Input data to sanitize
|
|
43
|
+
* @throws InputError if input exceeds limits
|
|
44
|
+
* @returns Sanitized input (same object if valid)
|
|
45
|
+
*/
|
|
46
|
+
sanitize(input: Record<string, unknown>): Record<string, unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* Recursively validate a value
|
|
49
|
+
*/
|
|
50
|
+
private validateValue;
|
|
51
|
+
/**
|
|
52
|
+
* Check if a key name appears to contain sensitive data
|
|
53
|
+
*/
|
|
54
|
+
isSensitiveKey(key: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Redact sensitive values in an object (for logging/errors)
|
|
57
|
+
*/
|
|
58
|
+
redactSensitive(data: Record<string, unknown>): Record<string, unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* Recursively redact sensitive values
|
|
61
|
+
*/
|
|
62
|
+
private redactValue;
|
|
63
|
+
/**
|
|
64
|
+
* Sanitize error message to remove sensitive paths and data
|
|
65
|
+
*/
|
|
66
|
+
sanitizeErrorMessage(message: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* Sanitize an error object for safe logging
|
|
69
|
+
*/
|
|
70
|
+
sanitizeError(error: Error): Error;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the input sanitizer singleton
|
|
74
|
+
*/
|
|
75
|
+
export declare function getInputSanitizer(): InputSanitizer;
|
|
76
|
+
//# sourceMappingURL=input-sanitizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-sanitizer.d.ts","sourceRoot":"","sources":["../../src/validation/input-sanitizer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;GAEG;AACH,eAAO,MAAM,cAAc;IACzB,4BAA4B;;IAE5B,6BAA6B;;IAE7B,2BAA2B;;IAE3B,0BAA0B;;IAE1B,6CAA6C;;CAErC,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA8BD;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;gBAEvC,OAAO,CAAC,EAAE,eAAe;IAUrC;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAiBjE;;OAEG;IACH,OAAO,CAAC,aAAa;IAsDrB;;OAEG;IACH,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIpC;;OAEG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIvE;;OAEG;IACH,OAAO,CAAC,WAAW;IAwBnB;;OAEG;IACH,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IA6B7C;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK;CAenC;AAOD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAKlD"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input Sanitizer for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* Security sanitization for inputs:
|
|
5
|
+
* - Input limits (string length, array elements, object depth)
|
|
6
|
+
* - Error sanitization (path redaction, credential stripping)
|
|
7
|
+
*/
|
|
8
|
+
import { InputError } from '../utils/errors.js';
|
|
9
|
+
/**
|
|
10
|
+
* Default limits for input sanitization
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_LIMITS = {
|
|
13
|
+
/** Maximum string length */
|
|
14
|
+
maxStringLength: 65536, // 64KB
|
|
15
|
+
/** Maximum array elements */
|
|
16
|
+
maxArrayElements: 1000,
|
|
17
|
+
/** Maximum object depth */
|
|
18
|
+
maxObjectDepth: 10,
|
|
19
|
+
/** Maximum object keys */
|
|
20
|
+
maxObjectKeys: 100,
|
|
21
|
+
/** Maximum total input size (approximate) */
|
|
22
|
+
maxInputSize: 1048576, // 1MB
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Patterns that indicate sensitive data
|
|
26
|
+
*/
|
|
27
|
+
const SENSITIVE_PATTERNS = [
|
|
28
|
+
/password/i,
|
|
29
|
+
/secret/i,
|
|
30
|
+
/token/i,
|
|
31
|
+
/api[_-]?key/i,
|
|
32
|
+
/auth/i,
|
|
33
|
+
/credential/i,
|
|
34
|
+
/private[_-]?key/i,
|
|
35
|
+
/bearer/i,
|
|
36
|
+
/signing[_-]?key/i,
|
|
37
|
+
/encryption[_-]?key/i,
|
|
38
|
+
];
|
|
39
|
+
/**
|
|
40
|
+
* Patterns for redacting file paths
|
|
41
|
+
*/
|
|
42
|
+
const PATH_PATTERNS = [
|
|
43
|
+
// Absolute paths
|
|
44
|
+
/\/Users\/[^/\s]+/g,
|
|
45
|
+
/\/home\/[^/\s]+/g,
|
|
46
|
+
/C:\\Users\\[^\\]+/gi,
|
|
47
|
+
// Config directories
|
|
48
|
+
/\.config\/mainwpcontrol/g,
|
|
49
|
+
];
|
|
50
|
+
/**
|
|
51
|
+
* Input Sanitizer class
|
|
52
|
+
*/
|
|
53
|
+
export class InputSanitizer {
|
|
54
|
+
limits;
|
|
55
|
+
constructor(options) {
|
|
56
|
+
this.limits = {
|
|
57
|
+
maxStringLength: options?.maxStringLength ?? DEFAULT_LIMITS.maxStringLength,
|
|
58
|
+
maxArrayElements: options?.maxArrayElements ?? DEFAULT_LIMITS.maxArrayElements,
|
|
59
|
+
maxObjectDepth: options?.maxObjectDepth ?? DEFAULT_LIMITS.maxObjectDepth,
|
|
60
|
+
maxObjectKeys: options?.maxObjectKeys ?? DEFAULT_LIMITS.maxObjectKeys,
|
|
61
|
+
maxInputSize: options?.maxInputSize ?? DEFAULT_LIMITS.maxInputSize,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Sanitize and validate input
|
|
66
|
+
*
|
|
67
|
+
* @param input - Input data to sanitize
|
|
68
|
+
* @throws InputError if input exceeds limits
|
|
69
|
+
* @returns Sanitized input (same object if valid)
|
|
70
|
+
*/
|
|
71
|
+
sanitize(input) {
|
|
72
|
+
// Check total size
|
|
73
|
+
const serialized = JSON.stringify(input);
|
|
74
|
+
if (serialized.length > this.limits.maxInputSize) {
|
|
75
|
+
throw new InputError(`Input size exceeds limit: ${serialized.length} bytes (max: ${this.limits.maxInputSize})`, { size: serialized.length, limit: this.limits.maxInputSize }, 'Reduce the size of your input or split into multiple requests');
|
|
76
|
+
}
|
|
77
|
+
// Validate structure
|
|
78
|
+
this.validateValue(input, 0, 'input');
|
|
79
|
+
return input;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Recursively validate a value
|
|
83
|
+
*/
|
|
84
|
+
validateValue(value, depth, path) {
|
|
85
|
+
// Check depth
|
|
86
|
+
if (depth > this.limits.maxObjectDepth) {
|
|
87
|
+
throw new InputError(`Input exceeds maximum depth at "${path}"`, { path, depth, limit: this.limits.maxObjectDepth }, 'Simplify your input structure or reduce nesting depth');
|
|
88
|
+
}
|
|
89
|
+
if (value === null || value === undefined) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (typeof value === 'string') {
|
|
93
|
+
if (value.length > this.limits.maxStringLength) {
|
|
94
|
+
throw new InputError(`String exceeds maximum length at "${path}"`, { path, length: value.length, limit: this.limits.maxStringLength }, 'Use shorter strings or split into multiple requests');
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (Array.isArray(value)) {
|
|
99
|
+
if (value.length > this.limits.maxArrayElements) {
|
|
100
|
+
throw new InputError(`Array exceeds maximum elements at "${path}"`, { path, length: value.length, limit: this.limits.maxArrayElements }, 'Reduce the number of array elements or split into multiple requests');
|
|
101
|
+
}
|
|
102
|
+
value.forEach((item, index) => {
|
|
103
|
+
this.validateValue(item, depth + 1, `${path}[${index}]`);
|
|
104
|
+
});
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (typeof value === 'object') {
|
|
108
|
+
const keys = Object.keys(value);
|
|
109
|
+
if (keys.length > this.limits.maxObjectKeys) {
|
|
110
|
+
throw new InputError(`Object exceeds maximum keys at "${path}"`, { path, count: keys.length, limit: this.limits.maxObjectKeys }, 'Reduce the number of object properties or split into multiple requests');
|
|
111
|
+
}
|
|
112
|
+
for (const key of keys) {
|
|
113
|
+
this.validateValue(value[key], depth + 1, `${path}.${key}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if a key name appears to contain sensitive data
|
|
119
|
+
*/
|
|
120
|
+
isSensitiveKey(key) {
|
|
121
|
+
return SENSITIVE_PATTERNS.some((pattern) => pattern.test(key));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Redact sensitive values in an object (for logging/errors)
|
|
125
|
+
*/
|
|
126
|
+
redactSensitive(data) {
|
|
127
|
+
return this.redactValue(data);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Recursively redact sensitive values
|
|
131
|
+
*/
|
|
132
|
+
redactValue(value) {
|
|
133
|
+
if (value === null || value === undefined) {
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
if (Array.isArray(value)) {
|
|
137
|
+
return value.map((item) => this.redactValue(item));
|
|
138
|
+
}
|
|
139
|
+
if (typeof value === 'object') {
|
|
140
|
+
const result = {};
|
|
141
|
+
for (const [key, val] of Object.entries(value)) {
|
|
142
|
+
if (this.isSensitiveKey(key)) {
|
|
143
|
+
result[key] = '[REDACTED]';
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
result[key] = this.redactValue(val);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Sanitize error message to remove sensitive paths and data
|
|
155
|
+
*/
|
|
156
|
+
sanitizeErrorMessage(message) {
|
|
157
|
+
let sanitized = message;
|
|
158
|
+
// Redact file paths
|
|
159
|
+
for (const pattern of PATH_PATTERNS) {
|
|
160
|
+
sanitized = sanitized.replace(pattern, '[PATH]');
|
|
161
|
+
}
|
|
162
|
+
// Redact URLs with credentials
|
|
163
|
+
sanitized = sanitized.replace(/https?:\/\/[^:]+:[^@]+@[^\s]+/g, '[URL_WITH_CREDENTIALS]');
|
|
164
|
+
// Redact base64 that might be auth headers
|
|
165
|
+
sanitized = sanitized.replace(/Basic\s+[A-Za-z0-9+/]+=*/gi, 'Basic [REDACTED]');
|
|
166
|
+
// Redact bearer tokens
|
|
167
|
+
sanitized = sanitized.replace(/Bearer\s+[A-Za-z0-9._-]+/gi, 'Bearer [REDACTED]');
|
|
168
|
+
return sanitized;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Sanitize an error object for safe logging
|
|
172
|
+
*/
|
|
173
|
+
sanitizeError(error) {
|
|
174
|
+
const sanitizedMessage = this.sanitizeErrorMessage(error.message);
|
|
175
|
+
if (sanitizedMessage === error.message) {
|
|
176
|
+
return error;
|
|
177
|
+
}
|
|
178
|
+
const sanitizedError = new Error(sanitizedMessage);
|
|
179
|
+
sanitizedError.name = error.name;
|
|
180
|
+
if (error.stack) {
|
|
181
|
+
sanitizedError.stack = this.sanitizeErrorMessage(error.stack);
|
|
182
|
+
}
|
|
183
|
+
return sanitizedError;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Singleton instance
|
|
188
|
+
*/
|
|
189
|
+
let instance = null;
|
|
190
|
+
/**
|
|
191
|
+
* Get the input sanitizer singleton
|
|
192
|
+
*/
|
|
193
|
+
export function getInputSanitizer() {
|
|
194
|
+
if (!instance) {
|
|
195
|
+
instance = new InputSanitizer();
|
|
196
|
+
}
|
|
197
|
+
return instance;
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=input-sanitizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-sanitizer.js","sourceRoot":"","sources":["../../src/validation/input-sanitizer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,4BAA4B;IAC5B,eAAe,EAAE,KAAK,EAAE,OAAO;IAC/B,6BAA6B;IAC7B,gBAAgB,EAAE,IAAI;IACtB,2BAA2B;IAC3B,cAAc,EAAE,EAAE;IAClB,0BAA0B;IAC1B,aAAa,EAAE,GAAG;IAClB,6CAA6C;IAC7C,YAAY,EAAE,OAAO,EAAE,MAAM;CACrB,CAAC;AAaX;;GAEG;AACH,MAAM,kBAAkB,GAAG;IACzB,WAAW;IACX,SAAS;IACT,QAAQ;IACR,cAAc;IACd,OAAO;IACP,aAAa;IACb,kBAAkB;IAClB,SAAS;IACT,kBAAkB;IAClB,qBAAqB;CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,aAAa,GAAG;IACpB,iBAAiB;IACjB,mBAAmB;IACnB,kBAAkB;IAClB,qBAAqB;IACrB,qBAAqB;IACrB,0BAA0B;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,cAAc;IACR,MAAM,CAA4B;IAEnD,YAAY,OAAyB;QACnC,IAAI,CAAC,MAAM,GAAG;YACZ,eAAe,EAAE,OAAO,EAAE,eAAe,IAAI,cAAc,CAAC,eAAe;YAC3E,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,IAAI,cAAc,CAAC,gBAAgB;YAC9E,cAAc,EAAE,OAAO,EAAE,cAAc,IAAI,cAAc,CAAC,cAAc;YACxE,aAAa,EAAE,OAAO,EAAE,aAAa,IAAI,cAAc,CAAC,aAAa;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@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Validator for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* AJV-based input validation against ability JSON schemas.
|
|
5
|
+
* Caches compiled schemas for performance.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Validation result
|
|
9
|
+
*/
|
|
10
|
+
export interface ValidationResult {
|
|
11
|
+
valid: boolean;
|
|
12
|
+
errors?: ValidationError[];
|
|
13
|
+
/** Coerced copy of input after AJV applies type coercion and defaults */
|
|
14
|
+
coerced?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Structured validation error
|
|
18
|
+
*/
|
|
19
|
+
export interface ValidationError {
|
|
20
|
+
path: string;
|
|
21
|
+
message: string;
|
|
22
|
+
keyword: string;
|
|
23
|
+
params: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Schema Validator class
|
|
27
|
+
*/
|
|
28
|
+
export declare class SchemaValidator {
|
|
29
|
+
private readonly ajv;
|
|
30
|
+
private readonly schemaCache;
|
|
31
|
+
constructor();
|
|
32
|
+
/**
|
|
33
|
+
* Validate input against a JSON schema
|
|
34
|
+
*
|
|
35
|
+
* @param input - The input data to validate
|
|
36
|
+
* @param schema - The JSON schema to validate against
|
|
37
|
+
* @param schemaId - Optional ID for caching compiled schema
|
|
38
|
+
* @returns Validation result with any errors
|
|
39
|
+
*/
|
|
40
|
+
validate(input: Record<string, unknown>, schema: Record<string, unknown>, schemaId?: string): ValidationResult;
|
|
41
|
+
/**
|
|
42
|
+
* Validate input and throw if invalid
|
|
43
|
+
*
|
|
44
|
+
* @param input - The input data to validate
|
|
45
|
+
* @param schema - The JSON schema to validate against
|
|
46
|
+
* @param abilityName - Name of the ability (for error message)
|
|
47
|
+
* @throws SchemaValidationError if validation fails
|
|
48
|
+
*/
|
|
49
|
+
validateOrThrow(input: Record<string, unknown>, schema: Record<string, unknown>, abilityName: string): ValidationResult;
|
|
50
|
+
/**
|
|
51
|
+
* Check if input would be valid (without detailed errors)
|
|
52
|
+
*/
|
|
53
|
+
isValid(input: Record<string, unknown>, schema: Record<string, unknown>, schemaId?: string): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Get or compile schema
|
|
56
|
+
*/
|
|
57
|
+
private getCompiledSchema;
|
|
58
|
+
/**
|
|
59
|
+
* Format AJV errors into structured errors
|
|
60
|
+
*/
|
|
61
|
+
private formatErrors;
|
|
62
|
+
/**
|
|
63
|
+
* Format a single error into a human-readable message
|
|
64
|
+
*/
|
|
65
|
+
private formatErrorMessage;
|
|
66
|
+
/**
|
|
67
|
+
* Clear the schema cache
|
|
68
|
+
*/
|
|
69
|
+
clearCache(): void;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get the schema validator singleton
|
|
73
|
+
*/
|
|
74
|
+
export declare function getSchemaValidator(): SchemaValidator;
|
|
75
|
+
//# sourceMappingURL=schema-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-validator.d.ts","sourceRoot":"","sources":["../../src/validation/schema-validator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC;IAC3B,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAKD;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAc;IAClC,OAAO,CAAC,QAAQ,CA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