fix(security): validate and sanitize correction flow inputs to prevent injection #8988

Open
opened 2026-04-14 04:35:30 +00:00 by HAL9000 · 1 comment
Owner

Background and Context

The v3.3.0 correction flow (plan correct --mode revert and --mode append) accepts user-provided inputs including decision IDs, guidance text, and plan identifiers. Without strict input validation and sanitization, these inputs could be used to inject malicious content into the decision tree, trigger unintended re-execution paths, or bypass authorization checks. The correction flow must validate all inputs at the CLI boundary before they reach the service layer, and the service layer must enforce its own validation as a defense-in-depth measure.

Acceptance Criteria

  • plan correct --mode revert <decision_id> validates that decision_id is a valid UUID belonging to the authenticated user's plan before processing
  • plan correct --mode append sanitizes guidance text to strip any template injection patterns (e.g., {var}, {{expr}}) before storing
  • Authorization check ensures the user owns the plan being corrected before any mutation occurs
  • Invalid or unauthorized correction attempts return a structured error with error code, not a stack trace
  • All correction inputs are logged (sanitized) to the audit log before processing
  • Test coverage >= 97%

Subtasks

  • Add CorrectionInputValidator class with validate_revert(decision_id, user_id) and validate_append(plan_id, guidance_text, user_id) methods
  • Add UUID format validation and ownership check for decision_id in revert mode
  • Add guidance text sanitizer that strips template injection patterns and enforces max length
  • Add authorization check in CorrectionEngine that verifies plan ownership before any mutation
  • Add structured error type CorrectionAuthorizationError with plan_id, user_id, and attempted_mode fields
  • Add pre-processing audit log entry for all correction attempts (before mutation)
  • Add docs/reference/correction_security.md documenting input validation rules
  • Tests (Behave): Add features/security_correction_validation.feature scenarios
  • Tests (Robot): Add robot/security_correction_validation.robot integration tests
  • Tests (ASV): Add benchmarks/security_correction_validation_bench.py for validation overhead
  • Verify coverage >= 97% via nox -s coverage_report; iterate until passing
  • Run nox (all default sessions including benchmark), fix any errors

Definition of Done

  • All acceptance criteria met
  • Tests written and passing (coverage >= 97%)
  • Code reviewed and approved
  • Documentation updated if needed
  • No regressions introduced

Metadata

  • Commit message: fix(security): validate and sanitize correction flow inputs to prevent injection
  • Branch name: fix/security-correction-validation

Automated by CleverAgents Bot
Supervisor: Epic Planning Pool | Agent: epic-planning-pool-supervisor

## Background and Context The v3.3.0 correction flow (`plan correct --mode revert` and `--mode append`) accepts user-provided inputs including decision IDs, guidance text, and plan identifiers. Without strict input validation and sanitization, these inputs could be used to inject malicious content into the decision tree, trigger unintended re-execution paths, or bypass authorization checks. The correction flow must validate all inputs at the CLI boundary before they reach the service layer, and the service layer must enforce its own validation as a defense-in-depth measure. ## Acceptance Criteria - [ ] `plan correct --mode revert <decision_id>` validates that `decision_id` is a valid UUID belonging to the authenticated user's plan before processing - [ ] `plan correct --mode append` sanitizes guidance text to strip any template injection patterns (e.g., `{var}`, `{{expr}}`) before storing - [ ] Authorization check ensures the user owns the plan being corrected before any mutation occurs - [ ] Invalid or unauthorized correction attempts return a structured error with error code, not a stack trace - [ ] All correction inputs are logged (sanitized) to the audit log before processing - [ ] Test coverage >= 97% ## Subtasks - [ ] Add `CorrectionInputValidator` class with `validate_revert(decision_id, user_id)` and `validate_append(plan_id, guidance_text, user_id)` methods - [ ] Add UUID format validation and ownership check for `decision_id` in revert mode - [ ] Add guidance text sanitizer that strips template injection patterns and enforces max length - [ ] Add authorization check in `CorrectionEngine` that verifies plan ownership before any mutation - [ ] Add structured error type `CorrectionAuthorizationError` with plan_id, user_id, and attempted_mode fields - [ ] Add pre-processing audit log entry for all correction attempts (before mutation) - [ ] Add `docs/reference/correction_security.md` documenting input validation rules - [ ] Tests (Behave): Add `features/security_correction_validation.feature` scenarios - [ ] Tests (Robot): Add `robot/security_correction_validation.robot` integration tests - [ ] Tests (ASV): Add `benchmarks/security_correction_validation_bench.py` for validation overhead - [ ] Verify coverage >= 97% via `nox -s coverage_report`; iterate until passing - [ ] Run `nox` (all default sessions including benchmark), fix any errors ## Definition of Done - [ ] All acceptance criteria met - [ ] Tests written and passing (coverage >= 97%) - [ ] Code reviewed and approved - [ ] Documentation updated if needed - [ ] No regressions introduced ## Metadata - **Commit message:** `fix(security): validate and sanitize correction flow inputs to prevent injection` - **Branch name:** `fix/security-correction-validation` --- **Automated by CleverAgents Bot** Supervisor: Epic Planning Pool | Agent: epic-planning-pool-supervisor
Author
Owner

Verified — Security fix: correction flow input validation/sanitization is required to prevent injection attacks. MoSCoW: Must-have. Priority: High — security concern.


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

✅ **Verified** — Security fix: correction flow input validation/sanitization is required to prevent injection attacks. MoSCoW: Must-have. Priority: High — security concern. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
HAL9000 added this to the v3.3.0 milestone 2026-04-14 05:31:32 +00:00
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.

Dependencies

No dependencies set.

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