Skip to content

Microsoft.XmlSerializer.Generator use of Assembly.LoadFile #102245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
filipnavara opened this issue May 15, 2024 · 1 comment
Open

Microsoft.XmlSerializer.Generator use of Assembly.LoadFile #102245

filipnavara opened this issue May 15, 2024 · 1 comment
Labels
area-Serialization untriaged New issue has not been triaged by the area owner

Comments

@filipnavara
Copy link
Member

The XML serializer generator uses Assembly.LoadFile to examine the original assembly for serializable types:

https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.XmlSerializer.Generator/src/Sgen.cs#L480C24-L480C41

Can it result in unintended code execution (eg. module initilizers)? Wouldn't it be more appropriate to use Assembly.ReflectionOnlyLoad?

@ghost ghost added the area-Serialization label May 15, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 15, 2024
@filipnavara
Copy link
Member Author

As @MichalPetryka pointed out to me, .NET [Core] doesn't support Assembly.ReflectionOnlyLoad[From] which makes this significantly more complicated to fix. Ideally I would like the code to use MetadataLoadContext but the XmlReflectionImporter class used under the covers heavily depends on the types existing in the same context which makes such fix non-trivial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Serialization untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

1 participant