failmap/admin

View on GitHub
websecmap/scanners/scanner/http.py

Summary

Maintainability
D
2 days
Test Coverage

File http.py has 602 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Scans for HTTP sites.

If there is a HTTP site on port 80, but there is not a TLS equivalent: give points.
Every http site that does want to instantly upgrade gets 10 points? (how to determine?)
Severity: Major
Found in websecmap/scanners/scanner/http.py - About 1 day to fix

    Function can_connect has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def can_connect(self, protocol: str, url: str, port: int, ip_version: int) -> bool:
        """
        Searches for both IPv4 and IPv6 IP addresses / types.
    
        The algorithm is very simple: if there is a http status code, or "a response" there is an
    Severity: Minor
    Found in websecmap/scanners/scanner/http.py - 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

    Cyclomatic complexity is too high in function can_connect. (12)
    Open

    @app.task(queue="4and6", rate_limit="120/s", bind=True)
    def can_connect(self, protocol: str, url: str, port: int, ip_version: int) -> bool:
        """
        Searches for both IPv4 and IPv6 IP addresses / types.
    
    
    Severity: Minor
    Found in websecmap/scanners/scanner/http.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in function get_ipv6. (6)
    Open

    def get_ipv6(url: str):
        # https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
        ipv6 = ""
    
        try:
    Severity: Minor
    Found in websecmap/scanners/scanner/http.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Function connect_result has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def connect_result(result, protocol: str, url_id: int, port: int, ip_version: int, origin: str = ""):
    Severity: Minor
    Found in websecmap/scanners/scanner/http.py - About 45 mins to fix

      Function can_connect has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def can_connect(self, protocol: str, url: str, port: int, ip_version: int) -> bool:
      Severity: Minor
      Found in websecmap/scanners/scanner/http.py - About 35 mins to fix

        Function kill_endpoint has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def kill_endpoint(protocol: str, url_id: int, port: int, ip_version: int, origin: str = ""):
        Severity: Minor
        Found in websecmap/scanners/scanner/http.py - About 35 mins to fix

          Function save_endpoint has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def save_endpoint(protocol: str, url_id: int, port: int, ip_version: int, origin: str = ""):
          Severity: Minor
          Found in websecmap/scanners/scanner/http.py - About 35 mins to fix

            Function redirects_to_safety has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            def redirects_to_safety(url: str):
                """
                Also includes the ip-version of the endpoint. Implies that the endpoint resolves.
                Any safety over any network is accepted now, both A and AAAA records.
            
            
            Severity: Minor
            Found in websecmap/scanners/scanner/http.py - 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

            Function get_ipv6 has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            def get_ipv6(url: str):
                # https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
                ipv6 = ""
            
                try:
            Severity: Minor
            Found in websecmap/scanners/scanner/http.py - 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

            Function store_url_ips has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            def store_url_ips(url: int, ips):
                """
                Todo: method should be stored in manager
            
                Be sure to give all ip's that are currently active in one call. Mix IPv4 and IPv6.
            Severity: Minor
            Found in websecmap/scanners/scanner/http.py - 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

            Avoid too many return statements within this function.
            Open

                            return True
            Severity: Major
            Found in websecmap/scanners/scanner/http.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return True
              Severity: Major
              Found in websecmap/scanners/scanner/http.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                    return True
                Severity: Major
                Found in websecmap/scanners/scanner/http.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return False
                  Severity: Major
                  Found in websecmap/scanners/scanner/http.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return True
                    Severity: Major
                    Found in websecmap/scanners/scanner/http.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return False
                      Severity: Major
                      Found in websecmap/scanners/scanner/http.py - About 30 mins to fix

                        Function check_network has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                        def check_network(code_location=""):
                            """
                            Used to see if a worker can do IPv6. Will trigger an exception when no ipv4 or ipv6 is available,
                            which is logged in sentry and other logs.
                        
                        
                        Severity: Minor
                        Found in websecmap/scanners/scanner/http.py - 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

                        Function compose_discover_task has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                        def compose_discover_task(urls: List[Url]):
                            tasks = []
                        
                            for ip_version in [4, 6]:
                                for port in PREFERRED_PORT_ORDER:
                        Severity: Minor
                        Found in websecmap/scanners/scanner/http.py - 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

                        There are no issues that match your filters.

                        Category
                        Status