Cross-Site Attacks in ASP.NET Core – Session 58

cross-site-attacks-in-asp-net-core-Session58

During this session, we explain the Cross-Site attacks or XSRF/CSRF attacks and will show you how to manage Cross-Site attacks in ASP.NET Core. This type of attack is also known as XSRF/CSRF attacks. Cross-Site or XSRF/CSRF is an attack against web-hosted apps in which a malicious web app can affect how a client browser interacts with a web app that relies on that browser. As various forms of authentication tokens are sent by web browsers automatically with each request to a website, these attacks are made possible. This type of exploit makes use of the user’s previously authenticated session, it is also known as a one-click attack or session riding.

What are the Cross-Site Attacks?

Cross-Site or XSRF/CSRF is an attack against web-hosted apps in which a malicious web app can affect how a client browser interacts with a web app that relies on that browser. This type of exploit makes use of the user’s previously authenticated session.

Let us explain this type of attack with an example. Imagine you receive an email with the below content.

cross-site attack example

As the content is attractive, some users are tempted to click on the button to see what happens next. Then, there is the place where the Cross-Site attack occurs.

Because if we have already authenticated with our Bank web app with the browser, the below code which is behind the above attractive message, submit a transfer request to our bank account.

As you can see instead of receiving any funds, we miss the above-mentioned amount of money from our bank account which was submitted by the malicious page. Of course, in real cases, it may not going to be as simple as we explain here, but I make it as simple as possible to convey the message.

Prevent Cross-Site Attacks in ASP.NET Core

There are several methods to prevent Cross-Site attacks (XSRF/CSRF). Also, the method that we provide during this session is not the only adequate way to secure your web app against this type of attack. But, we use Anti Forgery Token in this session to secure our web app against these attacks. The mentioned token is normally sent to the Controller from the form (with the Post method) in the View. It means, the asp-antiforgery Tag helper value is True by default and we don’t need to set this value inside the Form tag.

Next, we need to decorate the respective Action Methods to ValidateAntiForgeryToken attribute to secure the action methods against Cross-Site attacks.

Below code is related to the Cost Controller and we decorate all the action methods with the post method to the mentioned attribute. These modifications secure our action methods against this attack.

If you need more details, watch this session video. Also, to be updated about our coming sessions, follow us on Instagram, Facebook, Telegram, or YouTube. Moreover, you can have access to the list of all sessions HERE and you can download this session source code from our GitHub.

You can download this Session Slides form HERE.

0.00 avg. rating (0% score) - 0 votes

Tags

0 0 votes
Article Rating
guest

0 Comments
Inline Feedbacks
View all comments