Add CodeQL comments to clarify trusted input handling in ResourcesGen…#11763
Add CodeQL comments to clarify trusted input handling in ResourcesGen…#11763gpaskaleva-msft wants to merge 3 commits into
Conversation
…erator and UidManager
There was a problem hiding this comment.
Pull request overview
This PR adds inline CodeQL suppression/justification comments for rule SM00414 in WPF build tasks, documenting that the flagged file-path flows originate from developer-authored MSBuild items (build-time inputs), rather than runtime/untrusted user input.
Changes:
- Annotates
File.OpenRead(inputFile.ItemSpec)call sites inUidManagerwith CodeQL SM00414 trusted-input justification. - Annotates file deletion/existence checks in
UidManager.RemoveFilewith CodeQL SM00414 trusted-input justification. - Annotates resource file existence validation in
ResourcesGenerator.ValidResourceFileswith CodeQL SM00414 trusted-input justification.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/UidManager.cs | Adds CodeQL SM00414 suppress/justify comments on build-time file IO (read/delete/move) paths derived from MSBuild items. |
| src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/ResourcesGenerator.cs | Adds CodeQL SM00414 suppress/justify comment on resource file existence checks using MSBuild ItemSpec-derived paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| using (Stream uidStream = new FileStream(tempFile, FileMode.Create)) | ||
| { | ||
| using (Stream source = File.OpenRead(inputFile.ItemSpec)) | ||
| using (Stream source = File.OpenRead(inputFile.ItemSpec)) // CodeQL [SM00414] Trusted build-time input: ItemSpec is developer-authored MSBuild markup, not attacker-controlled |
| using (Stream uidStream = new FileStream(tempFile, FileMode.Create)) | ||
| { | ||
| using (Stream source = File.OpenRead(inputFile.ItemSpec)) | ||
| using (Stream source = File.OpenRead(inputFile.ItemSpec)) // CodeQL [SM00414] Trusted build-time input: ItemSpec is developer-authored MSBuild markup, not attacker-controlled |
| if (File.Exists(fileName)) // CodeQL [SM00414] Trusted build-time input: path derived from developer-authored MSBuild ItemSpec, not attacker-controlled | ||
| { | ||
| File.Delete(fileName); | ||
| File.Delete(fileName); // CodeQL [SM00414] Trusted build-time input: path derived from developer-authored MSBuild ItemSpec, not attacker-controlled |
| strFileName = inputFile.ItemSpec; | ||
|
|
||
| if (!File.Exists(TaskHelper.CreateFullFilePath(strFileName, SourceDir))) | ||
| if (!File.Exists(TaskHelper.CreateFullFilePath(strFileName, SourceDir))) // CodeQL [SM00414] Trusted build-time input: ItemSpec is developer-authored MSBuild markup, not attacker-controlled |
|
@gpaskaleva-msft please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement ( “Agreement” ) is agreed to by the party signing below ( “You” ), 1. Definitions. “Code” means the computer software code, whether in human-readable or machine-executable form, “Project” means any of the projects owned or managed by .NET Foundation and offered under a license “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any “Submission” means the Code and any other copyrightable material Submitted by You, including any 2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any 3. Originality of Work. You represent that each of Your Submissions is entirely Your 4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else 5. Licenses. a. Copyright License. You grant .NET Foundation, and those who receive the Submission directly b. Patent License. You grant .NET Foundation, and those who receive the Submission directly or c. Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement. 6. Representations and Warranties. You represent that You are legally entitled to grant the above 7. Notice to .NET Foundation. You agree to notify .NET Foundation in writing of any facts or 8. Information about Submissions. You agree that contributions to Projects and information about 9. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and 10. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and .NET Foundation dedicates this Contribution License Agreement to the public domain according to the Creative Commons CC0 1. |
|
The comments by copilot are not fully valid, but I think we should truncate the reasoning that we have provided. It should be a minimum of 25 chars as per the rules but if copilot suggest that analyzer will find it difficult to read, then we should consider truncating it. |
Adds a suppression comment for CodeQL finding SM00414.
After investigation, the reported data flows were determined to be build-time only and originate from trusted MSBuild inputs (ITaskItem.ItemSpec values such as ResourceFiles, OutputResourcesFile, and _markupFiles). These values are supplied by the project file and build items authored by the developer performing the build, not by untrusted external users or runtime application input.
This area can be re-evaluated in the future if these tasks begin accepting untrusted or externally supplied input.
Microsoft Reviewers: Open in CodeFlow