A quick intro.
In simple terms:- A friendly person A visits our happy site Happy.com and logs in.
- Happy.com site authenticates him and gives him a cookie so that every time he visits us we know he's a good guy.
- Unknowingly, friendly guy A visits a bad site Evil.com.
- Evil site Evil.com will sneakily return a malicious form tag that will request to our Happy.com site. This malicious code will be allowed to access our server because it is attached to the authentication cookie we gave him and we think that it has already been authenticated.
- Bad things can happen.
This works because the authentication cookie is being transported with the request.
The only way to prevent this is to ensure the form is created by the good user. We use an antiForgery token to help here.
In the View we put the anti forgery helper:
<% using (Html.BeginForm()) {%>
<% = Html.AntiForgeryToken() %>
In the controller action we use the ValidateAntiForgeryToken attribute:
[ValidateAntiForgeryToken]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id,
With this asp.net creates a crypto token that can't be created by the Evil user.
No comments:
Post a Comment