Cover analyzer-invisible path consumers in MSBuildTask0003 - #14828
Draft
ViktorHofer with Copilot wants to merge 2 commits into
Draft
Cover analyzer-invisible path consumers in MSBuildTask0003#14828ViktorHofer with Copilot wants to merge 2 commits into
ViktorHofer with Copilot wants to merge 2 commits into
Conversation
Contributor
|
Hello @copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo. |
Co-authored-by: ViktorHofer <7412651+ViktorHofer@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix missing analyzer-invisible path consumers in MSBuildTask0003
Cover analyzer-invisible path consumers in MSBuildTask0003
Aug 25, 2026
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.
Context
MSBuildTask0003decides whether a call needs an absolute path by matching the containing type against an allowlist. It missed what the issue calls analyzer-invisible path consumers: APIs on types unrelated toSystem.IOthat still take a path string and hit the file system.AssemblyName.GetAssemblyName(string)was the most-repeated defect found in a manual audit after ~150 task migrations across dotnet/arcade, dotnet/source-build-assets and the dotnet/dotnet VMR — where the analyzer had reported zero warnings.One correction to the issue's premise: the "fixed set of eight types" it quotes came from
README.md, which was stale.XDocument/XElement.Load,XmlReader/XmlWriter.Create,ZipFile.*andX509Certificate2(string)were already covered; the doc was misreporting real coverage.Changes Made
Sinks added to
SharedAnalyzerHelpers.ResolveFilePathTypes(shared with the transitive rule, soMSBuildTask0005picks them up automatically):System.Reflection.AssemblyNameGetAssemblyName(assemblyFile)System.Xml.XmlDocumentLoad(filename),Save(filename)System.Xml.XPath.XPathDocumentXPathDocument(uri)System.IO.Compression.ZipFileExtensionsExtractToFile,ExtractToDirectory,CreateEntryFromFile(+ async)X509CertificateLoaderLoadCertificateFromFile,LoadPkcs12FromFile,LoadPkcs12CollectionFromFileX509Certificate2CollectionImport(fileName),ImportFromPemFileXmlDocumentun-excluded. A comment asserted it had to stay out becauseCreateElement/CreateAttributewould false-positive. That reasoning was wrong — arguments are filtered bySpecialType.System_StringandIsPathParameterName, soCreateElement,SelectNodes,LoadXml,LoadPkcs12(byte[], password)and everyStream/TextReaderoverload are skipped. Comment replaced with why the filter makes whole-type monitoring safe.Code fix correctness.
ZipFileExtensionsmembers are extension methods; in static form the first argument is aZipArchive. The fixer wrapped the first syntactically unwrapped argument, which would emit code that does not compile. It now binds arguments to parameters and wraps the first unwrapped string path parameter — what the README already claimed it did.README.md: stale eight-type line replaced with the full set plus a note on the parameter-name filter; fixer description corrected.Testing
10 analyzer tests (5 positive, 5 guarding stream overloads and non-path strings) and 1 code-fix test. Each positive test was confirmed to fail without its corresponding source change — one initially passed spuriously because its
ZipFile.OpenReadsetup line was itself producing the diagnostic, and was reworked to assert a single diagnostic namingExtractToFile.False-positive risk was checked empirically rather than by inspection: a reflection probe enumerated every string-parameter member of each added type against the real
IsPathParameterNamefilter. No matches outside the intended path overloads.Measured against
src/Tasks/Microsoft.Build.Tasks.csproj -p:BuildAnalyzer=true -t:Rebuild(the configuration CI's "Linux Core Multithreaded Mode" job uses): 0 errors, +12MSBuildTask0003, +8MSBuildTask0005, none lost. New warnings are real unrooted consumers — 5 ×AssemblyName.GetAssemblyNameinGetAssemblyIdentity/ResolveComReference, plusXmlDocument.Save(string)reached fromSignFile/UpdateManifest. Both codes are already in that project'sWarningsNotAsErrors.Notes
Two judgement calls worth reviewer attention:
URI-capable overloads.
XmlDocument.Load(string filename)andnew XPathDocument(uri)also accept URLs, and wrapping one would corrupt it. This is pre-existing and deliberate rather than introduced here:IsPathParameterNamehas always matcheduri/url, andXDocument.Load(string uri)/XmlReader.Create(string inputUri)were already sinks. Narrowing it now would silently drop warnings from rules this change does not touch, so behavior is left as-is — but it is a reasonable thing to revisit deliberately.The "invert the rule shape" proposal is not attempted. Taint-tracking from task input properties is the stronger design and the only thing that catches the
InstallDotNetToolcase, where paths flow throughIFileSystem/ICommandFactoryand no BCL type appears. It is a different rule with its own false-positive surface (new AbsolutePath(path),Path.Combine(path1, path2)would trip a naive version) and warrants its own change rather than riding along with a sink-list fix.