Files
cleveragents-core/features/path_containment_security.feature
T
HAL9000 d7639635fc fix(ci): remove spurious noqa directives and add missing Behave step definitions
Remove all # noqa: ANN205 suppressions from container_tool_exec_steps.py
that were applied to already-annotated (-> None) functions, which caused
RUF100 (Unused noqa directive) lint failures. Add the missing Behave step
definitions required by path_containment_security.feature:
- Given a temporary sandbox directory "{path}"
- When I map the host path "{path}" to container
- Then the mapped path should be "{expected}"
Also rename ambiguous "the result should be true/false" steps to
"the host containment result should be true/false" to avoid AmbiguousStep
conflicts with the parametrized step in cli_steps.py.

ISSUES CLOSED: #7478
2026-05-16 23:57:07 +00:00

49 lines
2.5 KiB
Gherkin

Feature: Path containment startswith bypass prevention (issue #7478 / PR #7801)
AS a security engineer
I WANT path containment checks to use semantic comparison instead of string prefix matching
SO THAT sibling-directory prefix-collision attacks cannot bypass sandbox isolation
Background:
Given a temporary sandbox directory "/tmp/sandbox"
And a file "safe.txt" with content "safe content"
# ---- PathMapper _is_under prefix collision prevention (#7478) ----
@tdd_issue @tdd_issue_7478
Scenario: PathMapper rejects sibling-prefix path traversal via relpath containment
Given I have a PathMapper with host_root "/tmp/sandbox" and container_root "/workspace"
And a sibling directory with a name that is a prefix of the sandbox root
When I check whether host path is safe from prefix collision
Then the prefix collision check should return ``False``
@tdd_issue @tdd_issue_7478
Scenario: PathMapper correctly identifies legitimate child paths
Given I have a PathMapper with host_root "/tmp/sandbox" and container_root "/workspace"
When I check whether "/tmp/sandbox/src/main.py" is a host path
Then the host containment result should be true
@tdd_issue @tdd_issue_7478
Scenario: PathMapper correctly identifies root equality
Given I have a PathMapper with host_root "/tmp/sandbox" and container_root "/workspace"
When I check whether "/tmp/sandbox" is a host path
Then the host containment result should be true
@tdd_issue @tdd_issue_7478
Scenario: PathMapper rejects sibling-prefix escape path
Given I have a PathMapper with host_root "/tmp/sandbox" and container_root "/workspace"
And a file "escape-evil.txt" with content "malicious" at "/tmp/sandbox-escape/escape-evil.txt"
When I check whether "/tmp/sandbox-escape/escape-evil.txt" is a host path
Then the host containment result should be false
@tdd_issue @tdd_issue_7478
Scenario: PathMapper maps root path exactly (no relative component)
Given I have a PathMapper with host_root "/tmp/sandbox" and container_root "/workspace"
When I map the host path "/tmp/sandbox" to container
Then the mapped path should be "/workspace"
@tdd_issue @tdd_issue_7478
Scenario: PathMapper maps a child path correctly through relpath
Given I have a PathMapper with host_root "/tmp/sandbox" and container_root "/workspace"
When I map the host path "/tmp/sandbox/src/main.py" to container
Then the mapped path should be "/workspace/src/main.py"