Class: LittleGhost::TrustedPath

Inherits:
Data
  • Object
show all
Defined in:
lib/little_ghost/prompt_resolver.rb,
lib/little_ghost/prompt_resolver.rb

Overview

Marks a caller-supplied prompt directory as trusted application code. Construction resolves symbolic links immediately and rejects paths that are missing or are not directories.

Security and trust

Construction is a trust assertion, not a sanitizer. It does not inspect ownership, permissions, or who can modify the directory. ERB templates run as Ruby inside the current process, so create TrustedPath values only from allowlisted, application-controlled, non-user-writable roots. Never wrap a path taken from unchecked request or model input.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ TrustedPath

Returns a new instance of TrustedPath.



12
13
14
15
16
17
18
# File 'lib/little_ghost/prompt_resolver.rb', line 12

def initialize(path:)
  expanded = File.realpath(path)
  raise ArgumentError, "trusted template path must be a directory" unless File.directory?(expanded)
  super(path: expanded.freeze)
rescue Errno::ENOENT
  raise ArgumentError, "trusted template path must exist"
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



11
12
13
# File 'lib/little_ghost/prompt_resolver.rb', line 11

def path
  @path
end