Guard against UNC path bypass in file URI parsing on Windows#1573
Open
RacerZ-fighting wants to merge 1 commit intomicrosoft:mainfrom
Open
Guard against UNC path bypass in file URI parsing on Windows#1573RacerZ-fighting wants to merge 1 commit intomicrosoft:mainfrom
RacerZ-fighting wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Add detection for UNC paths encoded in the URI path component (e.g., file:////RemoteServer/Share/file) that could bypass netloc checks on Windows.
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
file_uri_to_path()determines whether afile:URI refers to a local resource byinspecting the parsed URI authority (
netloc). However, a crafted URI such asfile:////RemoteServer/Share/fileencodes a UNC path entirely within the path component,causing
urlparse()to return an emptynetloc— bypassing the locality check — whileurl2pathname()on Windows converts it into a valid UNC path (\\RemoteServer\Share\file).This allows the application to initiate unintended outbound SMB connections when processing
such inputs, which is particularly concerning in automated or agent-driven workflows
(e.g., MCP-based systems) where an attacker could influence input data by hosting
attacker-controlled files on a remote server.
Changes
os.name == 'nt'),rejecting URIs where the path resolves to a remote UNC share despite an empty
netloc