protect_from_forgery should be configured with 'with: :exception' Open
class DocumentCommitteeController < ActionController::Base
- Read upRead up
- Exclude checks
Cross-site request forgery is #5 on the OWASP Top Ten. CSRF allows an attacker to perform actions on a website as if they are an authenticated user.
This warning is raised when no call to protect_from_forgery
is found in ApplicationController
. This method prevents CSRF.
For Rails 4 applications, it is recommended that you use protect_from_forgery :with => :exception
. This code is inserted into newly generated applications. The default is to nil
out the session object, which has been a source of many CSRF bypasses due to session memoization.
See the Ruby Security Guide for details.
Method create_document
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def create_document
if params[:title].to_s == "" or params[:url].to_s == ""
flash[:notice] = "Populate all fields before submission."
redirect_to new_committee_document_path
elsif !(params[:url]=~/.com(.*)/)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method update_document
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def update_document
if params[:title].to_s == "" or params[:url].to_s == ""
flash[:notice] = "Populate all fields before submission."
redirect_to new_committee_document_path
elsif !(params[:url]=~/.com(.*)/)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"