Skip to content

.Net: Reject mixed-separator UNC paths in file plugins#14166

Open
jstar0 wants to merge 1 commit into
microsoft:mainfrom
jstar0:fix/unc-path-separator-validation
Open

.Net: Reject mixed-separator UNC paths in file plugins#14166
jstar0 wants to merge 1 commit into
microsoft:mainfrom
jstar0:fix/unc-path-separator-validation

Conversation

@jstar0

@jstar0 jstar0 commented Jul 18, 2026

Copy link
Copy Markdown

Motivation and Context

FileIOPlugin and WebFileDownloadPlugin rejected only some UNC path prefixes before path canonicalization. On Windows, mixed /\ and \/ prefixes resolve to UNC paths too, so those forms could reach filesystem path resolution before the allow-list rejected them.

Fixes #14157.

Description

  • Treat any two leading / or \ characters as a UNC or extended-path prefix in both plugins.
  • Reject those paths before canonicalization, File.Exists, or File.GetAttributes can probe the filesystem.
  • Add read, write, and download regressions for all four separator combinations.

The change is limited to the two plugins named in the issue. Single-separator rooted paths, normal local paths, allow-list behavior, symlink handling, overwrite checks, and download limits are unchanged.

Verification

dotnet test dotnet/src/Plugins/Plugins.UnitTests/Plugins.UnitTests.csproj --filter "FullyQualifiedName~ItRejectsUncOrExtendedPathsOnReadAsync|FullyQualifiedName~ItRejectsUncOrExtendedPathsOnWriteAsync|FullyQualifiedName~DownloadToFileRejectsUncOrExtendedPathsAsync"
dotnet test dotnet/src/Plugins/Plugins.UnitTests/Plugins.UnitTests.csproj --filter "FullyQualifiedName~FileIOPluginTests"
dotnet test dotnet/src/Plugins/Plugins.UnitTests/Plugins.UnitTests.csproj --filter "FullyQualifiedName!~DownloadToFileSucceedsAsync&FullyQualifiedName!~DownloadToFileFailsForInvalidParametersAsync"
dotnet format dotnet/src/Plugins/Plugins.UnitTests/Plugins.UnitTests.csproj --verify-no-changes --no-restore

The focused regressions pass 12/12, all FileIOPluginTests pass 21/21, and the deterministic Plugins unit-test suite passes 409/409. The two excluded Web tests use a live HTTPS request and fail on unmodified main in this macOS environment because certificate revocation status is unavailable.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the SK Contribution Guidelines and the pre-submission formatting script raises no violations
  • All unit tests pass, and I have added new tests where possible (409 deterministic tests pass; two live-network baseline tests are environment-limited as noted above)
  • I didn't break anyone 😄

Signed-off-by: King Star <mcxin.y@gmail.com>
Copilot AI review requested due to automatic review settings July 18, 2026 14:55
@jstar0
jstar0 requested a review from a team as a code owner July 18, 2026 14:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Hardens the .NET file-related plugins to consistently reject UNC / extended-path prefixes (including mixed /\ and \/ forms) before path canonicalization can trigger filesystem probes, and adds regression coverage for the newly blocked path-prefix variants.

Changes:

  • Update FileIOPlugin and WebFileDownloadPlugin to treat any two leading directory-separator characters (/ or \, in any combination) as a UNC/extended-path prefix and reject early.
  • Add unit tests covering all four leading-separator combinations for read/write/download scenarios.
  • Align the Web plugin’s per-path allow-list check with the shared UNC/extended prefix detection helper.

Reviewed changes

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

File Description
dotnet/src/Plugins/Plugins.Web/WebFileDownloadPlugin.cs Updates UNC/extended-path detection to reject mixed-separator two-character prefixes before path checks proceed.
dotnet/src/Plugins/Plugins.Core/FileIOPlugin.cs Applies the same UNC/extended-path prefix rejection to FileIOPlugin path validation.
dotnet/src/Plugins/Plugins.UnitTests/Web/WebFileDownloadPluginTests.cs Adds download regressions for the newly rejected mixed-separator UNC/extended prefixes.
dotnet/src/Plugins/Plugins.UnitTests/Core/FileIOPluginTests.cs Adds read/write regressions for the newly rejected mixed-separator UNC/extended prefixes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +116 to 119
if (IsUncOrExtendedPath(path))
{
throw new ArgumentException("Invalid file path, UNC paths are not supported.", nameof(path));
}
Comment on lines 218 to 224
var expanded = Environment.ExpandEnvironmentVariables(path);
if (IsUncOrExtendedPath(expanded))
{
throw new ArgumentException("Invalid file path, UNC paths are not supported.", nameof(path));
}

return PathUtilities.GetSafeFullPath(expanded);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Net: Harden FileIOPlugin/WebFileDownloadPlugin UNC path separator validation

2 participants