SpeciesFileGroup/taxonworks

View on GitHub
lib/queries/collecting_event/filter.rb

Summary

Maintainability
C
1 day
Test Coverage

Possible SQL injection
Open

          .having("COUNT(collecting_event_id) >= #{min_max[0]}")

Injection is #1 on the 2013 OWASP Top Ten web security risks. SQL injection is when a user is able to manipulate a value which is used unsafely inside a SQL query. This can lead to data leaks, data loss, elevation of privilege, and other unpleasant outcomes.

Brakeman focuses on ActiveRecord methods dealing with building SQL statements.

A basic (Rails 2.x) example looks like this:

User.first(:conditions => "username = '#{params[:username]}'")

Brakeman would produce a warning like this:

Possible SQL injection near line 30: User.first(:conditions => ("username = '#{params[:username]}'"))

The safe way to do this query is to use a parameterized query:

User.first(:conditions => ["username = ?", params[:username]])

Brakeman also understands the new Rails 3.x way of doing things (and local variables and concatenation):

username = params[:user][:name].downcase
password = params[:user][:password]

User.first.where("username = '" + username + "' AND password = '" + password + "'")

This results in this kind of warning:

Possible SQL injection near line 37:
User.first.where((((("username = '" + params[:user][:name].downcase) + "' AND password = '") + params[:user][:password]) + "'"))

See the Ruby Security Guide for more information and Rails-SQLi.org for many examples of SQL injection in Rails.

Possible SQL injection
Open

        q = q.having("COUNT(collecting_event_id) <= #{min_max[1]}") if min_max[1]

Injection is #1 on the 2013 OWASP Top Ten web security risks. SQL injection is when a user is able to manipulate a value which is used unsafely inside a SQL query. This can lead to data leaks, data loss, elevation of privilege, and other unpleasant outcomes.

Brakeman focuses on ActiveRecord methods dealing with building SQL statements.

A basic (Rails 2.x) example looks like this:

User.first(:conditions => "username = '#{params[:username]}'")

Brakeman would produce a warning like this:

Possible SQL injection near line 30: User.first(:conditions => ("username = '#{params[:username]}'"))

The safe way to do this query is to use a parameterized query:

User.first(:conditions => ["username = ?", params[:username]])

Brakeman also understands the new Rails 3.x way of doing things (and local variables and concatenation):

username = params[:user][:name].downcase
password = params[:user][:password]

User.first.where("username = '" + username + "' AND password = '" + password + "'")

This results in this kind of warning:

Possible SQL injection near line 37:
User.first.where((((("username = '" + params[:user][:name].downcase) + "' AND password = '") + params[:user][:password]) + "'"))

See the Ruby Security Guide for more information and Rails-SQLi.org for many examples of SQL injection in Rails.

File filter.rb has 320 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Queries
  module CollectingEvent
    class Filter < Query::Filter

      # Params exists for all CollectingEvent attributes except these.
Severity: Minor
Found in lib/queries/collecting_event/filter.rb - About 3 hrs to fix

    Class Filter has 30 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class Filter < Query::Filter
    
          # Params exists for all CollectingEvent attributes except these.
          # geographic_area_id is excluded because we handle it specially in conjunction with `geographic_area_mode``
          # Definition must preceed include.
    Severity: Minor
    Found in lib/queries/collecting_event/filter.rb - About 3 hrs to fix

      Method has too many lines. [27/25]
      Open

            def initialize(query_params)
              super
      
              @collectors = boolean_param(params, :collectors )
              @collecting_event_id = params[:collecting_event_id]

      This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

      Method initialize has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def initialize(query_params)
              super
      
              @collectors = boolean_param(params, :collectors )
              @collecting_event_id = params[:collecting_event_id]
      Severity: Minor
      Found in lib/queries/collecting_event/filter.rb - About 1 hr to fix

        TODO found
        Open

              # TODO: dry with Source, TaxonName, etc.

        TODO found
        Open

              # TODO: Spatial concern?

        TODO found
        Open

              # TODO: check, this should be simplifiable.

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

              def collection_object_query_facet
                return nil if collection_object_query.nil?
                s = 'WITH query_co_ce AS (' + collection_object_query.all.to_sql + ') ' +
                  ::CollectingEvent
                  .joins(:collection_objects)
        Severity: Minor
        Found in lib/queries/collecting_event/filter.rb and 2 other locations - About 25 mins to fix
        lib/queries/collecting_event/filter.rb on lines 383..390
        lib/queries/descriptor/filter.rb on lines 153..161

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 30.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

              def otu_query_facet
                return nil if otu_query.nil?
                s = 'WITH query_otu_ces AS (' + otu_query.all.to_sql + ') ' +
                  ::CollectingEvent.joins(:otus)
                  .joins('JOIN query_otu_ces as query_otu_ces1 on query_otu_ces1.id = otus.id')
        Severity: Minor
        Found in lib/queries/collecting_event/filter.rb and 2 other locations - About 25 mins to fix
        lib/queries/collecting_event/filter.rb on lines 393..401
        lib/queries/descriptor/filter.rb on lines 153..161

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 30.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        There are no issues that match your filters.

        Category
        Status