Configuration File Settings and ASP.Net Security
Somebody brought up a good point about my Configuration Settings class today that I failed to mention in the article: Security requirements for an ASP.Net application to be able to actually make changes to the .Config file.
If you are running in the default security environment the ASP.Net app runs under the ASPNET or NETWORK SERVICE account and these accounts usually don't have rights to write to web.config or any other part of application.
I personally run my ASP.Net apps under a specific user and assign this user to a Windows 2003 Application Pool which I then use for the application. Usually I configure this user to have read/write access in the application directory because I have a number of tasks that read and write to the file system in various places of my framework. I don't feel this is a huge security risk because in order to do anything with these 'loose' permission soembody has to first be able to compromise either my app (via some script or injection) or by hacking into the machine itself. If that's the case my Web directory is probably the last thing I need to worry about.
So, by default ASPNET and Network Service aren't allowed and if you're not comfortable with the environment I run (and many aren't ) you can limit your exposure by just allowing read/write access to web.config for these accounts. This file already has read access (although it can't be accessed over the Web due to ASP.Net's internal forbidden handlers) which if anything is the bigger vulnerability.
Using Impersonation in a separate web.config
As I was thinking about this I found another solution that should work without changing security if you have a separate directory to run all Admin requests through. Updating web.config should not be something you do frequently, so this requirement to run from a separate directory should be workable - all my apps use an Administration path for all admin tasks for example and I can place a separate web.config there that uses Impersonation to run under the account the user logged in under.
In this admin directory which should sit below your app root you can add a secondary web.config file that overrides the security settings of the primary web.config file. Set it to use Windows Auth and Impersonation like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<identity impersonate="true" />
<!-- WS: Allow only Authenticated users -->
<authorization>
<deny users="?" />
</authorization>
</system.web>
</configuration>
This is basically telling ASP. Net to impersonate the logged on user and to deny anonymous access which will force a login when any page in the directory with this web.config (or below) is accessed. Now when you hit any pages in the admin directory the remote user is impersonated and if this remote user has the appropriate rights on the server the application has rights to write web.config. This means an anonymous user has no access, but I as an Admin user have the rights to actually write to the .config files.
I just tried this and it works great even though several sources I checked state that you can't set authentication in a sub directory below the approot. It works though.
Other Posts you might also like
- Adding minimal OWIN Identity Authentication to an Existing ASP.NET MVC Application
- Resolving Paths To Server Relative Paths in .NET Code
- Map Physical Paths with an HttpContext.MapPath() Extension Method in ASP.NET
- Back to Basics: Rewriting a URL in ASP.NET Core
- Getting the Client IP Address in ASP.NET Core
The Voices of Reason
# re: Configuration File Settings and ASP.Net Security
# re: Configuration File Settings and ASP.Net Security
I am facing a problem like, when i am running my program in my local server i am able to access all the pages.But when i am placing it in the server and accessing it it gives me an error
"Please make < customErrors > tag in "Web.config" configuration file which exists in the root directory of a present Web application to make details of this error message can displayed with a remote computer. Afterwards, please set "Mode" attribute to "Off" with this < customErrors > tag."
Can you please help me out in this
# re: Configuration File Settings and ASP.Net Security
I am facing a serious problem running Asp.net Application. Actually , on our production we've Windows Server 2003
Enterprise Edition running IIS 6.0 and .NET Framework 1.1.
Every request of every .aspx file results in
a "Server Application Unavailable" message in the browser. No errors
are recorded in the Event viewer.
Any suggestions is appreciated
thanks
jaba
# Server Application Unavailable
When i query more tables from database using asp i end up with the following error.
Server application unavailable
For smaller queries i dont find any error
Can anyone solve this problem
I changed the processmodel attribute to "SYSTEM"(one of the suggested answers).I also increased the memory limit to 90. but i still end up with the same error
can anyone help me out.
# re: Configuration File Settings and ASP.Net Security
<appSettings file="myProd.config">
</appSettings>
If myProd.config will overwrite my above myProd.config ?
Thanks,
Stan
# re: Configuration File Settings and ASP.Net Security
# re: Configuration File Settings and ASP.Net Security
I haev small problem infect i have some html files witch stores in fodler with name articals . so i want just reg user can view html files but its not accessable from direct link spouse eye4tech.us/volume/artical/getit.html
i user windows authentication method but using this method i can just restrict aspx file but not html files . so plz whats the way
Thanks
# re: Keyword not supported: 'provider'.
when i am trying to connect to sql server using ado.net i am getting the error keyword not supported :'provider' plse help me.
i have written the code as
con=new SqlConnection("Provider=SQLOLEDB.1;User ID=sa;Initial Catalog=admin;Data Source=(local)")
# Failed to impersonate the Anonymous User for ASP Application /LM/W3SVC/2/Root.
When i am accessing site . i am getting the above error. we are using iis 6. In IIS the hirarchy of my accessing site is child and it is using ananymous. where as the parent is using integrated . and all the above is using both anaymous and integrated. Can u suggest on this.
# re: Configuration File Settings and ASP.Net Security
# Configuration ASP.Net Application on Different Machine
I developed ASP.NET application on which the systems contains WinXP pro & VS2003 with the backend as MySQL. This application was working fine on the same system. But when I moved this application to the local server, which also having IIS5.1 & virtual directory too, i could not able to run this. The Error was "the page cannot be found". Can anyone help me out. And is it necessary to have VS2003 to run the ASP.NET application?
Thxs
# Browser Compatibility for asp.net validators
But the validation controls are not supported by Netscape( which are supported well by the ie browser)
I've also tried vaarious asp.net <browsercaps> codes. But could not succeed .
Can anybody provide me latest <browsercaps> code or some other solution regarding this?
Thanks in advance
Parag
# Need Help
machine to use for one ASP.net application. i am using IIS 6.
ASP.net application runs fine but it become unavailable in every hour with a
big red color message "Server Application Unavailable".
i am also using simple ASP pages but
they are running fine but ASP.net application give this error. Please Help
niraj@anantsoftech.com
# re: Configuration File Settings and ASP.Net Security
Can somebody guide me.
my email address is adeelanjum2001@hotmail.com
thanks in advance
# re: Configuration File Settings and ASP.Net Security
# Process related question
In a web applicabtion if I try to start a process, it runs under the ASPNet user. I have tried the different solutions without any resolution. No matter which solution I use the process is started under the same user name.
My requirement is to run the process under another user name other than ASPNet user. Can you suggest a method.
Thanks,
Jinu
# re: Configuration File Settings and ASP.Net Security
# re: Configuration File Settings and ASP.Net Security
I am facing a problem like, when i am running my program in my local server it gives me an error
"Please make < customErrors > tag in "Web.config" configuration file which exists in the root directory of a present Web application to make details of this error message can displayed with a remote computer. Afterwards, please set "Mode" attribute to "Off" with this < customErrors > tag."
Can you please help me out in this
email: m.omais@gmail.com
# re: Configuration File Settings and ASP.Net Security
However, adding impersonation to a web.config file under a subdirectory worked perfectly. Thank you so much I never would have thought of doing that.
# re: Configuration File Settings and ASP.Net Security
# re: Configuration File Settings and ASP.Net Security
Can anyone help me in this pleaseeeeee? Its very urgent
Thanks in Advance
Srinivas
# re: Configuration File Settings and ASP.Net Security
In that case the only workable way is programmatic impersonation.
Right?
# re: Configuration File Settings and ASP.Net Security
How do I get my settings, from my winform app into the services config file!
I have to put a shared file somewhere.
# re: Configuration File Settings and ASP.Net Security
Pete.