fix(security): use relpath containment instead of startswith to prevent prefix-collision bypass #11242

Closed
HAL9000 wants to merge 4 commits from feature/security-fix-relpath-pr-11217 into master

4 Commits

Author SHA1 Message Date
cleveragents-auto 0aff794f69 chore: worker ruff auto-fix (pre-push lint gate)
CI / push-validation (pull_request) Successful in 22s
CI / build (pull_request) Successful in 33s
CI / helm (pull_request) Successful in 34s
CI / lint (pull_request) Successful in 36s
CI / quality (pull_request) Successful in 1m14s
CI / typecheck (pull_request) Successful in 1m18s
CI / security (pull_request) Successful in 1m19s
CI / integration_tests (pull_request) Failing after 2m54s
CI / unit_tests (pull_request) Successful in 4m46s
CI / docker (pull_request) Successful in 1m36s
CI / coverage (pull_request) Successful in 11m13s
CI / status-check (pull_request) Failing after 3s
2026-05-28 06:39:49 -04:00
HAL9000 ba1b2e20af fix(security): correct inverted relpath check and catch ValueError in path resolve
Two follow-up bugs from the relpath-containment refactor:

1. decomposition_clustering._directory_key had inverted boolean logic:
   `if not (rel == "" or not rel.startswith(".." + os.sep))` meant the
   relative path was used ONLY when it escaped the root, and discarded
   when the path was actually inside the root. Fixed to update
   `normalized` exactly when the path is inside (or equal to) root.

2. inline_executor._validate_paths split the original
   `except (OSError, ValueError)` so that ValueError from
   `Path(value).resolve()` (raised for invalid paths such as those
   containing null bytes) propagated instead of returning a graceful
   "Invalid path" error string.

ISSUES CLOSED: #11217
2026-05-28 06:39:25 -04:00
controller-ci-rerun 9d0c5850b3 chore: re-trigger CI [controller]
CI / build (pull_request) Successful in 35s
CI / lint (pull_request) Successful in 48s
CI / helm (pull_request) Successful in 29s
CI / quality (pull_request) Successful in 1m8s
CI / typecheck (pull_request) Successful in 1m9s
CI / security (pull_request) Successful in 1m18s
CI / push-validation (pull_request) Successful in 21s
CI / integration_tests (pull_request) Successful in 3m54s
CI / unit_tests (pull_request) Failing after 7m11s
CI / coverage (pull_request) Has been skipped
CI / docker (pull_request) Has been skipped
CI / status-check (pull_request) Failing after 3s
2026-05-28 00:09:44 -04:00
HAL9000 51ada4945e fix(security): use relpath containment instead of startswith to prevent prefix-collision bypass
Replace str().startswith(root) checks with proper relpath-based
containment that prevents prefix-collision bypass attacks where a
sibling directory whose name starts with the root path would pass
an unchecked containment test.

Files changed:
- decomposition_clustering.py: Use os.path.relpath() instead of
  string-prefix matching for root-relative path computation.
- plan.py (_apply_sandbox_changes): Use Path.is_relative_to()
  instead of str.startswith() for sandbox-to-project root check.
- inline_executor.py: Use Path.relative_to() instead of
  str.startswith() for sandbox containment validation.
2026-05-28 00:09:44 -04:00