Skip to main content

Posts

Showing posts with the label ASP.NET MVC 4

CSFR attacks, ASP.NET MVC 4

CSRF stands for Cross Site Request Forgery and is a technique employed to fooling a website by executing commands on behalf of a trusted (authenticated) user. How it works Commonly a malicious user sends a link to another user that maybe is authenticated on the target site and uses their session to execute commands like transfer money, change the email address and stuff like that. CSRF in action This time I’ll be working on a web site that allows authenticated users buy pastries at the online store. In this case, the goal of the attacker is to get a bunch of muffins on somebody else’s Mastercard. The target site has a couple of web pages that allow users to logon, buy products and see their orders history: Before going on, something to worth to mention is that after a user is successfully authenticated to a  website, the web browser will be sending the authentication cookie on every subsequent request to the server until the session expire (usually aft...

Migrating an ASP.NET MVC 4 app from Azure websites to WinHost

About a week ago I've to migrate an ASP.NET MVC 4/EF5 application from Azure websites to WinHost. While the process was really smooth, there were some caveats related to database connections that I want to share with you. Create and setup the ftp profile on VS and configure the connection string was really easy, WinHost provide you those values and there is nothing special here. But once you deploy your website and try to see it online, you may get the “yellow screen of dead” with the message: "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)" Assuming you wrote the connection string properly, this happens because you cannot use the default connection name in your web.c...

How to authenticate a console app to an ASP.NET MVC 4 web site

In this post I will show you how to authenticate an application to an ASP.NET MVC web site that uses forms authentication. This sounds a bit weird, but as I found out on the web, this is a fairly common thing to do these days. The most common scenario where people want to do this is, is when they want to consume an ASP.NET MVC web site as if it was a Web API, to get resources that are already in place and are accessible thru controller’s actions. There is couple of ways of doing this, and it is pretty easy until you need to authenticate the request in order to get those resources.   The web site we are working on uses Forms Authentication, this means that when a request arrives, the ASP.NET infrastructure is going to see if this request is authenticated or not, if is not, it will redirect the request to the login page. While this works fine for web pages, is not so good for APIs. Down below I’ll show how to authenticate a client to a login page using the HttpClient cl...