Skip to content
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

Merged

Conversation

Arkatufus
Copy link
Contributor


[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsDisallowedType(string name)
=> UnsafeTypesDenySet.Any(name.Contains);
Copy link
Contributor Author

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))
Copy link
Contributor Author

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))
Copy link
Contributor Author

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)
Copy link
Contributor Author

@Arkatufus Arkatufus Mar 22, 2022

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

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Aaronontheweb Aaronontheweb merged commit 82f3347 into akkadotnet:dev Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hyperion's serialization configuration setting disallow-unsafe-type = false has no effect
2 participants