django/django

View on GitHub
django/middleware/csrf.py

Summary

Maintainability
C
1 day
Test Coverage

File csrf.py has 340 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Cross Site Request Forgery Middleware.

This module provides a middleware that implements protection
against request forgeries from other sites.
Severity: Minor
Found in django/middleware/csrf.py - About 4 hrs to fix

    Function _check_referer has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def _check_referer(self, request):
            referer = request.META.get("HTTP_REFERER")
            if referer is None:
                raise RejectRequest(REASON_NO_REFERER)
    
    
    Severity: Minor
    Found in django/middleware/csrf.py - About 1 hr 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 process_view has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def process_view(self, request, callback, callback_args, callback_kwargs):
            if getattr(request, "csrf_processing_done", False):
                return None
    
            # Wait until request.META["CSRF_COOKIE"] has been manipulated before
    Severity: Minor
    Found in django/middleware/csrf.py - About 1 hr 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 _check_token has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def _check_token(self, request):
            # Access csrf_secret via self._get_secret() as rotate_token() may have
            # been called by an authentication middleware during the
            # process_request() phase.
            try:
    Severity: Minor
    Found in django/middleware/csrf.py - About 1 hr 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_secret has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def _get_secret(self, request):
            """
            Return the CSRF secret originally associated with the request, or None
            if it didn't have one.
    
    
    Severity: Minor
    Found in django/middleware/csrf.py - About 55 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 self._reject(
    Severity: Major
    Found in django/middleware/csrf.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                      return self._reject(request, exc.reason)
      Severity: Major
      Found in django/middleware/csrf.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return self._accept(request)
        Severity: Major
        Found in django/middleware/csrf.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return self._reject(request, exc.reason)
          Severity: Major
          Found in django/middleware/csrf.py - About 30 mins to fix

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

                def _origin_verified(self, request):
                    request_origin = request.META["HTTP_ORIGIN"]
                    try:
                        good_host = request.get_host()
                    except DisallowedHost:
            Severity: Minor
            Found in django/middleware/csrf.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