0

I'm currently working on a plugin system for a modding framework and I want to add some security to the plugins.

I need to detect whenever an assembly or class accesses a class, for example System.IO.File, so I can block this.

How can I do this?

private bool IsSecure(Assembly assembly, string path)
{
    if (assembly.IsFullyTrusted)
    {
        // PermissionSet perms = new PermissionSet(PermissionState.None);
        // perms.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
        // perms.AddPermission(new FileIOPermission(FileIOPermissionAccess.NoAccess, assembly.Location));
        // perms.AddPermission(new ReflectionPermission(PermissionState.None));

        assembly.PermissionSet.SetPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
        assembly.PermissionSet.SetPermission(new FileIOPermission(FileIOPermissionAccess.NoAccess, path));
        assembly.PermissionSet.SetPermission(new ReflectionPermission(PermissionState.None));

        return true;
    }

    return false;
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Michiel
  • 1
  • 1
  • You want a way to turn "IsFullyTrusted" from true into false ? And this at runtime ? – Holger Jan 11 '20 at 11:36
  • Thats just an check if the assembly is trusted, if not the plugin wont load. Further i want to deny acces to certial system classes like System.IO.File – Michiel Jan 11 '20 at 11:38
  • 1
    Does this answer your question? [Restrict plugin access to file system and network via appdomain](https://stackoverflow.com/questions/1357231/restrict-plugin-access-to-file-system-and-network-via-appdomain) – Progman Jan 11 '20 at 14:09

0 Answers0