Possible unprotected redirect Open
redirect_to "/tag/" + params[:name]
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Unvalidated redirects and forwards are #10 on the OWASP Top Ten.
Redirects which rely on user-supplied values can be used to "spoof" websites or hide malicious links in otherwise harmless-looking URLs. They can also allow access to restricted areas of a site if the destination is not validated.
Brakeman will raise warnings whenever redirect_to
appears to be used with a user-supplied value that may allow them to change the :host
option.
For example,
redirect_to params.merge(:action => :home)
will create a warning like
Possible unprotected redirect near line 46: redirect_to(params)
This is because params
could contain :host => 'evilsite.com'
which would redirect away from your site and to a malicious site.
If the first argument to redirect_to
is a hash, then adding :only_path => true
will limit the redirect to the current host. Another option is to specify the host explicitly.
redirect_to params.merge(:only_path => true)
redirect_to params.merge(:host => 'myhost.com')
If the first argument is a string, then it is possible to parse the string and extract the path:
redirect_to URI.parse(some_url).path
If the URL does not contain a protocol (e.g., http://
), then you will probably get unexpected results, as redirect_to
will prepend the current host name and a protocol.
Method multiple_add
has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring. Open
def multiple_add
return_to = params[:return_to] || "/subscriptions?_=" + Time.now.to_i.to_s
if params[:tagnames].blank?
flash[:notice] = "Please enter tags for subscription in the url."
redirect_to return_to
- Read upRead up
- Create a ticketCreate a ticket
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 add
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def add
if current_user && params[:type] == "tag"
tag = Tag.find_by(name: params[:name])
- Read upRead up
- Create a ticketCreate a ticket
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 multiple_add
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
def multiple_add
return_to = params[:return_to] || "/subscriptions?_=" + Time.now.to_i.to_s
if params[:tagnames].blank?
flash[:notice] = "Please enter tags for subscription in the url."
redirect_to return_to
- Create a ticketCreate a ticket
Method add
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
def add
if current_user && params[:type] == "tag"
tag = Tag.find_by(name: params[:name])
- Create a ticketCreate a ticket
Method delete
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def delete
# assume tag, for now
if params[:type] == "tag"
id = Tag.find_by(name: params[:name]).tid
end
- Read upRead up
- Create a ticketCreate a ticket
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
Avoid deeply nested control flow statements. Open
tagnames = params[:tagnames].class == Array ? params[:tagnames].join(', ') : params[:tagnames]
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
rescue ActiveRecord::RecordInvalid
flash[:error] = tag.errors.full_messages
redirect_to return_to
return false
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
render json: { status: status, message: message, id: tag.tid, tagname: params[:name], url: "/tags" + "?_=" + Time.now.to_i.to_s } if current_user
- Create a ticketCreate a ticket