Skip to content

Security Enhancement: Switch to spawn/execFile for Lagoon CLI command execution #11

@coderabbitai

Description

@coderabbitai

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 appropriately

Implementation Plan

  1. Create a new secure wrapper function for Lagoon CLI calls
  2. Refactor all instances of execLagoonCommand to use the new wrapper
  3. Update the logging mechanism to work with the new approach
  4. 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

cc @richardgaunt

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions