bcoles/ssrf_proxy

View on GitHub
lib/ssrf_proxy/http.rb

Summary

Maintainability
F
2 wks
Test Coverage

Method send_uri has a Cognitive Complexity of 155 (exceeds 5 allowed). Consider refactoring.
Open

    def send_uri(uri, method: 'GET', headers: {}, body: '')
      uri = uri.to_s
      body = body.to_s
      headers = {} unless headers.is_a?(Hash)

Severity: Minor
Found in lib/ssrf_proxy/http.rb - About 3 days 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

File http.rb has 974 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module SSRFProxy
  #
  # SSRFProxy::HTTP object takes information required to connect
  # to a HTTP(S) server vulnerable to Server-Side Request Forgery
  # (SSRF) and issue arbitrary HTTP requests via the vulnerable
Severity: Major
Found in lib/ssrf_proxy/http.rb - About 2 days to fix

    Method guess_status has a Cognitive Complexity of 84 (exceeds 5 allowed). Consider refactoring.
    Open

        def guess_status(response)
          result = {}
          # response status code returned by php-simple-proxy and php-json-proxy
          if response =~ /"status":{"http_code":([\d]+)}/
            result['code'] = $1
    Severity: Minor
    Found in lib/ssrf_proxy/http.rb - About 1 day 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 send_uri has 318 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def send_uri(uri, method: 'GET', headers: {}, body: '')
          uri = uri.to_s
          body = body.to_s
          headers = {} unless headers.is_a?(Hash)
    
    
    Severity: Major
    Found in lib/ssrf_proxy/http.rb - About 1 day to fix

      Method guess_status has 208 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def guess_status(response)
            result = {}
            # response status code returned by php-simple-proxy and php-json-proxy
            if response =~ /"status":{"http_code":([\d]+)}/
              result['code'] = $1
      Severity: Major
      Found in lib/ssrf_proxy/http.rb - About 1 day to fix

        Method initialize has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
        Open

            def initialize(url: nil,
                           file: nil,
                           proxy: nil,
                           ssl: false,
                           method: 'GET',
        Severity: Minor
        Found in lib/ssrf_proxy/http.rb - About 6 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 initialize has 149 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def initialize(url: nil,
                           file: nil,
                           proxy: nil,
                           ssl: false,
                           method: 'GET',
        Severity: Major
        Found in lib/ssrf_proxy/http.rb - About 5 hrs to fix

          Method send_http_request has 83 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def send_http_request(url, method, headers, body)
                # use upstream proxy
                if @proxy.nil?
                  http = Net::HTTP::Proxy(nil).new(
                    @url.host,
          Severity: Major
          Found in lib/ssrf_proxy/http.rb - About 3 hrs to fix

            Method send_http_request has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
            Open

                def send_http_request(url, method, headers, body)
                  # use upstream proxy
                  if @proxy.nil?
                    http = Net::HTTP::Proxy(nil).new(
                      @url.host,
            Severity: Minor
            Found in lib/ssrf_proxy/http.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 run_rules has 44 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def run_rules(url, rules)
                  str = url.to_s
                  return str if rules.nil?
                  rules.each do |rule|
                    case rule
            Severity: Minor
            Found in lib/ssrf_proxy/http.rb - About 1 hr to fix

              Method parse_http_request has 40 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def parse_http_request(request)
                    # parse method
                    if request.to_s !~ /\A(GET|HEAD|DELETE|POST|PUT|OPTIONS) /
                      logger.warn('HTTP request method is not supported')
                      raise SSRFProxy::HTTP::Error::InvalidClientRequest,
              Severity: Minor
              Found in lib/ssrf_proxy/http.rb - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                      elsif response =~ /HTTPError: HTTP Error \d+/
                        if response =~ /HTTPError: HTTP Error 400: Bad Request/
                          result['code'] = 400
                          result['message'] = 'Bad Request'
                        elsif response =~ /HTTPError: HTTP Error 401: Unauthorized/
                Severity: Major
                Found in lib/ssrf_proxy/http.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                          if response =~ /\[Errno -2\] Name or service not known/
                            result['code'] = 502
                            result['message'] = 'Bad Gateway'
                          elsif response =~ /\[Errno 101\] Network is unreachable/
                            result['code'] = 502
                  Severity: Major
                  Found in lib/ssrf_proxy/http.rb - About 45 mins to fix

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

                        def parse_http_request(request)
                          # parse method
                          if request.to_s !~ /\A(GET|HEAD|DELETE|POST|PUT|OPTIONS) /
                            logger.warn('HTTP request method is not supported')
                            raise SSRFProxy::HTTP::Error::InvalidClientRequest,
                    Severity: Minor
                    Found in lib/ssrf_proxy/http.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

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

                        def run_rules(url, rules)
                          str = url.to_s
                          return str if rules.nil?
                          rules.each do |rule|
                            case rule
                    Severity: Minor
                    Found in lib/ssrf_proxy/http.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

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

                        def encode_ip(url, mode)
                          return if url.nil?
                          new_host = nil
                          host = URI.parse(url.to_s.split('?').first).host.to_s
                          begin
                    Severity: Minor
                    Found in lib/ssrf_proxy/http.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

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

                            if response =~ /HTTPError: HTTP Error 400: Bad Request/
                              result['code'] = 400
                              result['message'] = 'Bad Request'
                            elsif response =~ /HTTPError: HTTP Error 401: Unauthorized/
                              result['code'] = 401
                    Severity: Major
                    Found in lib/ssrf_proxy/http.rb and 1 other location - About 4 hrs to fix
                    lib/ssrf_proxy/http.rb on lines 1224..1257

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

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

                            elsif response =~ /\[Errno 101\] Network is unreachable/
                              result['code'] = 502
                              result['message'] = 'Bad Gateway'
                            elsif response =~ /\[Errno 104\] Connection reset by peer/
                              result['code'] = 502
                    Severity: Major
                    Found in lib/ssrf_proxy/http.rb and 1 other location - About 4 hrs to fix
                    lib/ssrf_proxy/http.rb on lines 1260..1293

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

                    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