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

Consider adding an option for MobileFormatter to ignore version/signing on deserialization #3036

Open
rockfordlhotka opened this issue Jul 27, 2022 · 2 comments
Assignees

Comments

@rockfordlhotka
Copy link
Member

Although very risky and unsafe for a user, it may be possible for MobileFormatter to have an option to allow deserialization into a type of the same name/assembly where the version and signing information doesn't match.

The referenced discussion thread contains info about why this is risky and may lead to people having hard-to-find and hard-to-solve issues in their app.


Number 4: Apparently we are not using the SerializationInfo correctly. We add all of an object's properties using info.AddValue function regardless of if the value is a custom type or IMobileObject type or System type.

  1. Add an option to turn on assembly/type matching somewhere in the CSLA options (default setting is off)
  2. Change MobileFormatter to look at the matching options

Should just be those two.

Originally posted by @crazyfox55 in #3021 (comment)

@kant2002
Copy link
Contributor

I take a quick look at this. and I think this can be done in following way

  1. Add methods DisableStrongNamesCheck/EnableStrongNamesCheck here which enable/disable some configuration
    public SerializationOptions SerializationFormatter<T>() where T: ISerializationFormatter
    {
    ApplicationContext.SerializationFormatter = typeof(T);
    return this;
    }
  2. Create property inside ApplicationContext which will be used for storing this configuration
  3. During creation SerializationFormatter if it is MobileFormatter or derivative read this property and pass it to MobileFormatter.
    public static ISerializationFormatter GetFormatter(ApplicationContext applicationContext)
    {
    return (ISerializationFormatter)applicationContext.CreateInstanceDI(ApplicationContext.SerializationFormatter);
    }
  4. I would like to add some tests for this configuration in the SerializationTests, but I think I need to create couple simple test assemblies with same name, but different versions to check that real types are deserialized and do not play with mocks too much.

@rockfordlhotka
Copy link
Member Author

I think you are correct.

However, PR #4024 will change the implementation, because there will be a MobileFormatterOptions class where options specific to MobileFormatter are set and maintained. This will help enable other future formatters that people might create, and also provides a clear place for MF options.

Hopefully #4024 will be complete within the next day or two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

No branches or pull requests

2 participants