Re: Security problem with User Control embedded in Web Page

From: Shel Blauman [MSFT] (sheldonb_at_online.microsoft.com)
Date: 06/06/03


Date: Fri, 6 Jun 2003 09:24:48 -0700


Not sure why the URL based code group doesn't work for you, but my
recommendation would be to use a strong name rather than the URL. Here are
some generic instructions for setting up a user control:

How to run a user control assembly hosted on an Internet Information Server
(IIS) on an Internet Explorer (IE) client.

The following applies to an assembly intended to execute with greater
permissions than would normally be granted to the zone the assembly belongs
to, most likely Internet, Local Intranet or Trusted Sites.

  1.. The user control assembly is identifiable in a manner that can be used
to set the membership condition in a code group either using the .NET
Configuration Tool (Mscorcfg.msc) or caspol.exe. Signing using a strong
name or a certificate is preferable, but other sources of identity such as a
URL or site can also be used. Although a URL or site can serve as a
membership condition, they are not recommended, as they are not as secure as
a strong name or a certificate.

To create a strong name use sn.exe:

sn -k keyPair.snk

// This strong name key is used to create a code group that gives //
permissions to this assembly.

// Sign the assembly with the strong name key.

[assembly: AssemblyKeyFile("keyPair.snk")]

  2.. If strong named, the user control has the
AllowedPartiallyTrustedCallers attribute.

// The AllowPartiallyTrustedCallersAttribute requires the assembly to // be
signed with a strong name key.

// This attribute is necessary since the control is called by either an //
intranet or Internet Web page that should be running under //
restricted permissions.

// The fully attributed assembly should look similar to the following:

[assembly: AssemblyKeyFile("snKey.snk")]

[assembly: AssemblyVersion("1.0.0.0")]

[assembly:AllowPartiallyTrustedCallers]

namespace SignedAssembly

  3.. The user control asserts permissions it requires which the zone in
which it is running would not normally be granted. Permissions should only
be asserted if it is positively known the calling application has
insufficient permissions. Asserts should not be performed without a strong
need.
new FileIOPermission(PermissionState.Unrestricted).Assert();

            textBox1.Text = fileDialog.FileName;

            // Display the contents of the file in the text box.

FileStream fsIn = new FileStream(textBox1.Text, FileMode.Open,
FileAccess.Read, FileShare.Read);

            StreamReader sr = new StreamReader(fsIn);

            // Process every line in the file

for (String Line = sr.ReadLine(); Line != null; Line = sr.ReadLine())

            {

                  listBox1.Items.Add(Line);

            }

// It is very important to call RevertAssert to restore the stack walk //
for file operations.

                  FileIOPermission.RevertAssert();

  4.. The user control RevertAsserts immediately after performing asserted
actions.
// It is very important to call RevertAssert to restore the stack walk //
for file operations.

                  FileIOPermission.RevertAssert();

  5.. The user control is hosted in an IIS folder on the server that has an
"Execute permission" set to either "None" or "Scripts Only".

  6.. The client has a code group that the assembly resolves to that grants
the permissions the assembly requires.
caspol -machine -addgroup All_Code -strong -file signedassembly.exe
FullTrust -name FouthCoffeeStrongName -description "Code group granting
trust to code signed by FourthCoffee"

Alternatively, the code group can be created using the Microsoft .NET
Framework Configuration tool (Mscorcfg.msc) found under Administrative
Tools.

  7.. In Internet Explorer, Internet Options, Advanced Security settings,
the "Do not save encrypted pages to disk" should be unchecked if Internet
Explorer Enhanced Security Configuration has been enabled for both
Administrators and for Other Groups on the server. The Internet Explorer
Enhanced Security setting selected is the default on Windows Server 2003.
When in effect, one of the invoked features is the encryption of downloaded
files. Another feature is the automatic setting of "Do not save encrypted
pages to disk" on the client. To successfully download a user control under
these conditions, the client setting for "Do not save encrypted pages to
disk" should be cleared. This functionality is found in Control Panel, Add
or Remove Programs, Add/Remove Windows Components, Internet Explorer
Enhanced Security Configuration.

  8.. The runtime version on the client machine is compatible with the used
to compile the assembly.

  9.. The code group created for the user control is in the same runtime
that the control uses.

If problems occur, check the Fusionbinderror log in "C:\Documents and
Settings\<username>\Local Settings\Temporary Internet Files" to determine
which operations failed. This log must first be copied to another folder
before it can be opened.

-- 
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Mr B" <paul.bennett@aurora-uk.com> wrote in message
news:OcrR3RELDHA.2256@TK2MSFTNGP11.phx.gbl...
> Hello,
>
> Can anybody help me?
>
> I have a Win Form User control embedded in a Web Page using <object> tag
> (which is pretty standard)
>
> In the User control, I need to read the session cookie of the web page it
is
> embedded in. To do this, I have used the WinInet.dll InternetGetCookie
> method. It works fine on my PC, but when I put it onto the actual web
site,
> some PCs are not showing the control. After alot of research, I discovered
> that removing the code that references the WinInet.DLL makes the control
> work for everyone.
>
> I have created a specific code group that gives full trust for the web
site
> (using the URL Condition type for the permission set), which I thought
would
> allow the control (or, more accuratly, the assembly DLL) to be run on the
> PC. With a bit more research, I found that changing the Internet security
> level to full access allowed all users to display the control. But as I am
> trying to write an installation program, I need to know what permissions
to
> setup so that everyone can run this User Control.
>
> It is obviously a security problem, but does anyone know why referencing a
> System32 DLL from within a managed DLL with full trust would cause this
> problem, or whether this is a "Red Herring" and it is something else not
so
> obvious. And if anyone has a solution that would be even better.
>
> cheers
>
> Paul
>
>


Relevant Pages

  • Re: Windows .NET forms - controls in IE?
    ... How to run a user control assembly hosted on an Internet Information Server ... permissions than would normally be granted to the zone the assembly belongs ... In Internet Explorer, Internet Options, Advanced Security settings, ...
    (microsoft.public.dotnet.security)
  • Re: Windows .NET forms - controls in IE?
    ... > How to run a user control assembly hosted on an Internet Information ... > permissions than would normally be granted to the zone the assembly ... > Enhanced Security setting selected is the default on Windows Server 2003. ...
    (microsoft.public.dotnet.security)
  • Re: win forms security
    ... > using the URL as a means of assigning permissions within a code group. ... > of our assemblies given strong names and I would rather control the code ... >> How to run a user control assembly hosted on an Internet Information ...
    (microsoft.public.dotnet.security)
  • Strong Naming Assemblies + permissions
    ... I have a strong names signed assembly which contains a user control. ... added a code group under machine for LocalIntranetZone that should ... group in there to grant full permissions to ALL code, ...
    (microsoft.public.dotnet.languages.csharp)
  • Permissions issues with strong named assemblies
    ... I have a strong names signed assembly which contains a user control. ... added a code group under machine for LocalIntranetZone that should ... group in there to grant full permissions to ALL code, ...
    (microsoft.public.dotnet.languages.csharp)