Why Oh Why Couldn't WebPermission Be Part Of Medium Trust?

Source: http://macibolt.hu/pag/goldilock.htmlThis is a bit of rant born out of some frustrations I have with ASP.NET. When setting the trust level of an ASP.NET site, you have the following options:

Full, High, Medium, Low, Minimal

It turns out that many web hosting companies have chosen to congregate around Medium trust as a sweet spot in terms of tightened security while still allowing decent functionality. Only natural as it is the one in the middle.

For the most part, I am sure there are very good reasons for which permissions make it into Medium trust and which ones are not allowed. But some decisions seem rather arbitrary. For example, WebPermission. Why couldn’t that be a part of the default Medium trust configuration? I mean really? Why not? (Ok, there are really good reasons, but remember, this is a rant, not careful analysis. Bear with me. Let me get it off my chest.)

Web applications have very good reason to make web requests (ever hear of something called a web service. They may take off someday) and how damaging is that going to be to a hosting environment. I mean, put a throttle on it if you are that concerned, but don’t rule it out entirely!

I really do want to be a good ASP.NET citizen and support Medium Trust with applications such as Subtext, but what a huge pain it is when some of the best features do not work under Medium Trust. For example, Akismet.

Akismet makes a web request in order to check incoming comments for spam. I tried messing around with wildcards for the originUrl attribute of the <trust /> element, but they don’t work. In fact, I only found a single blog post that said it would work, but no documentation that backed that claim up.

Instead, you need access to the machine.config file (as the previously linked blog post describes), which no self respecting host is going to just give you willy nilly. Nope. In order to get Akismet to work under medium trust, I have to tell Subtext users that they must beg, canoodle, and plead with their host provider to update the machine.config file to allow unrestricted access to the WebPermission. Good luck with that.

If they don’t give unrestricted access, then they need to add an originURl entry for each URL you wish to request. Hopefully machine.config entries do allow wildcards because the URL for an Akismet request includes the Akismet API code. Otherwise running an Akismet enabled multiple user blog in a custom Medium Trust environment would be a royal pain.

Hopefully you can see the reason behind all my bitching and moaning. A major goal for Subtext is to provide a really simple and easy installation experience. At least as easy as possible for installing a web application.  Having an installation step that requires groveling does not make for a good user experience.  But then again, security and usability have always created tension between them.

Scott Watermasysk points out a great guide to enabling WebPermission in Medium Trust for hosters. So if you’re going to be groveling, at least you have a helpful guide to give them. The guide also points out the security risks in involved with Medium Trust.

Related Posts:

What others have said

Requesting Gravatar... Scott Watermasysk Oct 18, 2006 4:06 AM
# re: Why Oh Why Couldn't WebPermission Be Part Of Medium Trust?
You can get around most of the WebPermission issues by setting a proxy.

If the ISP is running the site under medium trust, they will hopefully set up a proxy which can be used in these cases.

See Here

HTH,
Scott
Requesting Gravatar... David Mohundro Oct 18, 2006 6:07 PM
# More on Trackback Spam...
Requesting Gravatar... Rob Conery Oct 18, 2006 10:37 PM
# re: Why Oh Why Couldn't WebPermission Be Part Of Medium Trust?
We ran into this exact issue with the Commerce Starter Kit. You can't make a call to PayPal (even by setting the originUrl) using Meduim Trust because the web service needs to package an SSL cert. In fact you can't really use the whole System.Net namespace because (as I was told by Stefan Shacktow at MS) you're executing a procedure outside the application's space. It's back to the Sandbox again.

In my opinion, this is a giant step backward. Coding an application for medium trust is akin to coding for Netscape :). Obviously security is a very high concern for ISPs but Medium trust is ridiculous.

Discount ASP, Re-Invent, and Webhost4Life all run modified full trust for those interested...
Requesting Gravatar... Dani Oct 19, 2006 11:27 AM
# re: Why Oh Why Couldn't WebPermission Be Part Of Medium Trust?
Agree 100%.
I understand that full trust is not the best option, I uploaded a page that calls winapi functions and it worked, but probably my web app can live without those api calls :) Anyway, the NetworkService/aspnet user is pretty secure for the system.
The configuration of medium trust is perfect with the exception of WebPermission exclusion. WebServices, consuming RSS, parsing another webpage to do a useful service... forbidden. Great. We the asp.net developers play in second division, all due to the security paranoia.

And the solution would be so easy, in SP1 another trust level called "hosting" with WebPermission enabled.
Requesting Gravatar... cathal Oct 19, 2006 3:37 PM
# re: Why Oh Why Couldn't WebPermission Be Part Of Medium Trust?
Phil,
the originUrl change should work fine. One thing to be careful of is that it's actually a regular expression, so needs to be correctly formed i.e.this should work (note the period):

<trust level="Medium" originUrl="http://akismet.com/.*" />

but this will not :

<trust level="Medium" originUrl="http://akismet.com/*" />
Requesting Gravatar... you've been HAACKED Oct 19, 2006 4:13 PM
# A Hole In Medium Trust Regarding Web Permission
A Hole In Medium Trust Regarding Web Permission
Requesting Gravatar... Sam Sep 25, 2007 7:21 PM
# re: Why Oh Why Couldn't WebPermission Be Part Of Medium Trust?
Use CrystalTech, they allow WebPermission in their Medium Trust environment, as well as a few other nice permissions. (Although they completely blew me off when I asked for binrary serialization permission, what a bunch of crap!)
Requesting Gravatar... steve Aug 15, 2008 11:38 PM
# re: Why Oh Why Couldn't WebPermission Be Part Of Medium Trust?
Great article.

What syntax to I tell my hoster so that they allow me to let the web service run and make the WebPermission error go away?

Thank you!

What do you have to say?

(will show your gravatar)
Please add 2 and 7 and type the answer here: