Skip to content

Guard against UNC path bypass in file URI parsing on Windows#1573

Open
RacerZ-fighting wants to merge 1 commit intomicrosoft:mainfrom
RacerZ-fighting:fix/unc-path-bypass-guard
Open

Guard against UNC path bypass in file URI parsing on Windows#1573
RacerZ-fighting wants to merge 1 commit intomicrosoft:mainfrom
RacerZ-fighting:fix/unc-path-bypass-guard

Conversation

@RacerZ-fighting
Copy link

Summary

file_uri_to_path() determines whether a file: URI refers to a local resource by
inspecting the parsed URI authority (netloc). However, a crafted URI such as
file:////RemoteServer/Share/file encodes a UNC path entirely within the path component,
causing urlparse() to return an empty netloc — bypassing the locality check — while
url2pathname() 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

  • Add UNC path detection in the URI path component on Windows (os.name == 'nt'),
    rejecting URIs where the path resolves to a remote UNC share despite an empty netloc
  • Simplify server name extraction logic (unify separators before split)
  • Remove redundant emptiness check

Add detection for UNC paths encoded in the URI path component
(e.g., file:////RemoteServer/Share/file) that could bypass netloc
checks on Windows.
@RacerZ-fighting
Copy link
Author

@microsoft-github-policy-service agree

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.

1 participant