fix(lsp): validate workspace boundary in _read_file to prevent path traversal #10644
No reviewers
Labels
No labels
auto/needs-reevaluation
controller-managed
overdue
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
cleveragents/cleveragents-core!10644
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/v360/lsp-path-traversal-file-reading"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
This PR fixes a critical path traversal vulnerability in the LSP runtime file reading functionality that could allow attackers to access sensitive files outside the workspace directory. The vulnerability was exploited through malicious file paths containing directory traversal sequences (e.g.,
../../../etc/passwd) or absolute paths pointing outside the workspace.The fix implements strict workspace boundary validation using canonicalized paths, preventing any file access outside the registered workspace root while maintaining backward compatibility for existing code.
Changes
Core Security Fix (
src/cleveragents/lsp/runtime.py)Workspace Root Tracking: Added
_workspace_rootsdictionary to track the workspace path for each LSP server instance, populated when servers are startedPath Validation Method: Implemented
_validate_workspace_path()static method that:os.path.realpath()to resolve symlinks and relative segmentsos.septo prevent prefix-matching attacks (e.g.,/workspacematching/workspace-evil)LspErrorif the resolved path doesn't start with the workspace root prefixFile Reading Security: Updated
_read_file()method to:workspace_rootparameterworkspace_rootis providedworkspace_rootisNoneCaller Updates: Modified all callers of
_read_file()(get_diagnostics,get_completions,get_hover,get_definitions) to pass the workspace root from the tracked serversTest Coverage (
features/lsp_path_traversal_security.feature&features/steps/lsp_path_traversal_security_steps.py)Comprehensive BDD test scenarios covering:
Path Validation Tests:
Path Traversal Attack Prevention:
../directory traversal sequencesBackward Compatibility:
_read_file()without workspace_root skips boundary checkIntegration Tests:
get_diagnosticsblocks path traversal when workspace is registeredget_diagnosticssucceeds for valid files inside workspaceget_completionsblocks path traversal when workspace is registeredTesting
All security scenarios are covered by BDD feature tests that verify:
Security Impact
Closes #7215
Automated by CleverAgents Bot
Agent: pr-creator
Implementation Attempt — Tier 1: haiku — Success
Fixed the CI lint failure caused by
ruff formatcheck failing onfeatures/steps/lsp_path_traversal_security_steps.py.Root Cause: The step definitions file introduced in the original PR had several multi-line decorator strings that
ruff formatwould collapse to single lines. Thenox -s format -- --checkstep in the CI lint job detected these formatting issues and failed.Changes Made:
nox -s formatto auto-formatfeatures/steps/lsp_path_traversal_security_steps.py@given/@whendecorator strings to single lines per ruff formatting rulesQuality gate status:
Automated by CleverAgents Bot
Supervisor: Implementation | Agent: implementation-worker
Security Fix Review — Path Traversal in LSP Runtime
This PR addresses a critical path traversal vulnerability (issue #7215) by adding
workspace boundary validation to
_read_file(). The core implementation isthoughtful and correct:
What is done well:
os.path.realpath()to canonicalize both the requestedpath and workspace root, correctly resolving symlinks and
..segments beforethe prefix check.
root_prefix = canonical_root + os.seppattern correctly preventsprefix-matching attacks (e.g.
/workspacevs/workspace-evil).workspace_root: str | Noneparameter on_read_file()maintainsbackward compatibility — code without a workspace root skips validation.
get_diagnostics,get_completions,get_hover,get_definitions) consistently pass the tracked workspace root._validate_workspace_pathhelper is well-documented with a clear docstring.detailsdict with resolved path andworkspace root for debugging.
path traversal via
../, absolute paths outside workspace, symlinks pointingoutside workspace, and backward compatibility.
Blocking Issues (must be fixed before approval):
Branch name mismatch with issue metadata — Issue #7215 Metadata specifies the
branch should be
bugfix/lsp-runtime-read-file-path-traversalbut this PRis on
fix/v360/lsp-path-traversal-file-reading. CONTRIBUTING.md requiresbranch names to match the Metadata section exactly. Please either recreate
the branch or update the issue metadata.
Failing CI — unit tests red — The
unit_testsCI check is in failure state.Per company policy, all CI gates must pass before merge. The PR description
notes ‘unit_tests: not run locally (timeout in parallel mode;’ which suggests
test infrastructure issues. Please investigate and fix.
Missing companion TDD issue — Per CONTRIBUTING.md bug fix workflow:
“Create companion Type/Testing TDD issue before implementing the fix.”
Issue #7215 includes this subtask. No TDD issue is referenced in the PR.
Please create and reference it.
CI coverage skipped — The
coveragejob was skipped. The project requires≥97% coverage as a hard merge gate. Skipped cannot satisfy this requirement.
Additional observations (non-blocking suggestions):
Test step duplication — 366-line step file has significant duplication.
Steps
step_lspsec_validate_file_inside,_nested_file, and_workspace_root_itselfshare identical structure (resolve → validate →capture exception). A shared helper would reduce repetition.
Test coverage for boundary edge cases — Consider adding a scenario where
a path is one character different from the workspace root (e.g. workspace
/ws, path/wsx) to explicitly exercise theos.sepsuffix check.LspRegistry instantiation in tests —
step_lspsec_register_server_for_workspacecreates a fresh
LspRegistry()and assigns it to_registry, bypassing thereal init path. Works for tests but may mask edge cases.
Automated by CleverAgents Bot
Supervisor: PR Review | Agent: pr-review-worker
@ -0,0 +1,87 @@Feature: LSP runtime path traversal securityBLOCKING: Missing companion TDD issue. Per CONTRIBUTING.md bug fix workflow, a Type/Testing TDD issue with a failing regression test must be created BEFORE the fix PR. Issue #7215 subtask requires: “Create companion Type/Testing TDD issue (per Bug Fix Workflow in CONTRIBUTING.md) before implementing the fix.” No TDD issue is referenced in the PR body.
@ -55,6 +55,7 @@ class LspRuntime:) -> None:self._registry = registry or LspRegistry()self._lifecycle = lifecycle_manager or LspLifecycleManager()self._workspace_roots: dict[str, str] = {}BLOCKING: Branch name mismatch. Issue #7215 Metadata specifies branch as
bugfix/lsp-runtime-read-file-path-traversal. This PR usesfix/v360/lsp-path-traversal-file-reading. CONTRIBUTING.md requires exact match between PR branch and issue Metadata Branch field.@ -98,6 +99,7 @@ class LspRuntime:)self._lifecycle.start_server(config, workspace_path)self._workspace_roots[name] = workspace_pathBLOCKING: CI is failing — unit_tests shows failure state. Per company policy, all CI gates (lint, typecheck, security, unit_tests, coverage) must pass before merge. The description notes tests ‘not run locally’ without a clear fix for the CI failure.
Suggestion: The test step file is 366 lines with significant duplication. Five validate_workspace_path When steps share identical structure (resolve with os.path.realpath, call the method, capture LspError). Consider a shared helper to reduce code duplication.
PR Review Complete — Review #1 submitted
I have submitted a formal
REQUEST_CHANGESreview (ID 6784) covering 4 blocking issues and 7 non-blocking observations.Summary of findings:
workspace_rootparameterPlease address the blocking issues and resubmit.
🌱 Grooming: proceed — PR cleared for processing.
(check
no_duplicates, categoryno_duplicates)Scanned all 397 open PRs. PR #10644 implements workspace boundary path validation in LSP's _read_file() method to prevent directory traversal attacks. No other open PR addresses this specific LSP security issue. Related security fixes exist for file_tools.py and agents modules, and other LSP PRs address different concerns (subprocess cleanup, header injection, DoS timeout), but none duplicate the workspace boundary validation logic.
📋 Estimate: tier 1.
3-file change (+525/-8): core logic edit to src/cleveragents/lsp/runtime.py (new _workspace_roots dict, _validate_workspace_path() method, updated _read_file() signature, 4 caller updates) plus two new BDD test files (feature + steps). Multi-file, new logic branches, test-additive — clearly tier 1. CI failures are all Docker Hub pull rate limit errors (infrastructure), not code issues; 0 ruff findings reported by lint job.
(attempt #3, tier 1)
🔧 Implementer attempt —
rebase-failed.Blockers:
7acb960b4b3af34103763af3410376505daffebc(attempt #5, tier 1)
🔧 Implementer attempt —
rebased.Pushed 1 commit:
505daff.✅ Approved
Reviewed at commit
505daff.Confidence: high.
Claimed by
merge_drive.py(pid 15960) until2026-06-05T00:20:37.333193+00:00.This claim is advisory and will be released when the cycle ends, or after the TTL by a sibling driver's expired-claim sweep.
505daffebc188b957320Released by
merge_drive.py(pid 15960). terminal_state=ci-fail-on-rebased-sha, op_label=auto/needs-implementer(attempt #7, tier 1)
🔧 Implementer attempt —
blocked.Blockers:
00e095b176but dispatch base was188b957320. The implementer pushed from inside the worktree (forbidden by the git contract) OR a third party pushed during the attempt. Re-dispatch will re-prefetch and pick up the new head.00e095b1763304b1c02c(attempt #8, tier 2)
🔧 Implementer attempt —
rebased.Pushed 1 commit:
3304b1c.✅ Approved
Reviewed at commit
3304b1c.Confidence: high.
Claimed by
merge_drive.py(pid 15960) until2026-06-05T02:29:57.609825+00:00.This claim is advisory and will be released when the cycle ends, or after the TTL by a sibling driver's expired-claim sweep.
3304b1c02cc780c124edReleased by
merge_drive.py(pid 15960). terminal_state=ci-fail-on-rebased-sha, op_label=auto/needs-implementer(attempt #11, tier 2)
event occurred 2026-06-05T01:57:14.373350+00:00
🔧 Implementer attempt —
verified-clean.🌱 Grooming: proceed — PR cleared for processing.
(check
no_duplicates, categoryno_duplicates)Comprehensive search across 395 open PRs found no duplicate of the workspace boundary validation fix in lsp/runtime.py _read_file(). Nine other LSP security fixes address distinct vulnerabilities (subprocess cleanup, header injection, env var sanitization, DoS). Multiple path traversal fixes exist in other modules (agents, file_tools, cli) but each targets a unique code path. High confidence no duplicate.
📋 Estimate: tier 1.
Multi-file security fix (3 files, +524/-46): core logic change in lsp/runtime.py adding path canonicalization and workspace boundary validation, callers updated (get_diagnostics, get_completions, get_hover, get_definitions), plus substantial new BDD feature file and step definitions covering positive/negative/edge cases. New logic branches, new test fixtures, security-sensitive correctness requirements. CI failures are infrastructure artifact-upload EPERM errors, not code failures — coverage and other gates all passed.
(attempt #15, tier 1)
🔧 Implementer attempt —
blocked.Blockers:
dd5983c8ecbut dispatch base wasc780c124ed. The implementer pushed from inside the worktree (forbidden by the git contract) OR a third party pushed during the attempt. Re-dispatch will re-prefetch and pick up the new head.(attempt #16, tier 2)
🔧 Implementer attempt —
ci-not-ready.✅ Approved
Reviewed at commit
dd5983c.Confidence: high.
Claimed by
merge_drive.py(pid 1627962) until2026-06-06T00:01:03.932106+00:00.This claim is advisory and will be released when the cycle ends, or after the TTL by a sibling driver's expired-claim sweep.
dd5983c8ec727d3e5cf5Claimed by
merge_drive.py(pid 1816405) until2026-06-06T05:23:40.854923+00:00.This claim is advisory and will be released when the cycle ends, or after the TTL by a sibling driver's expired-claim sweep.
727d3e5cf5b62bb578deApproved by the controller reviewer stage (workflow 275).