Repository navigation
Harden exported project metadata against MSBuild injection - #4320
Merged
Merged
Conversation
An exported project repeats a lot of text the decompiled assembly chose:
resource names in LogicalName metadata, the assembly name, the names of
referenced assemblies, the target framework moniker. MSBuild expands
property references, item references and property functions inside
attribute and element values, so a resource named
"pwn$([System.IO.File]::ReadAllText('/etc/hostname')).txt" was evaluated as
soon as the exported project was opened or built - and the file contents
landed in the name. Assemblies get decompiled precisely because nobody
trusts them, so none of their text may reach MSBuild as syntax.
Quoting uses MSBuild's own escape form, which it resolves back to the
literal before anything else reads the value, and which is a no-op for text
that has nothing to quote. It also repairs a name that could not survive
the round trip before: a resource whose name contains a percent sign was
un-escaped by MSBuild and rebuilt under a different name.
Assisted-by: Claude:claude-opus-5[1m]:Claude Code
siegfriedpammer
force-pushed
the
fix/msbuild-metadata-escaping
branch
from
November 8, 2026 11:25
7cd91a6 to
dfce142
Compare
dgrunwald
reviewed
Nov 8, 2026
| /// </summary> | ||
| public static string EscapeAssemblyName(string name) | ||
| { | ||
| if (name.IndexOfAny(new[] { '/', '\\', ':' }) >= 0) |
Member
There was a problem hiding this comment.
Sometimes skipping CleanUpFileName seems questionable?
Assembly-controlled names and metadata are consumed by MSBuild when an exported project is loaded. Escape those values, remove path-like assembly references before project emission and resolver probing, and preserve solution reference matching after escaping. Assisted-by: OpenCode:gpt-5.6-luna:OpenCode
siegfriedpammer
force-pushed
the
fix/msbuild-metadata-escaping
branch
from
November 8, 2026 15:44
dfce142 to
02320bd
Compare
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.
Assembly-controlled names and metadata written into exported project files could be interpreted as MSBuild syntax when the project was loaded or built. Path-like assembly references could also make MSBuild or ILSpy probe outside the export directory.
This change:
Addresses scan finding ANT-2026-P4WLW6Q2.
Tests:
OPENSSL_ENABLE_SHA1_SIGNATURES=1 dotnet test --project ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj --report-trx --filter "FullyQualifiedName~MSBuildEscapingTests|FullyQualifiedName~UniversalAssemblyResolverTests"(23 passed)OPENSSL_ENABLE_SHA1_SIGNATURES=1 dotnet test --project ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj --report-trx --filter "FullyQualifiedName~ProjectDecompiler"(260 passed)