Closed wmrutten closed 5 years ago
Turns out that the System.Exception.SerializeObjectState event is not supported in netcore...
protected event EventHandler<SafeSerializationEventArgs> SerializeObjectState
{
add { throw new PlatformNotSupportedException(SR.PlatformNotSupported_SecureBinarySerialization); }
remove { throw new PlatformNotSupportedException(SR.PlatformNotSupported_SecureBinarySerialization); }
}
However, it also turns out that in dotnetcore, the Exception.GetObjectData method is NOT decorated with the SecurityCrititical
attribute.
Suggestion:
SerializeObjectState
event
=> compatible with partial trust environmentException.GetObjectData
No need to specify SecurityCritical attribute
=> compatible with partial trust environmentIs this not a complete duplicate of #735?
Is this not a complete duplicate of #735?
Indeed... Github was experiencing some stability issues yesterday, resulting in duplicate post. I'll close #735.
Challenge: it appears that the alternative ISafeSerializationInfo
interface is not widely supported...
JSON.NET only supports Exception.GetObjectData
, not the ISafeSerializationInfo
interface:
https://github.com/JamesNK/Newtonsoft.Json/issues/840
Orleans relies on Exception.GetObjectData
to exchange exceptions
https://github.com/dotnet/orleans/issues/5018
Conclusion:
Exception.GetObjectData
Exception.GetObjectData
requires SecurityCritical
attribute in dotNetFramework, which breaks compatibility with low-trust environments such as dotNetFiddle.ISafeSerializationInfo
interface is compatible with low-trust environments, but is not supported by Orleans/JSON.Net (also not available in dotNetCore)So in dotnetcore, we can simply keep using the GetObjectData
override, SecurityCritical
attribute is not necessary. In dotnetFramework, we can implement ISafeSerializationInfo
instead of GetObjectData
to support low-trust environment; that might break exception serialization in Orleans, however such server/cloud environments typically use dotnetCore.
Done. Dotnetfiddle is happy now!
@mbaltus reported that the API packages are incompatible with https://dotnetfiddle.net/ (an online C# playground). DotNetFiddle refuses to load the Core package, reporting a security violation on override method
FhirOperationException.GetObjectData
.Other libraries have reported a similar issue: https://github.com/axuno/SmartFormat.NET/issues/104
Explanation: Method
Exception.GetObjectData
is marked with the [SecurityCritical] attribute (in the dotNet runtime). Hl7.Fhir.Core.FhirOperationException overrides this method and also specifies the [SecurityCritical] attribute, as required. However in a low trust environment, all explicit security attribute declarations are ignored. Consequently, the override is no longer valid.Fortunately, dotNet runtime provides an alternative to overriding GetObjectData that also works in low-trust environments: https://stackoverflow.com/questions/14124874/how-do-i-implement-exception-getobjectdata-in-net-4-in-a-library-assembly-that
I propose that we update the implementation to the alternative approach.