-
Notifications
You must be signed in to change notification settings - Fork 321
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
Migrated to MessagePack instead of BinaryFormatter #1202
Migrated to MessagePack instead of BinaryFormatter #1202
Conversation
…tion logic into a separate class
@@ -9,11 +9,11 @@ namespace Microsoft.Spark.E2ETest.ExternalLibrary | |||
[Serializable] | |||
public class ExternalClass | |||
{ | |||
private string _s; | |||
private string s; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise messagePack cannot instantiate an ExternalClass instance, as it doesn't know what to use for argument.
We can either create a default parameter-less constructor, or rename field to match ctor argument name.
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
Just come back from Chinese New Year. Hi @grazy27, I see #1166 says do not merge this PR. #1166 (comment) Could you please summarize what was the blocker before and if that has been resolved in this PR? |
@@ -30,6 +29,7 @@ | |||
|
|||
<ItemGroup> | |||
<PackageReference Include="Apache.Arrow" Version="14.0.2" /> | |||
<PackageReference Include="MessagePack" Version="3.0.214-rc.1" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use the pre-release version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for noticing, I didn't see that checkbox 'Include pre-release' was checked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bumped up to the latest release one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, it seems like we don't have latest msgPack version in the Arcade nuget sources, and we don't have standard nuget.org enabled in nuget.config. And that version must have been the latest available in those feeds.
I'll have a look how to handle it, either choose existing in those sources version or add nuget.org to package sources
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, @SparkSnail @wudanzy,
It turns out there's no release MessagePack 3 in feeds recommended by Arcade project.
It seems to be some internal Microsoft strategy, since there's no nuget.org
feed in any of dotnet** projects. Example of removing commit
There's this pre-prelease 3.0.214 and release 2.5
There were breaking changes between 3.0 and 2.5, 2.5 has different API and requires additional efforts for making it work - and we'll have to spend more efforts to migrate back up when it appears.
I suggest using pre-prelease 3.0, as since it's already in the feed it must have passed some internal review. And if you know who can be reached out to include release 3.* version to the dotnet-public feed, your help would be appreciated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, if there's no security concerns, that's fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's fine, we can upgrade it in the future.
Hello, @wudanzy, welcome back! The comment not to merge refers to a few reasons: 1. The PR is not fully completed and doesn't function properlySee my review comments inside. 2. A Microsoft dev pointed out that both
|
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @grazy27, thanks for picking this up and make it proceed!
public override void ThrowIfDeserializingTypeIsDisallowed(Type type) | ||
{ | ||
// Check against predefined blacklist | ||
base.ThrowIfDeserializingTypeIsDisallowed(type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How this is going to be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's no 'System.Serializable' attribute defined, we won't allow deserialization. Mimics behavior of binarySerializer
base.ThrowIfDeserializingTypeIsDisallowed(type); | ||
|
||
// Check if MessagePack can handle this type safely | ||
var formatter = StandardResolver.Instance.GetFormatterDynamic(type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a unit test to cover this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
86a662f
to
60e66c3
Compare
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
Overview
This PR replaces
BinaryFormatter
serialization with theMessagePack
library.I was unable to contribute to #1166, so I’ve opened a new one.
Replacing
BinaryFormatter
addresses a range of issues, including:BinaryFormatter
has been abandoned and is officially deprecated.Compatibility Considerations
To ensure better compatibility with existing .NET types and reduce coupling with MessagePack, I opted to retain the
Serializable
andNonSerialized
attributes.One limitation of MessagePack is its handling of types with constructors containing parameters. If parameter names do not match the corresponding property or field names (e.g., a property
_value
and a constructor argumentvalue
), the parameters will not be automatically matched.In such cases a default, parameterless constructor is required. If no default constructor is found, MessagePack throws a descriptive exception.
This PR fixes #1131.
Security Considerations
Using
MessagePack
improves serialization security by addressing common vulnerabilities associated withBinaryFormatter
. Key points include:Safe Deserialization:
MessagePack
does not support arbitrary executable code. It can only serialize and deserialize objects and their properties. Delegates are not supported by design.Typeless Mode:
Typeless
mode is only used for deserializing custom objects. For primitives, an optimized serialization format is used, which adds a single byte for type information rather than serializing the entireSystem.Type
.Restricted Type Resolution:
Mitigation of RCE (Remote Code Execution) Risks:
MessagePack
Enhanced Security Mode is enabled to filter object types and disallow known vulnerable ones.[Serializable]
attribute.For reference, here’s an overview paper on potential RCE attack vectors with typeless
MessagePack
deserialization:Generating Deserialization Payloads for MessagePack-C# Typeless Mode