@eldrforge/git-tools 0.1.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/dist/child.js ADDED
@@ -0,0 +1,212 @@
1
+ import { spawn, exec } from 'child_process';
2
+ import util from 'util';
3
+ import { getLogger } from './logger.js';
4
+
5
+ /**
6
+ * Escapes shell arguments to prevent command injection
7
+ */ function escapeShellArg(arg) {
8
+ // For Windows, we need different escaping
9
+ if (process.platform === 'win32') {
10
+ // Escape double quotes and backslashes
11
+ return `"${arg.replace(/[\\"]/g, '\\$&')}"`;
12
+ } else {
13
+ // For Unix-like systems, escape single quotes
14
+ return `'${arg.replace(/'/g, "'\\''")}'`;
15
+ }
16
+ }
17
+ /**
18
+ * Validates git references to prevent injection
19
+ */ function validateGitRef(ref) {
20
+ // Git refs can contain letters, numbers, hyphens, underscores, slashes, and dots
21
+ // But cannot contain certain dangerous characters
22
+ const validRefPattern = /^[a-zA-Z0-9._/-]+$/;
23
+ const invalidPatterns = [
24
+ /\.\./,
25
+ /^-/,
26
+ /[\s;<>|&`$(){}[\]]/ // No shell metacharacters
27
+ ];
28
+ if (!validRefPattern.test(ref)) {
29
+ return false;
30
+ }
31
+ return !invalidPatterns.some((pattern)=>pattern.test(ref));
32
+ }
33
+ /**
34
+ * Validates file paths to prevent injection
35
+ */ function validateFilePath(filePath) {
36
+ // Basic validation - no shell metacharacters
37
+ const invalidChars = /[;<>|&`$(){}[\]]/;
38
+ return !invalidChars.test(filePath);
39
+ }
40
+ /**
41
+ * Securely executes a command with arguments array (no shell injection risk)
42
+ */ async function runSecure(command, args = [], options = {}) {
43
+ const logger = getLogger();
44
+ return new Promise((resolve, reject)=>{
45
+ logger.verbose(`Executing command securely: ${command} ${args.join(' ')}`);
46
+ logger.verbose(`Working directory: ${(options === null || options === void 0 ? void 0 : options.cwd) || process.cwd()}`);
47
+ const child = spawn(command, args, {
48
+ ...options,
49
+ shell: false,
50
+ stdio: 'pipe'
51
+ });
52
+ let stdout = '';
53
+ let stderr = '';
54
+ if (child.stdout) {
55
+ child.stdout.on('data', (data)=>{
56
+ stdout += data.toString();
57
+ });
58
+ }
59
+ if (child.stderr) {
60
+ child.stderr.on('data', (data)=>{
61
+ stderr += data.toString();
62
+ });
63
+ }
64
+ child.on('close', (code)=>{
65
+ if (code === 0) {
66
+ logger.verbose(`Command completed successfully`);
67
+ logger.verbose(`stdout: ${stdout}`);
68
+ if (stderr) {
69
+ logger.verbose(`stderr: ${stderr}`);
70
+ }
71
+ resolve({
72
+ stdout,
73
+ stderr
74
+ });
75
+ } else {
76
+ logger.error(`Command failed with exit code ${code}`);
77
+ logger.error(`stdout: ${stdout}`);
78
+ logger.error(`stderr: ${stderr}`);
79
+ reject(new Error(`Command "${[
80
+ command,
81
+ ...args
82
+ ].join(' ')}" failed with exit code ${code}`));
83
+ }
84
+ });
85
+ child.on('error', (error)=>{
86
+ logger.error(`Command failed to start: ${error.message}`);
87
+ reject(error);
88
+ });
89
+ });
90
+ }
91
+ /**
92
+ * Securely executes a command with inherited stdio (no shell injection risk)
93
+ */ async function runSecureWithInheritedStdio(command, args = [], options = {}) {
94
+ const logger = getLogger();
95
+ return new Promise((resolve, reject)=>{
96
+ logger.verbose(`Executing command securely with inherited stdio: ${command} ${args.join(' ')}`);
97
+ logger.verbose(`Working directory: ${(options === null || options === void 0 ? void 0 : options.cwd) || process.cwd()}`);
98
+ const child = spawn(command, args, {
99
+ ...options,
100
+ shell: false,
101
+ stdio: 'inherit'
102
+ });
103
+ child.on('close', (code)=>{
104
+ if (code === 0) {
105
+ logger.verbose(`Command completed successfully with code ${code}`);
106
+ resolve();
107
+ } else {
108
+ logger.error(`Command failed with exit code ${code}`);
109
+ reject(new Error(`Command "${[
110
+ command,
111
+ ...args
112
+ ].join(' ')}" failed with exit code ${code}`));
113
+ }
114
+ });
115
+ child.on('error', (error)=>{
116
+ logger.error(`Command failed to start: ${error.message}`);
117
+ reject(error);
118
+ });
119
+ });
120
+ }
121
+ async function run(command, options = {}) {
122
+ const logger = getLogger();
123
+ const execPromise = util.promisify(exec);
124
+ // Ensure encoding is set to 'utf8' to get string output instead of Buffer
125
+ const execOptions = {
126
+ encoding: 'utf8',
127
+ ...options
128
+ };
129
+ logger.verbose(`Executing command: ${command}`);
130
+ logger.verbose(`Working directory: ${(execOptions === null || execOptions === void 0 ? void 0 : execOptions.cwd) || process.cwd()}`);
131
+ logger.verbose(`Environment variables: ${Object.keys((execOptions === null || execOptions === void 0 ? void 0 : execOptions.env) || process.env).length} variables`);
132
+ try {
133
+ const result = await execPromise(command, execOptions);
134
+ logger.verbose(`Command completed successfully`);
135
+ logger.verbose(`stdout: ${result.stdout}`);
136
+ if (result.stderr) {
137
+ logger.verbose(`stderr: ${result.stderr}`);
138
+ }
139
+ // Ensure result is properly typed as strings
140
+ return {
141
+ stdout: String(result.stdout),
142
+ stderr: String(result.stderr)
143
+ };
144
+ } catch (error) {
145
+ logger.error(`Command failed: ${command}`);
146
+ logger.error(`Error: ${error.message}`);
147
+ logger.error(`Exit code: ${error.code}`);
148
+ logger.error(`Signal: ${error.signal}`);
149
+ if (error.stdout) {
150
+ logger.error(`stdout: ${error.stdout}`);
151
+ }
152
+ if (error.stderr) {
153
+ logger.error(`stderr: ${error.stderr}`);
154
+ }
155
+ throw error;
156
+ }
157
+ }
158
+ /**
159
+ * @deprecated Use runSecureWithInheritedStdio instead for better security
160
+ * Legacy function for backward compatibility - parses shell command string
161
+ */ async function runWithInheritedStdio(command, options = {}) {
162
+ // Parse command to extract command and arguments safely
163
+ const parts = command.trim().split(/\s+/);
164
+ if (parts.length === 0) {
165
+ throw new Error('Empty command provided');
166
+ }
167
+ const cmd = parts[0];
168
+ const args = parts.slice(1);
169
+ // Use the secure version
170
+ return runSecureWithInheritedStdio(cmd, args, options);
171
+ }
172
+ async function runWithDryRunSupport(command, isDryRun, options = {}, useInheritedStdio = false) {
173
+ const logger = getLogger();
174
+ if (isDryRun) {
175
+ logger.info(`DRY RUN: Would execute command: ${command}`);
176
+ return {
177
+ stdout: '',
178
+ stderr: ''
179
+ };
180
+ }
181
+ if (useInheritedStdio) {
182
+ await runWithInheritedStdio(command, options);
183
+ return {
184
+ stdout: '',
185
+ stderr: ''
186
+ }; // No output captured when using inherited stdio
187
+ }
188
+ return run(command, options);
189
+ }
190
+ /**
191
+ * Secure version of runWithDryRunSupport using argument arrays
192
+ */ async function runSecureWithDryRunSupport(command, args = [], isDryRun, options = {}, useInheritedStdio = false) {
193
+ const logger = getLogger();
194
+ if (isDryRun) {
195
+ logger.info(`DRY RUN: Would execute command: ${command} ${args.join(' ')}`);
196
+ return {
197
+ stdout: '',
198
+ stderr: ''
199
+ };
200
+ }
201
+ if (useInheritedStdio) {
202
+ await runSecureWithInheritedStdio(command, args, options);
203
+ return {
204
+ stdout: '',
205
+ stderr: ''
206
+ }; // No output captured when using inherited stdio
207
+ }
208
+ return runSecure(command, args, options);
209
+ }
210
+
211
+ export { escapeShellArg, run, runSecure, runSecureWithDryRunSupport, runSecureWithInheritedStdio, runWithDryRunSupport, runWithInheritedStdio, validateFilePath, validateGitRef };
212
+ //# sourceMappingURL=child.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"child.js","sources":["../src/child.ts"],"sourcesContent":["#!/usr/bin/env node\nimport child_process, { exec, spawn } from 'child_process';\nimport util from 'util';\nimport { getLogger } from './logger';\n\n/**\n * Escapes shell arguments to prevent command injection\n */\nfunction escapeShellArg(arg: string): string {\n // For Windows, we need different escaping\n if (process.platform === 'win32') {\n // Escape double quotes and backslashes\n return `\"${arg.replace(/[\\\\\"]/g, '\\\\$&')}\"`;\n } else {\n // For Unix-like systems, escape single quotes\n return `'${arg.replace(/'/g, \"'\\\\''\")}'`;\n }\n}\n\n/**\n * Validates git references to prevent injection\n */\nfunction validateGitRef(ref: string): boolean {\n // Git refs can contain letters, numbers, hyphens, underscores, slashes, and dots\n // But cannot contain certain dangerous characters\n const validRefPattern = /^[a-zA-Z0-9._/-]+$/;\n const invalidPatterns = [\n /\\.\\./, // No double dots (directory traversal)\n /^-/, // Cannot start with dash (flag injection)\n /[\\s;<>|&`$(){}[\\]]/ // No shell metacharacters\n ];\n\n if (!validRefPattern.test(ref)) {\n return false;\n }\n\n return !invalidPatterns.some(pattern => pattern.test(ref));\n}\n\n/**\n * Validates file paths to prevent injection\n */\nfunction validateFilePath(filePath: string): boolean {\n // Basic validation - no shell metacharacters\n const invalidChars = /[;<>|&`$(){}[\\]]/;\n return !invalidChars.test(filePath);\n}\n\n/**\n * Securely executes a command with arguments array (no shell injection risk)\n */\nexport async function runSecure(\n command: string,\n args: string[] = [],\n options: child_process.SpawnOptions = {}\n): Promise<{ stdout: string; stderr: string }> {\n const logger = getLogger();\n\n return new Promise((resolve, reject) => {\n logger.verbose(`Executing command securely: ${command} ${args.join(' ')}`);\n logger.verbose(`Working directory: ${options?.cwd || process.cwd()}`);\n\n const child = spawn(command, args, {\n ...options,\n shell: false, // CRITICAL: Never use shell for user input\n stdio: 'pipe'\n });\n\n let stdout = '';\n let stderr = '';\n\n if (child.stdout) {\n child.stdout.on('data', (data) => {\n stdout += data.toString();\n });\n }\n\n if (child.stderr) {\n child.stderr.on('data', (data) => {\n stderr += data.toString();\n });\n }\n\n child.on('close', (code) => {\n if (code === 0) {\n logger.verbose(`Command completed successfully`);\n logger.verbose(`stdout: ${stdout}`);\n if (stderr) {\n logger.verbose(`stderr: ${stderr}`);\n }\n resolve({ stdout, stderr });\n } else {\n logger.error(`Command failed with exit code ${code}`);\n logger.error(`stdout: ${stdout}`);\n logger.error(`stderr: ${stderr}`);\n reject(new Error(`Command \"${[command, ...args].join(' ')}\" failed with exit code ${code}`));\n }\n });\n\n child.on('error', (error) => {\n logger.error(`Command failed to start: ${error.message}`);\n reject(error);\n });\n });\n}\n\n/**\n * Securely executes a command with inherited stdio (no shell injection risk)\n */\nexport async function runSecureWithInheritedStdio(\n command: string,\n args: string[] = [],\n options: child_process.SpawnOptions = {}\n): Promise<void> {\n const logger = getLogger();\n\n return new Promise((resolve, reject) => {\n logger.verbose(`Executing command securely with inherited stdio: ${command} ${args.join(' ')}`);\n logger.verbose(`Working directory: ${options?.cwd || process.cwd()}`);\n\n const child = spawn(command, args, {\n ...options,\n shell: false, // CRITICAL: Never use shell for user input\n stdio: 'inherit'\n });\n\n child.on('close', (code) => {\n if (code === 0) {\n logger.verbose(`Command completed successfully with code ${code}`);\n resolve();\n } else {\n logger.error(`Command failed with exit code ${code}`);\n reject(new Error(`Command \"${[command, ...args].join(' ')}\" failed with exit code ${code}`));\n }\n });\n\n child.on('error', (error) => {\n logger.error(`Command failed to start: ${error.message}`);\n reject(error);\n });\n });\n}\n\nexport async function run(command: string, options: child_process.ExecOptions = {}): Promise<{ stdout: string; stderr: string }> {\n const logger = getLogger();\n const execPromise = util.promisify(exec);\n\n // Ensure encoding is set to 'utf8' to get string output instead of Buffer\n const execOptions = { encoding: 'utf8' as const, ...options };\n\n logger.verbose(`Executing command: ${command}`);\n logger.verbose(`Working directory: ${execOptions?.cwd || process.cwd()}`);\n logger.verbose(`Environment variables: ${Object.keys(execOptions?.env || process.env).length} variables`);\n\n try {\n const result = await execPromise(command, execOptions);\n logger.verbose(`Command completed successfully`);\n logger.verbose(`stdout: ${result.stdout}`);\n if (result.stderr) {\n logger.verbose(`stderr: ${result.stderr}`);\n }\n // Ensure result is properly typed as strings\n return {\n stdout: String(result.stdout),\n stderr: String(result.stderr)\n };\n } catch (error: any) {\n logger.error(`Command failed: ${command}`);\n logger.error(`Error: ${error.message}`);\n logger.error(`Exit code: ${error.code}`);\n logger.error(`Signal: ${error.signal}`);\n if (error.stdout) {\n logger.error(`stdout: ${error.stdout}`);\n }\n if (error.stderr) {\n logger.error(`stderr: ${error.stderr}`);\n }\n throw error;\n }\n}\n\n/**\n * @deprecated Use runSecureWithInheritedStdio instead for better security\n * Legacy function for backward compatibility - parses shell command string\n */\nexport async function runWithInheritedStdio(command: string, options: child_process.ExecOptions = {}): Promise<void> {\n\n // Parse command to extract command and arguments safely\n const parts = command.trim().split(/\\s+/);\n if (parts.length === 0) {\n throw new Error('Empty command provided');\n }\n\n const cmd = parts[0];\n const args = parts.slice(1);\n\n // Use the secure version\n return runSecureWithInheritedStdio(cmd, args, options);\n}\n\nexport async function runWithDryRunSupport(\n command: string,\n isDryRun: boolean,\n options: child_process.ExecOptions = {},\n useInheritedStdio: boolean = false\n): Promise<{ stdout: string; stderr: string }> {\n const logger = getLogger();\n\n if (isDryRun) {\n logger.info(`DRY RUN: Would execute command: ${command}`);\n return { stdout: '', stderr: '' };\n }\n\n if (useInheritedStdio) {\n await runWithInheritedStdio(command, options);\n return { stdout: '', stderr: '' }; // No output captured when using inherited stdio\n }\n\n return run(command, options);\n}\n\n/**\n * Secure version of runWithDryRunSupport using argument arrays\n */\nexport async function runSecureWithDryRunSupport(\n command: string,\n args: string[] = [],\n isDryRun: boolean,\n options: child_process.SpawnOptions = {},\n useInheritedStdio: boolean = false\n): Promise<{ stdout: string; stderr: string }> {\n const logger = getLogger();\n\n if (isDryRun) {\n logger.info(`DRY RUN: Would execute command: ${command} ${args.join(' ')}`);\n return { stdout: '', stderr: '' };\n }\n\n if (useInheritedStdio) {\n await runSecureWithInheritedStdio(command, args, options);\n return { stdout: '', stderr: '' }; // No output captured when using inherited stdio\n }\n\n return runSecure(command, args, options);\n}\n\n// Export validation functions for use in other modules\nexport { validateGitRef, validateFilePath, escapeShellArg };\n\n"],"names":["escapeShellArg","arg","process","platform","replace","validateGitRef","ref","validRefPattern","invalidPatterns","test","some","pattern","validateFilePath","filePath","invalidChars","runSecure","command","args","options","logger","getLogger","Promise","resolve","reject","verbose","join","cwd","child","spawn","shell","stdio","stdout","stderr","on","data","toString","code","error","Error","message","runSecureWithInheritedStdio","run","execPromise","util","promisify","exec","execOptions","encoding","Object","keys","env","length","result","String","signal","runWithInheritedStdio","parts","trim","split","cmd","slice","runWithDryRunSupport","isDryRun","useInheritedStdio","info","runSecureWithDryRunSupport"],"mappings":";;;;AAKA;;IAGA,SAASA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