SpeciesFileGroup/taxonworks

View on GitHub
app/controllers/images_controller.rb

Summary

Maintainability
B
4 hrs
Test Coverage

Possible unprotected redirect
Open

        format.html { redirect_to @image, notice: 'Image was successfully updated.' }

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.

Class ImagesController has 24 methods (exceeds 20 allowed). Consider refactoring.
Open

class ImagesController < ApplicationController
  include DataControllerConfiguration::ProjectDataControllerConfiguration
  after_action -> { set_pagination_headers(:images) }, only: [:index, :api_index, :api_image_inventory], if: :json_request?

  before_action :set_image, only: [:show, :edit, :update, :destroy, :rotate, :regenerate_derivative]
Severity: Minor
Found in app/controllers/images_controller.rb - About 2 hrs to fix

    Please use Rails.root.join('path', 'to') instead.
    Open

        tempfile = Tempfile.new(['ocr', '.jpg'], "#{Rails.root.join("public/images/tmp")}", encoding: 'utf-8')

    This cop is used to identify usages of file path joining process to use Rails.root.join clause. It is used to add uniformity when joining paths.

    Example: EnforcedStyle: arguments (default)

    # bad
    Rails.root.join('app/models/goober')
    File.join(Rails.root, 'app/models/goober')
    "#{Rails.root}/app/models/goober"
    
    # good
    Rails.root.join('app', 'models', 'goober')

    Example: EnforcedStyle: slashes

    # bad
    Rails.root.join('app', 'models', 'goober')
    File.join(Rails.root, 'app/models/goober')
    "#{Rails.root}/app/models/goober"
    
    # good
    Rails.root.join('app/models/goober')

    Please use Rails.root.join('path', 'to') instead.
    Open

        tempfile = Tempfile.new(['ocr', '.jpg'], "#{Rails.root.join("public/images/tmp")}", encoding: 'utf-8')

    This cop is used to identify usages of file path joining process to use Rails.root.join clause. It is used to add uniformity when joining paths.

    Example: EnforcedStyle: arguments (default)

    # bad
    Rails.root.join('app/models/goober')
    File.join(Rails.root, 'app/models/goober')
    "#{Rails.root}/app/models/goober"
    
    # good
    Rails.root.join('app', 'models', 'goober')

    Example: EnforcedStyle: slashes

    # bad
    Rails.root.join('app', 'models', 'goober')
    File.join(Rails.root, 'app/models/goober')
    "#{Rails.root}/app/models/goober"
    
    # good
    Rails.root.join('app/models/goober')

    TODO found
    Open

      # TODO: remove for /images.json
    Severity: Minor
    Found in app/controllers/images_controller.rb by fixme

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

      def index
        respond_to do |format|
          format.html do
            @recent_objects = Image.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
            render '/shared/data/all/index'
    Severity: Major
    Found in app/controllers/images_controller.rb and 4 other locations - About 55 mins to fix
    app/controllers/biological_associations_controller.rb on lines 9..20
    app/controllers/extracts_controller.rb on lines 9..19
    app/controllers/georeferences_controller.rb on lines 8..18
    app/controllers/observations_controller.rb on lines 9..21

    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 44.

    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 23 locations. Consider refactoring.
    Open

      def update
        respond_to do |format|
          if @image.update(image_params)
            format.html { redirect_to @image, notice: 'Image was successfully updated.' }
            format.json { render :show, status: :ok, location: @image }
    Severity: Major
    Found in app/controllers/images_controller.rb and 22 other locations - About 55 mins to fix
    app/controllers/asserted_distributions_controller.rb on lines 58..65
    app/controllers/attributions_controller.rb on lines 58..65
    app/controllers/biological_associations_controller.rb on lines 60..67
    app/controllers/biological_associations_graphs_controller.rb on lines 60..67
    app/controllers/biological_relationships_controller.rb on lines 77..84
    app/controllers/character_states_controller.rb on lines 45..52
    app/controllers/collection_object_observations_controller.rb on lines 47..55
    app/controllers/common_names_controller.rb on lines 62..69
    app/controllers/confidences_controller.rb on lines 55..62
    app/controllers/depictions_controller.rb on lines 86..93
    app/controllers/documents_controller.rb on lines 45..52
    app/controllers/extracts_controller.rb on lines 60..67
    app/controllers/gene_attributes_controller.rb on lines 49..56
    app/controllers/observation_matrices_controller.rb on lines 63..70
    app/controllers/organizations_controller.rb on lines 52..59
    app/controllers/origin_relationships_controller.rb on lines 59..66
    app/controllers/otu_page_layouts_controller.rb on lines 47..54
    app/controllers/protocol_relationships_controller.rb on lines 63..70
    app/controllers/protocols_controller.rb on lines 56..63
    app/controllers/ranged_lot_categories_controller.rb on lines 45..52
    app/controllers/sequences_controller.rb on lines 54..61
    app/controllers/type_materials_controller.rb on lines 58..65

    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 44.

    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 4 locations. Consider refactoring.
    Open

      def api_index
        @images = Queries::Image::Filter.new(params.merge!(api: true)).all
          .where(project_id: sessions_current_project_id)
          .page(params[:page]).per(params[:per])
        render '/images/api/v1/index'
    Severity: Minor
    Found in app/controllers/images_controller.rb and 3 other locations - About 20 mins to fix
    app/controllers/controlled_vocabulary_terms_controller.rb on lines 133..138
    app/controllers/data_attributes_controller.rb on lines 46..51
    app/controllers/observation_matrices_controller.rb on lines 239..244

    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 27.

    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