|
| 1 | +<!DOCTYPE qhelp PUBLIC |
| 2 | + "-//Semmle//qhelp//EN" |
| 3 | + "qhelp.dtd"> |
| 4 | +<qhelp> |
| 5 | + |
| 6 | + <overview> |
| 7 | + <p> |
| 8 | + Cross-site request forgery (CSRF) is a type of vulnerability in which an |
| 9 | + attacker is able to force a user carry out an action that the user did |
| 10 | + not intend. This may allow the attacker to perform actions on behalf of |
| 11 | + the targeted user. |
| 12 | + </p> |
| 13 | + |
| 14 | + <p> |
| 15 | + The attacker tricks an authenticated user into submitting a request to the |
| 16 | + web application. Typically this request will result in a state change on |
| 17 | + the server, such as changing the user's password. The request can be |
| 18 | + initiated when the user visits a site controlled by the attacker. If the |
| 19 | + web application relies only on cookies for authentication, or on other |
| 20 | + credentials that are automatically included in the request, then this |
| 21 | + request will appear as legitimate to the server. |
| 22 | + </p> |
| 23 | + |
| 24 | + <p> |
| 25 | + A common countermeasure for CSRF is to generate a unique token to be |
| 26 | + included in the HTML sent from the server to a user. This token can be |
| 27 | + used as a hidden field to be sent back with requests to the server, where |
| 28 | + the server can then check that the token is valid and associated with the |
| 29 | + relevant user session. |
| 30 | + </p> |
| 31 | + </overview> |
| 32 | + |
| 33 | + <recommendation> |
| 34 | + <p> |
| 35 | + In many web frameworks, CSRF protection is enabled by default. In these |
| 36 | + cases, using the default configuration is sufficient to guard against most |
| 37 | + CSRF attacks. |
| 38 | + </p> |
| 39 | + </recommendation> |
| 40 | + |
| 41 | + <example> |
| 42 | + <p> |
| 43 | + The following example shows a case where forgery protection is disabled by |
| 44 | + skipping token verification. |
| 45 | + </p> |
| 46 | + |
| 47 | + <sample src="examples/UsersController.rb"/> |
| 48 | + |
| 49 | + <p> |
| 50 | + Verification can be re-enabled by removing the call to |
| 51 | + <code>skip_before_action</code>. |
| 52 | + </p> |
| 53 | + |
| 54 | + </example> |
| 55 | + |
| 56 | + <references> |
| 57 | + <li>Wikipedia: <a href="https://en.wikipedia.org/wiki/Cross-site_request_forgery">Cross-site request forgery</a></li> |
| 58 | + <li>OWASP: <a href="https://owasp.org/www-community/attacks/csrf">Cross-site request forgery</a></li> |
| 59 | + <li>Securing Rails Applications: <a href="https://guides.rubyonrails.org/security.html#cross-site-request-forgery-csrf">Cross-Site Request Forgery (CSRF)</a></li> |
| 60 | + </references> |
| 61 | + |
| 62 | +</qhelp> |
0 commit comments