babgvant / elmah

Automatically exported from code.google.com/p/elmah
Apache License 2.0
0 stars 0 forks source link

EnvironmentPermission error under medium trust #128

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following exception is thrown when viewing elmah.axd:

    [SecurityException: Request for the permission of type
    'System.Security.Permissions.EnvironmentPermission, mscorlib,
Version=2.0.0.0,
    Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
       System.Security.CodeAccessSecurityEngine.Check(Object demand,
StackCrawlMark& stackMark, Boolean isPermSet) +0
       System.Security.CodeAccessPermission.Demand() +58
       System.Environment.get_MachineName() +66
       Elmah.ErrorLogPage.OnLoad(EventArgs e) +370
       System.Web.UI.Control.LoadRecursive() +50
       System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)+6785
       System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+242
       System.Web.UI.Page.ProcessRequest() +80
       System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
       System.Web.UI.Page.ProcessRequest(HttpContext context) +49 
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Ex
ecute
() +181
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously) +75 

What steps will reproduce the problem?
1. Install Elmah normally - dll in /bin folder, web.config configured
2. Add <security allowRemoteAccess="1"/> to the <elmah> element
3. I did not encounter this issue when running locally. I was only able to
reproduce when running on shared hosting under medium trust.

My original report:
http://groups.google.com/group/elmah/browse_thread/thread/693d251c7e0653bb

I was able to solve this issue by downloading the Elmah source code and
removing or replacing with a static string "MACHINE_NAME" all references to
Environment.MachineName. After that I recompiled Elmah and everything
worked like a charm (awesome software, by the way).

Original issue reported on code.google.com by isaac.n....@gmail.com on 18 Jul 2009 at 2:08

GoogleCodeExporter commented 9 years ago
The steps listed in the origianl report do no reproduce the indicated 
exception. 

Here's what I tried:

1. Ran demo.cmd in the root of the ELMAH 1.0 distribution.
2. Modified web.config to change the trust level from Full to Medium.
3. Switched from SQLiteErrorLog to XmlFileErrorLog because the former is known 
to
require full trust.
3. Deleted Default.aspx because it would cause a security exception in medium 
trust
(but for a different reason) since its code tries to directly access sections 
of the
configuration file.
4. Pointed the browser to the errors page by navigating to:
http://localhost:54321/elmah.axd
5. Generated a test exception by navigating to: http://localhost:54321/elmah.axd

All of the above steps demonstrated normal and by-design behavior and never 
generated
a security exception as being reported in the issue. For reference, the modified
version of the web.config is attached.

It looks like that the shared hosting environment may be using a modified 
version of
the default medium trust. As James points out in the following message, medium 
trust
does grant read access to the COMPUTERNAME environment variable:

http://groups.google.com/group/elmah/msg/782374e4e6afaeae

> The following line shows that by default the COMPUTERNAME can be read
> through the Environment.MachineName call:
> <IPermission class="EnvironmentPermission" version="1"
> Read="TEMP;TMP;USERNAME;OS;COMPUTERNAME"/> 

Original comment by azizatif on 20 Jul 2009 at 11:09

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by jamesdriscoll71 on 17 Jan 2010 at 11:52

GoogleCodeExporter commented 9 years ago

Original comment by jamesdriscoll71 on 18 Jan 2010 at 12:04