Skip to content

🔒 SECURITY: Validate DEVFLOW_DIR environment variable #5

@dean0x

Description

@dean0x

Security Issue: Path Injection via DEVFLOW_DIR

Severity: HIGH
Priority: CRITICAL
Category: Input Validation

Problem

The getDevFlowDirectory() function accepts DEVFLOW_DIR environment variable without validation:

function getDevFlowDirectory(): string {
  if (process.env.DEVFLOW_DIR) {
    return process.env.DEVFLOW_DIR;  // ⚠️ No validation!
  }
  return path.join(getHomeDirectory(), '.devflow');
}

Attack Vector:

DEVFLOW_DIR=/tmp/malicious npx devflow-kit init
# settings.json now points to: /tmp/malicious/scripts/statusline.sh
# Attacker controls code executed by Claude Code

Impact

  • Full code execution with user privileges
  • Arbitrary command execution via malicious statusline.sh
  • No user awareness of compromise

Solution

Validate that DEVFLOW_DIR is under home directory:

function getDevFlowDirectory(): string {
  if (process.env.DEVFLOW_DIR) {
    const dir = process.env.DEVFLOW_DIR;
    const home = getHomeDirectory();
    const resolved = path.resolve(dir);
    
    // Only allow paths under home directory
    if (!resolved.startsWith(home)) {
      console.warn('⚠️  DEVFLOW_DIR must be under home directory, using default');
      return path.join(home, '.devflow');
    }
    return resolved;
  }
  return path.join(getHomeDirectory(), '.devflow');
}

Files to Modify

  • src/cli/commands/init.ts:39-45

Acceptance Criteria

  • DEVFLOW_DIR is validated to be under home directory
  • Warning logged if invalid path is provided
  • Fallback to default path on validation failure
  • Add test coverage for validation logic
  • Update documentation with security note

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions