asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Easy Application State Securely
By Dmitry Khanine
Rating: 2.6 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Easy Application State Securely

    The biggest challenge in making your web site 100- percent secure is how to maintain your application state.

    The traditional desktop application "know" who is using it as soon as the user passes the authentication - whether on operating system level or inside the application itself. The application may be sure that it is the same user who is interfacing with it. A web application, however, may only assume. A standard web application is stateless. meaning You usually don’t know who is calling your page and from where unless the page has some direct authentication or you are saving your variables on the user machine through cookies.

    ASP gives us much more flexibility. With ASP Application and Session objects your web application has the ability to maintain its state from page to page, so once the user enters his password on page 1 and his user ID is stored as a variable inside your Session object,

    
    <%
    	Session("UserId") = 4521
    %>
    
    
    on page 10, you will be able to examine your UserId variable and be sure this is still the same user. Let’s assume the Session mechanism is completely reliable.

    Now imagine that your application provides your users some sort of confidential market information. After authentication on pages 1 through 10 you ask the user what sort of information he requires and finally provide it on page 11. What happens if your user tries to save time by going directly to page 11 by typing this location in his browser address box? On page 11 you check his Session(“UserId”) and its still 4521! How would you know if the information submitted on page 11 is up to date? And will your page 11 work correctly if invoked this way, if any or all of parameters you expect at this page are not supplied?

    Now let’s ask ourselves if it is really safe to use ASP Sessions. ASP documentation alerts you: “Session state is only maintained for browsers that support cookies.” This means that Sessions are not the safe way of maintaining your application’s state because the client browser may not support or accept cookies. To let each page know what was done before we have to transfer all the application data from one page to another.

    There are methods of doing this. You may pass your parameters as a URL-encoded string or submit them using your form via the GET method, or you may use the Standard IN/OUT stream via POST when all data that needs to be transferred to the page is stored in the <input type="hidden" ...>

    HTML tags:

    
    
    <form method="POST">
    	<input type="hidden" name="param1" value="value1">
    	<input type="hidden" name="param2" value="value2">
    	<input type="submit" value="Submit">
    </form>
    
    
    

    POST has biggest advantage. It hides data from the user and "the evil person" who may want to compromise your security system as well. However, everyone might write his own HTML form, fill your "hidden" inputs with the data he likes, and submit it to your application:

    
    
    <form method="POST">
    	<input type="hidden" name="param1" value="value2">
    	<input type="hidden" name="param2" value="something_else">
    	<input type="submit" value="Submit">
    </form>
    
    
    
    The GET method is more flexible since you may want to send some data to the page invoked through the URL link:
    
    
    <a href="your_page.asp?param1=value1¶m2=value2">
    
    
    
    But imagine, anyone can access your resource even easier just by typing this string in their browser address box:
    
    
    http://your_site.com/your_page.asp?param1=value1¶m2=value2
    
    
    
    Someone may also want to type it like this:
    
    
    http://your_site.com/your_page.asp?param1=value2¶m2=something_else
    
    
    
    Here’s what we need to do:
    1. We need to maintain our application state to be sure at page 10 that the user who authenticated at page 1 is still the same user. We would like to not use ASP Sessions and cookies in critical sections of our application.
    2. We need to have some reliable way of checking that all the pages (except default.asp) of our application are always called with the correct parameters and that they are really called from within the application itself.
    Once problem 2 is solved, we will be able to accomplish task 1 successfully by transferring the application data from page to page.

    How can we solve problem 2? The only way is to introduce some sort of authentication at the beginning of each page to check, again, that the page is called with correct parameters and that it is really called from within the application itself. Obviously, we can’t bother the user with UserId/Password inquiries so frequently, so we need to find something else that can answer our questions behind the scenes. Maybe the client’s browser can help.

    Let’s check the arsenal. What is information can the client browser give us? We will write a very small utility program called list_env.asp that may help in many cases. All it does is list all the server environment variables so we can see what information we have. Here is the ASP code for list_env.asp:

    
    
    <%@Language=VBSCRIPT%>
    <HTML>
    <BODY>
    <%
    	For Each v in Request.ServerVariables
    		Response.Write("<p><b>" & v & "</b> = ")
    		Response.Write(Request.ServerVariables(v))
    	Next
    %>
    </BODY>
    </HTML>
    
    
    
    And here is a fragment from this application’s output when invoked from page1.asp through the link <a href="list_env.asp">List environment variables</a>:
    APPL_PHYSICAL_PATH = C:\Inetpub\wwwroot\
    LOCAL_ADDR = 127.0.0.1
    PATH_INFO = /list_env.asp
    PATH_TRANSLATED = C:\Inetpub\wwwroot\list_env.asp
    QUERY_STRING =
    REMOTE_ADDR = 127.0.0.1
    REMOTE_HOST = 127.0.0.1
    REQUEST_METHOD = GET
    SCRIPT_NAME = /list_env.asp
    SERVER_NAME = localhost
    URL = /list_env.asp
    HTTP_ACCEPT = image/gif, image/x-xbitmap, image/jpeg,
    image/pjpeg, application/vnd.ms-
    excel, application/msword, application/vnd.ms-powerpoint, */*
    HTTP_ACCEPT_LANGUAGE = en-us
    HTTP_REFERER = http://localhost/page1.asp
    HTTP_USER_AGENT = Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)
    HTTP_COOKIE = GENERALRESTAURANTS=LOG=Login11&PWD=22; GUID;
    ASPSESSIONIDGGQQGQYX=ICCNNJJDIHBCADHHDHIHLDNG;
    ASPSESSIONIDQQQGGGYN=EJCPOJJDOGCIOGFCBDOMEIAD; …
    HTTP_ACCEPT_ENCODING = gzip, deflate
    You may want to store the user IP address (REMOTE_HOST variable) somewhere on your system and verify at the beginning of each page whether it is the same user. (See 15 Seconds article by Alain Trotter in the Nov. 4, 1998 issue, “ASP Authentication Using IP Address”). But this still doesn’t guarantee the user will not call your page by typing something in the address box. It also may not work with some network configurations where the user IP address may change.

    HTTP_REFERER, however, will give you all the information you need. By checking the HTTP_REFERER value at the beginning of each page you can assure that the page is really called from within the application itself and, therefore, is called with correct parameters!

    Editors Note
    The "HTTP_REFERER" environment variable is set by the server before the ASP script is processed. The contents of this field are obtained by reading the HTTP header passed in to the server by the client browser. However, according to the HTTP/1.0 specifications and the HTTP/1.1 specifications, the "HTTP-Referer" field in the HTTP header is optional:
    "Note: Because the source of a link may be private information or may reveal an otherwise private information source, it is strongly recommended that the user be able to select whether or not the Referer field is sent. For example, a browser client could have a toggle switch for browsing openly/anonymously, which would respectively enable/disable the sending of Referer and From information."
    If the client does not send the "HTTP-Referer" field in its header, the authentication advocated in your article will fail -- thus locking out authorized users. More to the point, since the "HTTP-Referer" field is generated by the client browser and sent in with the HTTP request, it is untrustworthy. Any system cracker worth who knows what they're doing will be able to fake their "HTTP-Referer" field just as easily as they can fake cookies and forms. Advocating that a website's security rely on the "HTTP-Referer" field, cookies, "HIDDEN" form fields, HTTP/1.x's "Basic authentication" or IP address verification is foolish in the extreme, since none of those techniques are bulletproof -- they can all be circumvented.

    For more details, I would refer you to the following RFCs:

    Special Thanks to Sam Clippinger
    To make transferring data between the pages of your application safe and reliable, consider checking the HTTP_REFERER environment variable at the beginning of each page. This can be done in just two steps:
    1. First write the simple ASP include file; and name it referrer.asp*:
      
      
      lt;%
      Dim sResult
      sResult = InStr( 1, Request.ServerVariables("HTTP_REFERER"), _
       "//your_host_name/your_app_path/", 1)
      if sResult = 0 or sResult = Null then
      Response.Redirect("error.htm")
      End If
      %>
      
      
      
      Note
      You shouldn’t give your include files an .inc extension because anyone will be able to access their source by simply typing the file location in the browser’s address box. When the extension is changed to .asp the ASP processor interprets the file and no output will be done in most cases. For details see Active Server Developer’s Journal, February 1998 “Making #INCLUDE files "hack-proof" by Jeremy Broyle.
      The above code is just checking whether the user really comes from your site. 2. Include this check in all of your pages that take parameters:
      
      
      <%@ LANGUAGE = VBSCRIPT%>
      <%Option Explicit%>
      <!-- #INCLUDE file="referer.asp" -->
      <% ‘Your ASP code goes here %>
      
      
      
      This assures that your site will have only the number of entry points that you want it to have. These simple steps will make your site behave like a single application. When the user authenticates at page 1, you will be sure that it is still the same user (more precisely - the same client machine) at page 10, because there will be no way to submit a UserId anywhere else besides within your web application.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Supporting Products/Tools
    ASP Session Manager
    ASP Session Manager works by inserting 2 lines of code at the top of your ASP script and have the session serialize itself to any DBMS. There are three licenses available, ranging from a single binary to an enterprise ISP license with source code.
    [Top]
    AspEncrypt
    Built around the Microsoft CryptoAPI, AspEncrypt helps you harness all major encryption and hashing algorithms such as DES, Triple-DES, RC2, RC4, RSA, MD5 and SHA1 in just a few lines of code. The component can be used in tandem with AspEmail to send encrypted and signed mail in the industry-standard S/MIME format, or with AspUpload to encrypt files as they are being uploaded. AspEncrypt can also be used to issue and manage X.509 digital certificates.
    [Top]
    AspPDF
    AspPDF is an ASP/ASP.NET component which enables generation and management of documents in PDF format. Features include advanced text formatting, font embedding, form fill-in, images, tables, content and page extraction, document stitching, encryption, digital signatures, and more.
    [Top]
    SA-Session Pro
    Web farm getting out of control? You need scalability! SA-SessionPro is a simple, yet very powerful means of making your ASP application persistent--share and save information on a per-user, per-application, per-server, or per network basis. SA-Session is like the built in Session object that comes with the IIS Server, except it allows developers more flexibility. It has the ability to store information without expiration and the ability to preserve session state across multiple machines in a web farm.
    [Top]
    SessionFarm
    SessionFarm is an Active Server Pages component that allows you to manage session state on multiple servers in a web-farm. SessionFarm utilizes the built-in IIS Session object which means you don't have to learn new methods and objects. The IIS Session object is stored on either a file-share or a SQL database using optimized stored procedures.

    SessionFarm requires no rewriting of your existing code and works by supplementing the existing IIS Session.

    For code samples, see http://www.groat.com/sessionfarm/implement.asp.

    [Top]
    Other Articles
    Feb 3, 2005 - ASP.NET Mixed Mode Authentication
    In many web applications it is desirable for both intranet users and external parties to be able to seamlessly log onto the system. The problem this raises is that it is not easy to allow intranet users to log in via Windows integrated authentication while also allowing external parties to log in to the same application using standard forms authentication. This article will show you one way to achieve the best of both worlds when it comes to authentication.
    [Read This Article]  [Top]
    Dec 8, 2004 - Designing Role-Based Security Models for .NET
    In this article, Michele Leroux Bustamante discusses authentication, authorization and role-based security in .NET. Along the way, he provides some best practices for implementing role-based security in some typical .NET application scenarios including rich clients, Web applications, and Web services.
    [Read This Article]  [Top]
    May 11, 2004 - SharePoint Security and .NET Impersonation
    When implementing custom components that require access to restricted resources, implicit impersonation must be used. Jay Nathan shows how to create a class that makes using .NET Impersonation a snap.
    [Read This Article]  [Top]
    Mar 10, 2004 - Intellectual Property Protection and Code Obfuscation
    Learn about the execution process of CLR-based programs and how to protect your applications from being easily disassembled back into source code.
    [Read This Article]  [Top]
    Feb 24, 2004 - How to Send Secure Mail in ASP-Based E-Commerce Applications - Part II
    Businesses that utilize encrypted e-mail may find Secure Multipurpose Internet Mail Extensions (S/MIME) to be somewhat restrictive. This article shows how to use security features in PDF as an alternative to S/MIME.
    [Read This Article]  [Top]
    Feb 2, 2004 - Fighting Spambots with .NET and AI
    Bill Gates, in a recent interview, predicted the end of spam by 2006. One of the methods he mentioned involved a challenge only a real live person could handle. Adnan Masood shows how to use AI and .NET to create a user verification scheme that incorporates similar concepts Gates alluded to.
    [Read This Article]  [Top]
    Jan 21, 2004 - Configuring .NET Code Access Security
    Code Access Security (CAS) is the .NET Framework security model that grants code permission to resources based on "evidence" pertaining to the encapsulating assembly. In this article, David Myers examines CAS and explains different configuration methods.
    [Read This Article]  [Top]
    Mar 10, 2003 - Platform Neutral and Transparent Encryption of Sensitive Customer Information
    Zhenlei Cai combines an open source C++ encryption library with SQL Server extended stored procedures to create a platform neutral, transparent encryption solution that resides at the database layer.
    [Read This Article]  [Top]
    Jan 15, 2003 - Exploring Machine.Config - User Security and More
    Christopher Spann offers a .NET configuration tip that should help ease system administrators' fears of security compromise and thus assuage growing developer demand for a .NET environment.
    [Read This Article]  [Top]
    Dec 10, 2002 - Encrypting Cookie Data with ASP.NET
    You don't have to be a cryptography expert or spend lots of money on third-party components to secure sensitive data in .NET. In this article, Wayne Plourde shows just how easy it is to encrypt cookie data using encryption classes in the .NET System.Security.Cryptography namespace.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info

    Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers