Security Code Snafu

development , .net , csharp , microsoft Orlando, United States
  • 11 years ago

    CodeAccessPermission fiop = new FileIOPermission(PermissionState.Unrestricted); CodeAccessPermission ep = new EnvironmentPermission (EnvironmentPermissionAccess.Read, "USERNAME")); CodeAccessPermission fdp = new FileDialogPermission(FileDialogPermissionAccess.Open)); CodeAccessPermission isfp = new IsolatedStorageFilePermission(PermissionState.Unrestricted)); CodeAccessPermission rp = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess)); CodeAccessPermission uip = new UIPermission(UIPermissionWindow.SafeTopLevelWindows)); CodeAccessPermission pp = new PrintingPermission(PrintingPermissionLevel.SafePrinting)); Console.WriteLine(fiop.GetType().ToString() + ": " + SecurityManager.IsGranted(fiop)); Console.WriteLine(ep.GetType().ToString() + ": " + SecurityManager.IsGranted(ep)); Console.WriteLine(fdp.GetType().ToString() + ": " + SecurityManager.IsGranted(fdp)); Console.WriteLine(isfp.GetType().ToString() + ": " + SecurityManager.IsGranted(isfp)); Console.WriteLine(rp.GetType().ToString() + ": " + SecurityManager.IsGranted(rp)); Console.WriteLine(uip.GetType().ToString() + ": " + SecurityManager.IsGranted(uip)); Console.WriteLine(pp.GetType().ToString() + ": " + SecurityManager.IsGranted(pp));

    If the above code is ran from a command prompt from C:\ and with administrator privileges, it produces ‘true’ to all permissions (C:\Permissions.exe) since MyComputerZone (C:) has the Full Trust permission set. If the above code is ran from a command prompt through a loopback with administrator privileges, it should NOT produce ‘true’ for several permissions (\127.0.0.1\C$\Permissions.exe). Permissions.exe is now running from a shared folder and hence under the Internet Zone. Specifically IsolatedStorageFilePermission. Yet in my case it does!

    .NET Configuration Tool shows everything as normal. Zones and their respective trusts are as follows. My Computer: Full Trust; Local Intranet: Medium Trust; Internet: Low Trust; Trusted Sites: Low Trust; Untrusted Sites: No Trust. Runtime Security Policy –> Machine –> Code Groups –> AllCode –> InternetZone –> InternetSameSite_Access also reset to normal settings.

    I’m baffled! Any help is welcomed.

    • Code, although modified, is courtesy of Tony Northrup’s book “Microsoft .NET Framework – Application Development Foundation”.

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Memory is like an orgasm. It's a lot better if you don't have to fake it.” - Seymour Cray