Skip to content

fix: prevent directory traversal in OneLake file operations#2136

Open
srinuthati78 wants to merge 3 commits intomainfrom
srthatip/fixsecuritybug
Open

fix: prevent directory traversal in OneLake file operations#2136
srinuthati78 wants to merge 3 commits intomainfrom
srthatip/fixsecuritybug

Conversation

@srinuthati78
Copy link
Contributor

What does this PR do?

Adds a ValidatePathForTraversal helper to OneLakeService that rejects any caller-supplied path containing .. sequences before an HTTP request is made, preventing directory traversal attacks.

Changes:

OneLakeService.cs: ValidatePathForTraversal static helper applied across all 13 file/blob/directory methods
New: OneLakePathTraversalTests.cs— service-level tests for all 13 methods
Updated command tests: FileRead, FileWrite, FileDelete, BlobGet, BlobPut, DirectoryCreate, DirectoryDelete — each with a traversal rejection test case
Fixed TableGetCommandTests.cs to use --namespace instead of --schema

Changelog entry added to changelog-entries

Tests: 191/191 passing

[Add additional context, screenshots, or information that helps reviewers]

GitHub issue number?

[Link to the GitHub issue this PR addresses]

Pre-merge Checklist

  • Required for All PRs
    • [x ] Read contribution guidelines
    • [x ] PR title clearly describes the change
    • [x ] Commit history is clean with descriptive messages (cleanup guide)
    • [x ] Added comprehensive tests for new/modified functionality
    • [x ] Created a changelog entry if the change falls among the following: new feature, bug fix, UI/UX update, breaking change, or updated dependencies. Follow the changelog entry guide
  • For MCP tool changes:
    • [x ] One tool per PR: This PR adds or modifies only one MCP tool for faster review cycles
    • [x ] Updated servers/Azure.Mcp.Server/README.md and/or servers/Fabric.Mcp.Server/README.md documentation
    • [x ] Validate README.md changes running the script ./eng/scripts/Process-PackageReadMe.ps1. See Package README
    • For new or modified tool descriptions, ran ToolDescriptionEvaluator and obtained a score of 0.4 or more and a top 3 ranking for all related test prompts
    • For tools with new names, including new tools or renamed tools, update consolidated-tools.json
    • For renamed tools, follow the Tool Rename Checklist and tag the PR with the breaking-change label
    • For new tools associated with Azure services or publicly available tools/APIs/products, add URL to documentation in the PR description
  • Extra steps for Azure MCP Server tool changes:
    • Updated command list in servers/Azure.Mcp.Server/docs/azmcp-commands.md
    • Ran ./eng/scripts/Update-AzCommandsMetadata.ps1 to update tool metadata in azmcp-commands.md (required for CI)
    • Updated test prompts in servers/Azure.Mcp.Server/docs/e2eTestPrompts.md
    • 👉 For Community (non-Microsoft team member) PRs:
      • Security review: Reviewed code for security vulnerabilities, malicious code, or suspicious activities before running tests (crypto mining, spam, data exfiltration, etc.)
      • Manual tests run: added comment /azp run mcp - pullrequest - live to run Live Test Pipeline

Srinivas Thatipamula added 2 commits March 20, 2026 10:26
Add ValidatePathForTraversal helper that rejects any path containing '..'
and call it at the entry point of all 8 public methods that use user-supplied
paths in URL construction: GetFileInfoAsync, ReadFileAsync, WriteFileAsync,
PutBlobAsync, GetBlobAsync, DeleteFileAsync, DeleteDirectoryAsync,
CreateDirectoryAsync.

This prevents a directory traversal attack where a crafted path like
'../../other-item/Files/secret' could be normalized by System.Uri to escape
the intended item scope and access files in other lakehouses/warehouses.
Adds ValidatePathForTraversal helper to OneLakeService that rejects any
path containing '..' sequences before making an HTTP request. The check
is applied to all 13 file/blob/directory methods that accept caller-
supplied path parameters.

Adds 65 new tests covering the traversal guard at both the service level
(OneLakePathTraversalTests) and per-command level (FileRead, FileWrite,
FileDelete, BlobGet, BlobPut, DirectoryCreate, DirectoryDelete commands).

Fixes xUnit1051 (explicit CancellationToken) and TableGetCommand test to
use --namespace instead of --schema.
Copilot AI review requested due to automatic review settings March 20, 2026 19:05
@srinuthati78 srinuthati78 requested a review from a team as a code owner March 20, 2026 19:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the Fabric OneLake tool by adding service-side validation to block directory traversal attempts in caller-supplied file/blob/directory paths before any HTTP requests are sent, and extends test coverage to verify the behavior across the OneLake surface area.

Changes:

  • Added a ValidatePathForTraversal helper in OneLakeService and applied it across the OneLake file/blob/directory APIs.
  • Added service-level traversal tests and updated command tests to validate traversal inputs return error responses.
  • Added a Fabric server changelog entry for the security fix.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tools/Fabric.Mcp.Tools.OneLake/src/Services/OneLakeService.cs Adds and applies path traversal validation to OneLake data-plane operations.
tools/Fabric.Mcp.Tools.OneLake/tests/Services/OneLakePathTraversalTests.cs New service-level tests ensuring traversal inputs fail before any HTTP call is made.
tools/Fabric.Mcp.Tools.OneLake/tests/Commands/FileWriteCommandTests.cs Adds traversal rejection test case for the file write command.
tools/Fabric.Mcp.Tools.OneLake/tests/Commands/FileReadCommandTests.cs Adds traversal rejection test case for the file read command.
tools/Fabric.Mcp.Tools.OneLake/tests/Commands/FileDeleteCommandTests.cs Adds traversal rejection test case for the file delete command.
tools/Fabric.Mcp.Tools.OneLake/tests/Commands/DirectoryCreateCommandTests.cs Adds traversal rejection test case for directory create command.
tools/Fabric.Mcp.Tools.OneLake/tests/Commands/DirectoryDeleteCommandTests.cs Adds traversal rejection test case for directory delete command.
tools/Fabric.Mcp.Tools.OneLake/tests/Commands/BlobPutCommandTests.cs Adds traversal rejection test case for blob put command.
tools/Fabric.Mcp.Tools.OneLake/tests/Commands/BlobGetCommandTests.cs Adds traversal rejection test case for blob get command.
tools/Fabric.Mcp.Tools.OneLake/tests/Commands/Table/TableGetCommandTests.cs Updates parsing in schema/namespace-related test case.
servers/Fabric.Mcp.Server/changelog-entries/1774030436485.yaml Records the bug/security fix in the Fabric server changelog entry format.

…riants

- ValidatePathForTraversal now decodes percent-encoding (Uri.UnescapeDataString)
  before checking, catching %2e%2e and %2E%2E variants
- Splits on both '/' and '\' separators and rejects any segment equal to '.' or '..'
- Neutral error message 'Path cannot contain directory traversal sequences.'
  instead of the misleading 'File path...' for blob/directory params
- Updated 93 traversal tests: added URL-encoded InlineData cases to all 13
  service methods; updated command-level tests to match new error message
- Renamed TableGetCommandTests.ExecuteAsync_AllowsSchemaAlias to
  ExecuteAsync_AcceptsWorkspaceAndItemByName
- Updated tests/README.md and tests/TestImplementationSummary.md (231 tests)
foreach (var segment in segments)
{
var trimmed = segment.Trim();
if (trimmed is "." or "..")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe consider blocking "~" character as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

3 participants