Skip to content

LSP file access should use shared path containment and explicit rootless trust rules #3426

Description

@Widthdom

Found while dogfooding the current source with the locally built cdidx.

The LSP path-resolution code has several file-access trust-boundary edge cases. Project-relative checks use ad hoc relative-path string logic, and rootless mode appears to accept any resolved file URI before reading position text. Position reads also check file length before reading, but do not guard file growth while the read proceeds.

Evidence:

  • src/CodeIndex/Lsp/LspServer.cs TryGetProjectRelativePath uses Path.GetRelativePath plus .. string checks instead of the shared path-casing/containment helper.
  • TryResolveDocumentPath returns success when _projectRoot == null, then TryReadPositionLine opens the resolved file.
  • TryReadPositionLine checks stream.Length before constructing a reader, then reads lines until the target.

Suggested fix: use the shared path containment comparer for rooted workspaces, document or restrict rootless trust rules, and keep position reads bounded even if files change during the read.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsecurity

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions