-
Notifications
You must be signed in to change notification settings - Fork 62
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
Fix disallow-unsafe-type Akka.NET settings and harden unsafe type detection #301
Fix disallow-unsafe-type Akka.NET settings and harden unsafe type detection #301
Conversation
…ufus/Hyperion into Fix_Allow_unsafe_type_still_throws
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static bool IsDisallowedType(string name) | ||
=> UnsafeTypesDenySet.Any(name.Contains); |
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.
Refactored this out of the method so we can use it in unit tests
@@ -208,16 +226,16 @@ public static Type LoadTypeByName(string name, bool disallowUnsafeTypes, ITypeFi | |||
// i.e. if there are different version available in GAC and locally | |||
var typename = ToQualifiedAssemblyName(name, ignoreAssemblyVersion: false); | |||
var type = Type.GetType(typename, true); | |||
if (UnsafeInheritanceCheck(type)) | |||
if (disallowUnsafeTypes && UnsafeInheritanceCheck(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.
This is the bug, disallowed types are checked several times, this line need to be bypassed if unsafe types are allowed
var type = Type.GetType(typename, true); | ||
if (UnsafeInheritanceCheck(type)) | ||
var type = Type.GetType(typename, true); | ||
if (disallowUnsafeTypes && UnsafeInheritanceCheck(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.
This is the bug, disallowed types are checked several times, this line need to be bypassed if unsafe types are allowed
@@ -25,6 +34,73 @@ public void CantDeserializeANaughtyType() | |||
} | |||
} | |||
|
|||
[Theory] | |||
[MemberData(nameof(DangerousObjectFactory))] | |||
public void DetectNaughtyTypesByDefault(Type dangerousType) |
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.
Detection hardening unit test, actually try to use the dangerous types and see if they are being caught by the default filter
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.
LGTM
Fixes akkadotnet/akka.net#5740