[Bug Hunt][Cycle 2][Config] Unlimited file size loading in configuration parsers #7162

Open
opened 2026-04-10 08:21:45 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Branch: fix/bug-hunt-cycle2/config-unlimited-file-size-loading
  • Commit Message: fix(config): add file size limits to ReactiveConfigParser and ConfigService to prevent memory exhaustion
  • Milestone: None (Backlog)
  • Parent Epic: #5502

Backlog note: This issue was discovered during autonomous operation
on milestone v3.2.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.

Background

Configuration parsers in ReactiveConfigParser and ConfigService load entire files into memory without any size limits or streaming support. This creates a resource management vulnerability where a malicious or accidentally oversized configuration file could cause memory exhaustion and denial of service.

This violates the project's fail-fast and argument validation principles (CONTRIBUTING.md §Error and Exception Handling): public methods must validate inputs — including implicit inputs such as file sizes — before performing operations.

Current Behavior

ReactiveConfigParser (src/cleveragents/reactive/config_parser.py, line 69)

content = Path(file_path).read_text(encoding="utf-8")  # No size limit
data = yaml.safe_load(content) or {}

The entire file is read into memory unconditionally, with no check on file size before loading.

ConfigService (src/cleveragents/application/services/config_service.py, lines 1250–1258)

def read_merged_config(self) -> dict[str, Any]:
    merged = self.read_config()          # Load global config
    merged = _deep_merge(merged, self.read_project_config())  # Load project config
    merged = _deep_merge(merged, self.read_local_config())    # Load local config
    return merged

Multiple configuration files are loaded simultaneously into memory without any size guard, compounding the memory impact.

Expected Behavior

Configuration file loading should enforce reasonable size limits before reading file contents into memory. A file exceeding the limit should raise a clear, descriptive error rather than silently consuming all available memory.

Suggested approach:

  1. Add a MAX_CONFIG_FILE_SIZE constant (e.g., 10 MB) as a module-level guard.
  2. In ReactiveConfigParser.parse_files() and all ConfigService.read_*_config() methods, check path.stat().st_size before calling read_text(). Raise ValueError with a descriptive message if the limit is exceeded.
  3. Optionally expose the limit as a configurable option for deployments with legitimate large configs.

Actual Behavior

A malicious or accidentally large configuration file (e.g., a 500 MB YAML file) can be passed to either parser, causing the process to attempt loading the entire file into memory. This can exhaust available RAM, triggering OOM kills or severe performance degradation — a denial-of-service condition.

Severity Assessment

  • Impact: Large configuration files could cause memory exhaustion and denial of service
  • Likelihood: Low to Medium — depends on deployment context with user-controlled config files
  • Priority: Medium

Affected Files

  • src/cleveragents/reactive/config_parser.pyReactiveConfigParser.parse_files() (line 69)
  • src/cleveragents/application/services/config_service.pyConfigService.read_merged_config() and related read_*_config() methods (lines 1250–1258)

Subtasks

  • Add MAX_CONFIG_FILE_SIZE constant to config_parser.py (e.g., 10 * 1024 * 1024 bytes)
  • Add file size check in ReactiveConfigParser.parse_files() before read_text()
  • Add MAX_CONFIG_FILE_SIZE constant to config_service.py
  • Add file size check in ConfigService.read_config(), read_project_config(), and read_local_config() before reading file contents
  • Raise ValueError with a descriptive message when the size limit is exceeded
  • Tests (Behave): Add scenarios for oversized config file rejection in both parsers
  • Tests (Robot): Add integration test for config loading size guard
  • Verify coverage >= 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • Both ReactiveConfigParser.parse_files() and all ConfigService.read_*_config() methods reject files exceeding MAX_CONFIG_FILE_SIZE with a clear ValueError.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
  • All nox stages pass.
  • Coverage >= 97%.

TDD Note

After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. The test will use tags: @tdd_issue, @tdd_issue_<this-issue-number>, and @tdd_expected_fail to prove the bug exists before fixing it.


Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: new-issue-creator

