Re: Forms Authentication problem with WebRequest

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hello Harry,

I am using the System.Net.WebRequest class to hit a URL from within my
web application and stream out the html returned. I am using forms
authentication, and instead of getting the page I have requested, I am
getting my login screen. I assume the solution to this problem lies
in the Credentials property of WebRequest, but I am not sure what I
need to set it to. I am calling this from a page that is already
authenticated, so if I can just get the creditials from the current
page, that should do it, right?

This probably won't work

I'll try to explain why.

The normal request will go like this:

user <-> webserver
1 user: requests page.aspx 2 webserver: looks for valid cookie and redirects user to login.aspx
3 user: request login.aspx
4 webserver: server transfers login page to user
5 user: submits login.aspx
6 webserver: handles login, redirects to page.aspx, passes a cookie or url variable
7 user: reqests page.aspx and sends cookie back to server
8 webserver: server validates cookie and transfers content of page.aspx

Now in your scenario the server does a request to itself from page.aspx. Let's consider that the user already authenticated himself, so we can skip all the way to step 7

user <-> webserver <-> webserver
7 user: reqests page.aspx and sends cookie back to server
8 webserver: server validates cookie
9 webserver: requests page.aspx from itself
10 webserver: looks for a valid cookie, finds none and redirects itself to login.aspx

You might think it would be easy to fix this by authenticating (like you're trying to do) or by sending the cookie along, but:
- authenticating has nothing to do with this scenario, but with server authentication (integrated security). Forms authentication is actually just not authenticated by the server, but by the application.
- sending the cookie along might do the trick, but I believe that the cookie contains information about the originator (like IP address) and that the cookie won't match the IP of the sever (which of course differs from the user's IP).

To solve this there are a few easy solutions:
1) use a usercontrol instead of a second page include that on the original page.
2) place the second page in a seperate folder only accessible from IP 127.0.0.1, that prevents anyone else accessing it except apps on that server. You can then exclude this folder from forms authentication in the web.config
3) response.redirect the user to the second page, or use server.transfer to preserve the original url.
4) use an iframe or a normal frame to include the contents of the second page within the first one.

--
Jesse Houwing
jesse.houwing at sogeti.nl


.



Relevant Pages

  • [REVS] NTLM HTTP Authentication is Insecure By Design
    ... in front of a web server, and that proxy server shares a single TCP ... These are attacks that make use of non-RFC HTTP requests (HTTP Request ... the authentication is associated with the ...
    (Securiteam)
  • Re: EAP-TLS with windows CE
    ... The AP was sending out an Identity Request every second, ... request to the identification server. ... When the server asks the Windows CE device to identify itself, ... I could easily steal your authentication information. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Strange Digest Authentication behaviour
    ... That's the way the http stack does authentication. ... After the first request ... The IIS web server on the midtier is setup to use Digest ... > - First request to server is given 401 Access Denied message with nonce ...
    (microsoft.public.inetserver.iis.security)
  • RE: Authentication from another Application on server
    ... I have two web applications which both use forms authentication. ... server and also where they're on different servers. ... Both of these describe aspects of arranging for the same cookie to be used ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • RE: forms authentication cookie problem
    ... authentication cookie. ... what's going on on the server. ... >324488 Forms Authentication and View State Fail ... >characters, the browser will still request the page, but ...
    (microsoft.public.dotnet.framework.aspnet.security)