Uh oh!
There was an error while loading. Please reload this page.
Add BinaryFormatter auditing EventSource - #39874
Conversation
GrabYourPitchforks
commented
Jul 24, 2020
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
noahfalk
left a comment
There was a problem hiding this comment.
I spotted a few minor things you might want to address, overall looked good 👍
Uh oh!
There was an error while loading. Please reload this page.
| [Event(EventId_SerializationStarted, Opcode = EventOpcode.Start, Keywords = Keywords.Serialization, Level = EventLevel.Informational)] | ||
| public void SerializationStarted() | ||
| { | ||
| if (IsEnabled(EventLevel.Informational, Keywords.Serialization) && !_writeInProgress.Value) |
There was a problem hiding this comment.
Nit: I typically suggest people not to worry about adding IsEnabled() checks unless you are on a very hot code-path trying to shave a few nanoseconds. The implementation within WriteEvent() will do an appropriate check.
There was a problem hiding this comment.
Followed up offline. Will leave them in for now since at least one of the operations (Type.get_AssemblyQualifiedName) guarded by the initial check might have side effects that we don't want to run if nobody is listening.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This is the last of the 5.0 runtime changes per the
BinaryFormatterobsoletion document. This introduces a newEventSourceused by the serialization infrastructure to tell you when calls toBinaryFormatter.SerializeorBinaryFormatter.Deserializetake place. The are currently 6 events raised in total:Type.AssemblyQualifiedNameis provided as an arg)Type.AssemblyQualifiedNameis provided as an arg)This feature is not a "global
SerializationBinder" or a "global surrogate selector" and cannot be used to substitute types at runtime. Rather, as we begin to wind downBinaryFormatterwithin the runtime and libraries, it's meant to help app authors discover hiddenBinaryFormatterdependencies within their own code or within any assemblies they pull into their apps.There is an open question as to whether it would be useful to port this feature back to Full Framework as part of an overall defense-in-depth mechanism. I'm not considering that at the moment, but this code was designed such that it can be easily backported to Full Framework if needed. The code to hook up an
EventListenerwould look the same both in Full Framework and in .NET 5.0+.