New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ruby: Add a query for CSRF protection not enabled #14308
base: main
Are you sure you want to change the base?
Conversation
Specifically in Rails apps, we look for root ActionController classes without a call to `protect_from_forgery`.
|
QHelp previews: ruby/ql/src/queries/security/cwe-352/CSRFProtectionNotEnabled.qhelpCSRF protection not enabledCross-site request forgery (CSRF) is a type of vulnerability in which an attacker is able to force a user to carry out an action that the user did not intend. The attacker tricks an authenticated user into submitting a request to the web application. Typically this request will result in a state change on the server, such as changing the user's password. The request can be initiated when the user visits a site controlled by the attacker. If the web application relies only on cookies for authentication, or on other credentials that are automatically included in the request, then this request will appear as legitimate to the server. A common countermeasure for CSRF is to generate a unique token to be included in the HTML sent from the server to a user. This token can be used as a hidden field to be sent back with requests to the server, where the server can then check that the token is valid and associated with the relevant user session. RecommendationIn the Rails web framework, CSRF protection is enabled by the adding a call to the ExampleThe following example shows a case where CSRF protection is enabled with a secure request handling strategy of class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
end
References
|
| not exists(ActionController::ProtectFromForgeryCall call | | ||
| c.getSelf().flowsTo(call.getReceiver()) | ||
| ) | ||
| select c, "Potential CSRF vulnerability due to forgery protection not being enabled" |
Check warning
Code scanning / CodeQL
Alert message style violation Warning
|
This might be a bit over-sensitive. We could reduce the FP rate by looking for specific routes which map to actions in controllers with no |
|
|
Specifically in Rails apps, we look for root ActionController classes without a call to
protect_from_forgery.