Skip to content

Resolve and suppress false-positive CodeQL alerts - #15347

Merged
JanProvaznik merged 8 commits into
mainfrom
janprovaznik-codeql-triage-resolution
Oct 22, 2026
Merged

JanProvaznik merged 8 commits into
mainfrom
janprovaznik-codeql-triage-resolution

Conversation

@JanProvaznik

Copy link
Copy Markdown
Member

Related issue(s):

N/A (S360 CodeQL SDL-Required Findings)

Context

Resolves and suppresses 54 open CodeQL alerts reported against MSBuild in DevDiv/DotNet-msbuild-Trusted and the unified .NET VMR (dotnet/dotnet).

Almost all of the alerts originate from the unified VMR CodeQL build, where cross-repository static call-graph and virtual object.ToString() / TextWriter.Flush() dispatch over-approximation connects ASP.NET Core HTTP sources into MSBuild internals (GenerateResource, ResGenDependencies, ProfilerLogger, XmlPoke, XslTransformation, FileSystems, and [Serializable] types).

Changes Made

  • src/Build.UnitTests/BinaryLogger_Tests.cs (SM04191, SM03722): Replace BinaryFormatter in Replay_EventFilter_ExceptionSerializationPreservesDiagnosticInformation (#if NETFRAMEWORK) with direct GetObjectData + SerializationInfo constructor invocation.
  • src/Tasks/Unzip.cs & src/Tasks.UnitTests/Unzip_Tests.cs (SM02729): Keep AbsolutePath canonicalization intact (TaskEnvironment.GetAbsolutePath(...).GetCanonicalForm()), add inline // CodeQL [SM02729] false-positive suppression, and add unit test DoesNotExtractFilesOutsideDestination.
  • src/Framework/FileSystem/ManagedFileSystem.cs, src/Framework/FileSystem/WindowsFileSystem.cs, src/Framework/NativeMethods.cs, src/UnitTests.Shared/ObjectModelHelpers.cs (SM00414): Add inline // CodeQL [SM00414] false-positive suppressions on the reported file system sink lines.
  • src/Build/Logging/ProfilerLogger.cs (SM04881): Add inline // CodeQL [SM04881] false-positive suppression on File.WriteAllText(FileToLog, content).
  • src/Tasks/XmlPoke.cs & src/Tasks/XslTransformation.cs (SM00404): Add inline // CodeQL [SM00404] false-positive suppressions on XmlReader.Create(...).
  • src/Tasks/GenerateResource.cs & src/Tasks/ResGenDependencies.cs (SM02363): Add inline // CodeQL [SM02363] false-positive suppressions on the reported resource-reading lines.
  • .CodeQL.yml (SM02227): Add repository-level .CodeQL.yml excluding cs/dangerous-deserialization-routine (matching dotnet/runtime and dotnet/winforms), which flows into the VMR's generated root .CodeQL.yml via arcade-services codeflow (dotnet/dotnet#9504).

Testing

  • .\build.cmd -v quiet — passed (0 errors)
  • dotnet build src/Samples/Dependency/Dependency.csproj -v:q — passed
  • dotnet artifacts/bin/bootstrap/core/sdk/11.0.100-rc.2.26504.105/MSBuild.dll --help — passed
  • artifacts\bin\Microsoft.Build.Tasks.UnitTests\Debug\net11.0\Microsoft.Build.Tasks.UnitTests.exe --filter-method "*DoesNotExtractFilesOutsideDestination*" --no-progress — passed (1 succeeded, 0 failed)
  • artifacts\bin\Microsoft.Build.Tasks.UnitTests\Debug\net472\Microsoft.Build.Tasks.UnitTests.exe --filter-method "*DoesNotExtractFilesOutsideDestination*" --no-progress — passed (1 succeeded, 0 failed)
  • artifacts\bin\Microsoft.Build.Engine.UnitTests\Debug\net472\Microsoft.Build.Engine.UnitTests.exe --filter-method "*Replay_EventFilter_ExceptionSerializationPreservesDiagnosticInformation*" --no-progress — passed (2 succeeded, 0 failed)

JanProvaznik and others added 7 commits October 21, 2026 14:20
…round-trip

Resolves CodeQL SM04191 (cs/binary-formatter-without-binder) and SM03722 (cs/dangerous-binary-deserialization).

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f8d5e6ae-c629-4d2a-9868-e6af55a54067
…test

Unzip.Extract already canonicalizes and validates entry paths via TaskEnvironment.GetAbsolutePath(...).GetCanonicalForm() and StartsWith(fullDestinationDirectoryPath). Keep AbsolutePath intact, add inline SM02729 suppression, and add DoesNotExtractFilesOutsideDestination regression test.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f8d5e6ae-c629-4d2a-9868-e6af55a54067
In the VMR CodeQL build, virtual object.ToString() dispatch from ASP.NET Core creates false taint paths into MSBuild file existence and timestamp helpers.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f8d5e6ae-c629-4d2a-9868-e6af55a54067
ProfilerLogger writes evaluation profile output to the trusted local path specified by /profileevaluation; the VMR alert stems from cross-repo static taint over-approximation.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f8d5e6ae-c629-4d2a-9868-e6af55a54067
XmlPoke and XslTransformation process arbitrary user build XML/XSLT inputs that have no fixed XSD schema; both already configure DtdProcessing.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f8d5e6ae-c629-4d2a-9868-e6af55a54067
…nDependencies

Resource files (.resx/.resources) processed during a build are trusted developer inputs; VMR taint flows stem from cross-repo virtual object.ToString() over-approximation.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f8d5e6ae-c629-4d2a-9868-e6af55a54067
Matches dotnet/runtime and dotnet/winforms CodeQL configuration; flows into the VMR root .CodeQL.yml via arcade-services codeflow (dotnet/dotnet#9504) to resolve the 25 SM02227 false positives without littering [Serializable] types with inline comments.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f8d5e6ae-c629-4d2a-9868-e6af55a54067

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The security suppressions and repository-wide query exclusion require human validation against the original alert traces.

No open issues 🎉

What changed in this PR

Addresses reported CodeQL false positives in MSBuild and unified .NET scans without changing production behavior.

Changes:

  • Adds inline suppression comments and a repository-level deserialization-query exclusion.
  • Replaces BinaryFormatter usage in an exception serialization test.
  • Adds a ZIP path-traversal regression test.
File Description
src/​UnitTests.Shared/​ObjectModelHelpers.cs Adds test filesystem suppression comments.
src/​Tasks/​XslTransformation.cs Documents XML-reader suppression.
src/​Tasks/​XmlPoke.cs Documents XML-reader suppression.
src/​Tasks/​Unzip.cs Adds suppression comments explaining existing path checks.
src/​Tasks/​ResGenDependencies.cs Adds resource-reading suppression comments.
src/​Tasks/​GenerateResource.cs Adds resource-processing suppression comments.
src/​Tasks.UnitTests/​Unzip_Tests.cs Tests rejection of ZIP path traversal.
src/​Framework/​NativeMethods.cs Adds file-metadata suppression comments.
src/​Framework/​FileSystem/​WindowsFileSystem.cs Adds file-existence suppression comment.
src/​Framework/​FileSystem/​ManagedFileSystem.cs Adds filesystem suppression comments.
src/​Build/​Logging/​ProfilerLogger.cs Documents profiler-output suppression.
src/​Build.UnitTests/​BinaryLogger_Tests.cs Tests serialization contracts without BinaryFormatter.
.CodeQL.yml Excludes the dangerous-deserialization-routine query.

Review effort: Balanced

@JanProvaznik
JanProvaznik requested a review from a team October 21, 2026 13:16

@AR-May AR-May left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me, only have couple of minor comments.

Comment thread src/Framework/NativeMethods.cs Resolved
…ne SM00414 comment wording

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f8d5e6ae-c629-4d2a-9868-e6af55a54067
@JanProvaznik
JanProvaznik enabled auto-merge (squash) October 22, 2026 13:34
@JanProvaznik
JanProvaznik merged commit 4490c1a into main Oct 22, 2026
14 checks passed
@JanProvaznik
JanProvaznik deleted the janprovaznik-codeql-triage-resolution branch October 22, 2026 13:47
ViktorHofer pushed a commit that referenced this pull request Nov 18, 2026
…on (#15592)

Related issue(s): Follow-up to #15347 and #15465 (S360 CodeQL
SDL-required items).

### Context

#14693 added `BinaryLogEventFilterException`, a `[Serializable]` (.NET
Framework only) exception. The VMR Windows CodeQL scan
(`vmr_vertical_build_windows_pgo_arm64`) flagged it as SM02227
("Deserialization of this type may call System.IO.File.Delete"). This is
the same false positive as the 25 `[Serializable]` types suppressed in
#15465: the reported path goes from
`SerializationInfo.GetString`/`GetValue` through virtual
`ToString`/`Flush` dispatch across other VMR repos (runtime, winforms,
nuget-client, sdk) and ends in `eng/tools/BinaryToolKit` `File.Delete`.
The deserialization constructor only reads `SerializationInfo` values.

### Changes Made

Added the inline `// CodeQL [SM02227] ...` suppression above the class,
using the same wording as the other suppressed types.

### Testing

Comment-only change; no build or test needed.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f8d5e6ae-c629-4d2a-9868-e6af55a54067
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.

3 participants