AppDomain and SecurityPermission
From: Sekhmet den skammelige (s_at_lunarscape.dk)
Date: 07/13/03
- Previous message: Michel Gallant: "Re: Security problem with Managed Code calling Unmanaged Code in a Web Page"
- Next in thread: Eugene V. Bobukh [MS]: "Re: AppDomain and SecurityPermission"
- Reply: Eugene V. Bobukh [MS]: "Re: AppDomain and SecurityPermission"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Sun, 13 Jul 2003 15:37:23 +0200
Hi
I pretty sure I'm getting something wrong here.
I want to make sure that an assembly I load into a AppDomain i create can't
call assert to access fx. files it's not allowed to.
If execute the following code which is supposed to give the AppDomain no
access to d:\ and make sure it can't just assert that permission:
FileIOPermission ioPerm = new
FileIOPermission(FileIOPermissionAccess.AllAccess, @"d:\");
SecurityPermission secPerm = new
SecurityPermission(SecurityPermissionFlag.Assertion);
NamedPermissionSet permSet = new NamedPermissionSet("permSet",
PermissionState.None);
permSet.AddPermission(secPerm);
permSet.AddPermission(ioPerm);
permSet.Deny();
PolicyLevel lvl = PolicyLevel.CreateAppDomainLevel();
lvl.AddNamedPermissionSet(permSet);
AppDomain domain = AppDomain.CreateDomain("testApp");
domain.SetAppDomainPolicy(lvl);
Assembly ass = Assembly.GetAssembly(typeof(C.C));
domain.CreateInstance(ass.FullName, "C.C");
In the constructor for class C.C I have the following:
try {
new FileIOPermission(FileIOPermissionAccess.Read,
@"d:\temp").Assert();
Console.WriteLine(new StreamReader(File.Open(@"d:\temp\test.txt",
FileMode.Open, FileAccess.Read)).ReadToEnd());
} catch (Exception e) {
Console.WriteLine(e.Message);
}
The problem is now that if I execute the code with the
FileIOPermission.Assert statement in C I get the appropriate
SecurityException telling me I don't have access to d:\temp\.
But if I have the FileIOPermission.Assert statement the code runs and
outputs the contents of the file.
What I want is to make sure that under no circumstances can code running in
the new AppDomain access ressources other than those I specify.
Hope you can help me.
/sekhmet
- Previous message: Michel Gallant: "Re: Security problem with Managed Code calling Unmanaged Code in a Web Page"
- Next in thread: Eugene V. Bobukh [MS]: "Re: AppDomain and SecurityPermission"
- Reply: Eugene V. Bobukh [MS]: "Re: AppDomain and SecurityPermission"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|