Just as the title says: What, if any, are the security implications that need to be considered when using and/or passing around anonymous methods (Action<>
, Func<>
) in C#?
A method which accepts Action<>
/Func<>
seems to be a potential way for foreign code to be injected into a program. For the record, I understand that the injected method or function is not able to do inherently unsafe things in the sense of arbitrary memory access, but I would think that it could allow the calling code to call e.g. arbitrary .Net framework functions, corrupt data, or otherwise cause the application to misbehave.
Is this assumption wrong?
If it is not, what should be done to lock these down? Additionally, is there any way to validate the
/Func<>
that is passed into a method or function to ensure that it is of an expected form or to restrict its access to certain types and namespaces?
Also, forgive me if I'm not quite using the right terminology, I'm still learning.
System.String
class, for instance, protects itself from this by being sealed. – Abbreviation