SpeciesFileGroup/taxonworks

View on GitHub
lib/utilities/files.rb

Summary

Maintainability
A
35 mins
Test Coverage

Possible command injection
Open

      puts `wc -l #{f}`
Severity: Minor
Found in lib/utilities/files.rb by brakeman

Injection is #1 on the 2010 OWASP Top Ten web security risks. Command injection occurs when shell commands unsafely include user-manipulatable values.

There are many ways to run commands in Ruby:

`ls #{params[:file]}`

system("ls #{params[:dir]}")

exec("md5sum #{params[:input]}")

Brakeman will warn on any method like these that uses user input or unsafely interpolates variables.

See the Ruby Security Guide for details.

Possible command injection
Open

    mimetype = `file -b "#{file.path}"`.gsub(/\n/, '')
Severity: Minor
Found in lib/utilities/files.rb by brakeman

Injection is #1 on the 2010 OWASP Top Ten web security risks. Command injection occurs when shell commands unsafely include user-manipulatable values.

There are many ways to run commands in Ruby:

`ls #{params[:file]}`

system("ls #{params[:dir]}")

exec("md5sum #{params[:input]}")

Brakeman will warn on any method like these that uses user input or unsafely interpolates variables.

See the Ruby Security Guide for details.

Method replace has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def self.replace(original_file, new_file)
    return false unless File.exist?(original_file) && File.exist?(new_file)
    fo = original_file
    ft = fo + '.tmp'

Severity: Minor
Found in lib/utilities/files.rb - About 35 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

Do not write to stdout. Use Rails's logger if you want to log.
Open

    puts 'Lines per file: '
Severity: Minor
Found in lib/utilities/files.rb by rubocop

This cop checks for the use of output calls like puts and print

Example:

# bad
puts 'A debug message'
pp 'A debug message'
print 'A debug message'

# good
Rails.logger.debug 'A debug message'

Do not write to stdout. Use Rails's logger if you want to log.
Open

      puts `wc -l #{f}`
Severity: Minor
Found in lib/utilities/files.rb by rubocop

This cop checks for the use of output calls like puts and print

Example:

# bad
puts 'A debug message'
pp 'A debug message'
print 'A debug message'

# good
Rails.logger.debug 'A debug message'

There are no issues that match your filters.

Category
Status