Module: RosettAi::YamlLoader
- Defined in:
- lib/rosett_ai/yaml_loader.rb
Overview
Centralized YAML loading with bounds checking.
Enforces file-size, nesting-depth, and key-count limits to prevent denial-of-service via maliciously crafted YAML payloads.
Constant Summary collapse
- MAX_FILE_SIZE =
1 MB
1_048_576- MAX_DEPTH =
Returns Maximum nesting depth for YAML loading.
10- MAX_KEY_COUNT =
Returns Maximum number of keys allowed in loaded YAML.
1000
Class Method Summary collapse
-
.load_file(path, permitted_classes: [Date, Time]) ⇒ Hash
Loads and validates a YAML file with bounds checking.
Class Method Details
.load_file(path, permitted_classes: [Date, Time]) ⇒ Hash
Loads and validates a YAML file with bounds checking.
Enforces file size, nesting depth, and key count limits before returning the parsed data.
30 31 32 33 34 35 36 |
# File 'lib/rosett_ai/yaml_loader.rb', line 30 def self.load_file(path, permitted_classes: [Date, Time]) check_file_size!(path) data = YAML.safe_load_file(path, permitted_classes: permitted_classes) check_depth!(data, path) check_key_count!(data, path) data end |