Files
cleveragents-core/features/tdd_lsp_path_containment.feature
HAL9000 e619c1be58 test(lsp/runtime): fix TDD tag to reference bug issue #10490 and add safe-file scenario
Corrected @tdd_issue_10489 → @tdd_issue_10490 so the tag references the
actual bug issue (path traversal vulnerability) rather than the TDD issue
itself.  Added a positive scenario verifying _read_file can still read
files inside the workspace, as suggested in review.

ISSUES CLOSED: #10489
2026-04-26 12:19:34 +00:00

38 lines
2.0 KiB
Gherkin

@tdd_issue @tdd_issue_10490
Feature: TDD Issue #10490 — LspRuntime._read_file has no workspace path containment check
As a security-conscious developer
I want LspRuntime._read_file() to restrict file access to the workspace directory
So that a malicious or misconfigured LLM tool call cannot read arbitrary files
This test captures bug #10490. The ``_read_file`` static method in
``src/cleveragents/lsp/runtime.py`` calls ``os.path.realpath()`` to
resolve symlinks and ``..`` components, but does NOT verify that the
resolved path is contained within the workspace directory. An attacker
who can control ``file_path`` (e.g. via a malicious LLM tool call) could
read any file on the filesystem by supplying a path such as
``<workspace>/../../../etc/passwd``.
The method is a ``@staticmethod`` and has no access to the workspace path,
so it cannot perform containment checks without a design change.
The scenario below uses ``@tdd_expected_fail`` because the assertion
FAILS while the bug exists ``_read_file`` does NOT raise ``LspError``
when given a path that resolves outside the workspace. The tag inversion
mechanism causes CI to report the scenario as passed until the fix lands.
Once the fix for #10490 is merged, the ``@tdd_expected_fail`` tag must be
removed so the scenario runs normally.
See CONTRIBUTING.md > Bug Fix Workflow > TDD Issue Test Tags.
@tdd_expected_fail
Scenario: _read_file should reject paths outside workspace but currently does not
Given lsp_pc a workspace directory containing a safe file
And lsp_pc a sensitive file exists outside the workspace
When lsp_pc I call _read_file with a path that traverses outside the workspace
Then lsp_pc an LspError should be raised with message containing "outside workspace"
Scenario: _read_file can read a file inside the workspace
Given lsp_pc a workspace directory containing a safe file
When lsp_pc I call _read_file with the safe file path
Then lsp_pc the file content should be returned successfully