Class: Klee::MCP::PathValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/klee/mcp/path_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(allowed_roots: [Dir.pwd]) ⇒ PathValidator

Returns a new instance of PathValidator.



6
7
8
# File 'lib/klee/mcp/path_validator.rb', line 6

def initialize(allowed_roots: [Dir.pwd])
  @allowed_roots = allowed_roots.map { |r| File.expand_path(r) }
end

Instance Method Details

#validate!(patterns) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/klee/mcp/path_validator.rb', line 10

def validate!(patterns)
  patterns.each do |pattern|
    expanded = expand_pattern_root(pattern)
    unless allowed?(expanded)
      raise SecurityError, "Pattern '#{pattern}' resolves to '#{expanded}' which is outside allowed roots: #{@allowed_roots.join(", ")}"
    end
  end
end