Fix Mark of the Web detection by removing MUTZ_ISFILE flag#54937
Open
Evangelink wants to merge 2 commits into
Open
Fix Mark of the Web detection by removing MUTZ_ISFILE flag#54937Evangelink wants to merge 2 commits into
Evangelink wants to merge 2 commits into
Conversation
The interop modernization changed the MapUrlToZone flags argument from 0 to MUTZ_ISFILE. MUTZ_ISFILE maps the zone based solely on the file location and ignores the Zone.Identifier alternate data stream (Mark of the Web), so downloaded files were no longer detected as dangerous. Restoring the flag to 0 makes MapUrlToZone read the Zone.Identifier stream again. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Mark of the Web (Zone.Identifier ADS) detection in DangerousFileDetector by ensuring IInternetSecurityManager.MapUrlToZone is invoked with flags 0, allowing the zone to be derived from the file’s Mark of the Web metadata rather than solely from its location.
Changes:
- Change
MapUrlToZonecall to passdwFlags = 0instead ofPInvoke.MUTZ_ISFILE. - Add an explanatory comment documenting why
MUTZ_ISFILEmust not be used for this scenario.
Show a summary per file
| File | Description |
|---|---|
| src/Cli/Microsoft.DotNet.Cli.Utils/DangerousFileDetector.cs | Restores MapUrlToZone(..., 0) so Mark of the Web is respected; adds rationale comment to prevent regression. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
0101
approved these changes
Jun 23, 2026
…ent model Removing MUTZ_ISFILE alone was not enough: the modernization also replaced Activator.CreateInstance (CLR COM activation, equivalent to CoCreateInstance) with CoGetClassObject + IClassFactory::CreateInstance. The latter creates the apartment-model InternetSecurityManager directly in the calling MTA apartment (the xUnit runner's default) instead of letting COM host it in an STA and return a marshaled proxy. In the wrong apartment MapUrlToZone cannot read the Zone.Identifier (Mark of the Web) stream and reports LocalMachine, so the test failed only on CI agents. Switch to CoCreateInstance, which honors the registered ThreadingModel and restores the original behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3 tasks
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.
Problem
DangerousFileDetectorTests.ItShouldDetectFileWithMarkOfTheWebwas failing on CI:The test writes a
Zone.Identifierstream (ZoneId=3, Mark of the Web) and expects the file to be reported as dangerous.Root cause
The interop modernization made two changes to
DangerousFileDetectorthat broke Mark-of-the-Web detection:MapUrlToZoneflags changed from0toMUTZ_ISFILE.MUTZ_ISFILEmaps the zone from the file location only and ignores theZone.Identifierstream.COM activation changed from
Activator.CreateInstancetoCoGetClassObject+IClassFactory::CreateInstance.InternetSecurityManageris registered with the apartment threading model. The CLR'sActivator.CreateInstancepath (effectivelyCoCreateInstance) honors that model: when called from an MTA thread — the xUnit runner's default — COM hosts the object in an STA and returns a marshaled proxy. Creating the object directly through its class factory places it in the calling MTA apartment, whereMapUrlToZonecannot read theZone.Identifierstream and returns LocalMachine. This is why the test failed only on CI agents while passing on some dev machines.Fix
MapUrlToZoneflags argument to0so theZone.Identifierstream is read.InternetSecurityManagerviaCoCreateInstance(already present inNativeMethods.txt) instead of the class factory, so COM honors the registeredThreadingModeland apartment-hosts the object as the original code did.ComClassFactoryis retained — it's still used for the VSSetupConfigurationobject (which isThreadingModel=Bothand therefore unaffected).Verification
Microsoft.DotNet.Cli.Utilsbuilds clean (0 warnings/errors).Truefor a file with Mark of the Web (ZoneId=3) andFalsefor a clean file.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com