## Metadata - **Branch**: `fix/bug-hunt-cycle2/config-unlimited-file-size-loading` - **Commit Message**: `fix(config): add file size limits to ReactiveConfigParser and ConfigService to prevent memory exhaustion` - **Milestone**: None (Backlog) - **Parent Epic**: #5502 > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.2.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. ## Background Configuration parsers in `ReactiveConfigParser` and `ConfigService` load entire files into memory without any size limits or streaming support. This creates a resource management vulnerability where a malicious or accidentally oversized configuration file could cause memory exhaustion and denial of service. This violates the project's fail-fast and argument validation principles (CONTRIBUTING.md §Error and Exception Handling): public methods must validate inputs — including implicit inputs such as file sizes — before performing operations. ## Current Behavior ### ReactiveConfigParser (`src/cleveragents/reactive/config_parser.py`, line 69) ```python content = Path(file_path).read_text(encoding="utf-8") # No size limit data = yaml.safe_load(content) or {} ``` The entire file is read into memory unconditionally, with no check on file size before loading. ### ConfigService (`src/cleveragents/application/services/config_service.py`, lines 1250–1258) ```python def read_merged_config(self) -> dict[str, Any]: merged = self.read_config() # Load global config merged = _deep_merge(merged, self.read_project_config()) # Load project config merged = _deep_merge(merged, self.read_local_config()) # Load local config return merged ``` Multiple configuration files are loaded simultaneously into memory without any size guard, compounding the memory impact. ## Expected Behavior Configuration file loading should enforce reasonable size limits before reading file contents into memory. A file exceeding the limit should raise a clear, descriptive error rather than silently consuming all available memory. Suggested approach: 1. Add a `MAX_CONFIG_FILE_SIZE` constant (e.g., 10 MB) as a module-level guard. 2. In `ReactiveConfigParser.parse_files()` and all `ConfigService.read_*_config()` methods, check `path.stat().st_size` before calling `read_text()`. Raise `ValueError` with a descriptive message if the limit is exceeded. 3. Optionally expose the limit as a configurable option for deployments with legitimate large configs. ## Actual Behavior A malicious or accidentally large configuration file (e.g., a 500 MB YAML file) can be passed to either parser, causing the process to attempt loading the entire file into memory. This can exhaust available RAM, triggering OOM kills or severe performance degradation — a denial-of-service condition. ## Severity Assessment - **Impact**: Large configuration files could cause memory exhaustion and denial of service - **Likelihood**: Low to Medium — depends on deployment context with user-controlled config files - **Priority**: Medium ## Affected Files - `src/cleveragents/reactive/config_parser.py` — `ReactiveConfigParser.parse_files()` (line 69) - `src/cleveragents/application/services/config_service.py` — `ConfigService.read_merged_config()` and related `read_*_config()` methods (lines 1250–1258) ## Subtasks - [ ] Add `MAX_CONFIG_FILE_SIZE` constant to `config_parser.py` (e.g., `10 * 1024 * 1024` bytes) - [ ] Add file size check in `ReactiveConfigParser.parse_files()` before `read_text()` - [ ] Add `MAX_CONFIG_FILE_SIZE` constant to `config_service.py` - [ ] Add file size check in `ConfigService.read_config()`, `read_project_config()`, and `read_local_config()` before reading file contents - [ ] Raise `ValueError` with a descriptive message when the size limit is exceeded - [ ] Tests (Behave): Add scenarios for oversized config file rejection in both parsers - [ ] Tests (Robot): Add integration test for config loading size guard - [ ] Verify coverage >= 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - Both `ReactiveConfigParser.parse_files()` and all `ConfigService.read_*_config()` methods reject files exceeding `MAX_CONFIG_FILE_SIZE` with a clear `ValueError`. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. - All nox stages pass. - Coverage >= 97%. ## TDD Note After this bug issue is verified, a corresponding `Type/Testing` issue will be created for TDD. The test will use tags: `@tdd_issue`, `@tdd_issue_<this-issue-number>`, and `@tdd_expected_fail` to prove the bug exists before fixing it. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: new-issue-creator
Author
Owner

Verified — Bug: unlimited file size loading in config parsers — DoS risk. MoSCoW: Should-have. Priority: Medium.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — Bug: unlimited file size loading in config parsers — DoS risk. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core#7162
No description provided.