-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Background
As identified in PR #8, the current approach of using string interpolation when executing Lagoon CLI commands creates potential command injection vulnerabilities.
Problem
Currently, command arguments (like instance names, project names, branch names, etc.) are interpolated directly into shell command strings:
const command = `lagoon -l ${instance} -p ${project} deploy branch --branch ${branch} --output-json`;
const { stdout } = await execLagoonCommand(command, `Deploy Branch ${branch} to ${project}`);While we've implemented regex validation in some places, this approach is still vulnerable to command injection if an argument contains shell metacharacters.
Proposed Solution
Replace string interpolation with Node.js spawn or execFile functions to pass arguments securely:
const { stdout } = await util.promisify(child_process.execFile)('lagoon', [
'-l', instance,
'-p', project,
'deploy', 'branch',
'--branch', branch,
'--output-json'
]);Or using spawn with proper output handling:
const lagoonProcess = child_process.spawn('lagoon', [
'-l', instance,
'-p', project,
'deploy', 'branch',
'--branch', branch,
'--output-json'
]);
// Handle output streams appropriatelyImplementation Plan
- Create a new secure wrapper function for Lagoon CLI calls
- Refactor all instances of
execLagoonCommandto use the new wrapper - Update the logging mechanism to work with the new approach
- Add tests to verify the security of the implementation
Benefits
- Eliminates command injection vulnerabilities
- More maintainable and secure code
- No need for complex regex validation of input parameters
- Explicit separation of command and arguments improves readability
Related
- PR [#1] Implemented branch deployment feature. #8: Implemented branch deployment feature
- Discussion: [#1] Implemented branch deployment feature. #8 (comment)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels