publiclab/plots2

View on GitHub
app/controllers/comment_controller.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Possible unprotected redirect
Open

            redirect_to "#{@node.path}#last" # to last comment
Severity: Critical
Found in app/controllers/comment_controller.rb by brakeman

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 delete has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  def delete
    @comment = Comment.find params[:id]

    comments_node_and_path

Severity: Minor
Found in app/controllers/comment_controller.rb - About 2 hrs to fix

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 create has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def create
    @node = Node.find params[:id]
    @body = params[:body]
    @user = current_user
    begin
Severity: Minor
Found in app/controllers/comment_controller.rb - About 1 hr to fix

Method create has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def create
    @node = Node.find params[:id]
    @body = params[:body]
    @user = current_user
    begin
Severity: Minor
Found in app/controllers/comment_controller.rb - About 1 hr to fix

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 delete has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def delete
    @comment = Comment.find params[:id]

    comments_node_and_path

Severity: Minor
Found in app/controllers/comment_controller.rb - About 1 hr to fix

Method react_delete has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def react_delete
    @comment = Comment.find params[:id]

    comments_node_and_path

Severity: Minor
Found in app/controllers/comment_controller.rb - About 25 mins to fix

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

Trailing whitespace detected.
Open

            tagnames = "Click to subscribe to updates on these tags or topics: #{tagnames}" unless tagnames.empty?        

There are no issues that match your filters.

Category
Status