-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathMissingAntiForgeryTokenValidation.qhelp
More file actions
42 lines (37 loc) · 1.91 KB
/
MissingAntiForgeryTokenValidation.qhelp
File metadata and controls
42 lines (37 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>Web applications that use tokens to prevent cross-site request forgery
(CSRF) should validate the tokens for all Http POST requests.</p>
<p>Although login and authentication methods are not vulnerable to traditional
CSRF attacks, they still need to be protected with a token or other mitigation.
This because an unprotected login page can be used by an attacker to force a
login using an account controlled by the attacker. Subsequent requests to the
site are then made using this account, without the user being aware that this is
the case. This can result in the user associating private information with the
attacker-controlled account.</p>
</overview>
<recommendation>
<p>The appropriate attribute should be added to this method to ensure the
anti-forgery token is validated when this action method is called. If using the
MVC-provided anti-forgery framework this will be the
<code>[ValidateAntiForgeryToken]</code> attribute.
</p>
<p>Alternatively, you may consider including a global filter that applies token
validation to all POST requests.</p>
</recommendation>
<example>
<p>In the following example an ASP.NET MVC <code>Controller</code> is using the
<code>[ValidateAntiForgeryToken]</code> attribute to mitigate against CSRF attacks.
It has been applied correctly to the <code>UpdateDetails</code> method. However,
this attribute has not been applied to the <code>Login</code> method. This should
be fixed by adding this attribute.</p>
<sample src="MissingAntiForgeryTokenValidation.cs" />
</example>
<references>
<li>Wikipedia: <a href="https://en.wikipedia.org/wiki/Cross-site_request_forgery">Cross-Site Request Forgery</a>.</li>
<li>Microsoft Docs: <a href="https://docs.microsoft.com/en-us/aspnet/mvc/overview/security/xsrfcsrf-prevention-in-aspnet-mvc-and-web-pages">XSRF/CSRF Prevention in ASP.NET MVC and Web Pages</a>.</li>
</references>
</qhelp>