Class: KairosMcp::Daemon::RestrictedShell::GitArgvValidator

Inherits:
BaseArgvValidator show all
Defined in:
lib/kairos_mcp/daemon/restricted_shell/argv_validators.rb

Overview

Git: allowlisted subcommands + env scrub + forbidden flags.

Constant Summary collapse

ALLOWED_SUBCOMMANDS =
%w[status diff log show rev-parse ls-files].freeze
FORBIDDEN_FLAGS =
%w[-c -C --exec-path --git-dir --work-tree].freeze

Constants inherited from BaseArgvValidator

BaseArgvValidator::UNIVERSAL_FORBIDDEN

Class Method Summary collapse

Methods inherited from BaseArgvValidator

validate!

Class Method Details

.validate_specific!(argv) ⇒ Object

Raises:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/kairos_mcp/daemon/restricted_shell/argv_validators.rb', line 29

def self.validate_specific!(argv)
  # Check global forbidden flags
  argv.each do |arg|
    # Exact match for short flags (-c, -C)
    raise PolicyViolation, "forbidden git flag: #{arg}" if arg == '-c' || arg == '-C'
    # Prefix match for long flags
    %w[--exec-path --git-dir --work-tree].each do |f|
      raise PolicyViolation, "forbidden git flag: #{arg}" if arg.start_with?(f)
    end
  end

  sub = argv.first
  raise PolicyViolation, 'git subcommand required' unless sub
  raise PolicyViolation, "git #{sub} not allowed" unless ALLOWED_SUBCOMMANDS.include?(sub)
end