ComplianceAsCode/content

View on GitHub

Showing 1,039 of 1,039 total issues

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

def fix_empty_identifier(file_contents, yaml_contents):
    section = 'identifiers'

    empty_identifiers = []
    if yaml_contents[section] is not None:
Severity: Major
Found in utils/fix_rules.py and 1 other location - About 5 hrs to fix
utils/fix_rules.py on lines 380..390

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

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

Rule has 37 functions (exceeds 20 allowed). Consider refactoring.
Open

class Rule(XCCDFEntity, Templatable):
    """Represents XCCDF Rule
    """
    KEYS = dict(
        description=lambda: "",
Severity: Minor
Found in ssg/build_yaml.py - About 4 hrs to fix

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

                if options.missing_cces and profile_stats['missing_cces']:
                    print("***Rules of '%s' " % profile + "profile missing " +
                          "CCE identifier: %d of %d [%d%% complete]" %
                          (rules_count - impl_cces_count, rules_count,
                           profile_stats['assigned_cces_pct']))
    Severity: Major
    Found in ssg/build_profile.py and 2 other locations - About 4 hrs to fix
    ssg/build_profile.py on lines 553..559
    ssg/build_profile.py on lines 561..567

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

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

                if options.missing_sces and profile_stats['missing_sces']:
                    print("*** Rules of '%s' " % profile + "profile missing " +
                          "SCE: %d of %d [%d%% complete]" %
                          (rules_count - impl_sces_count, rules_count,
                           profile_stats['implemented_sces_pct']))
    Severity: Major
    Found in ssg/build_profile.py and 2 other locations - About 4 hrs to fix
    ssg/build_profile.py on lines 553..559
    ssg/build_profile.py on lines 705..711

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

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

                if options.missing_ovals and profile_stats['missing_ovals']:
                    print("*** Rules of '%s' " % profile + "profile missing " +
                          "OVAL: %d of %d [%d%% complete]" %
                          (rules_count - impl_ovals_count, rules_count,
                           profile_stats['implemented_ovals_pct']))
    Severity: Major
    Found in ssg/build_profile.py and 2 other locations - About 4 hrs to fix
    ssg/build_profile.py on lines 561..567
    ssg/build_profile.py on lines 705..711

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

    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

    File data.py has 502 lines of code (exceeds 400 allowed). Consider refactoring.
    Open

    import string
    
    HEADERS = [
        'IA Control', 'CCI', 'SRGID', 'STIGID', 'SRG Requirement', 'Requirement',
        'SRG VulDiscussion', 'Vul Discussion', 'Status', 'SRG Check', 'Check', 'SRG Fix',
    Severity: Major
    Found in utils/srg_export/data.py - About 4 hrs to fix

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

      if __name__ == "__main__":
          parser = argparse.ArgumentParser()
          parser.add_argument(
              "ssg_root",
              help="Path to the root directory of scap-security-guide")
      Severity: Major
      Found in utils/gen_html_guides_index.py and 1 other location - About 4 hrs to fix
      utils/gen_rendered_policies_index.py on lines 69..79

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

      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

      class AND(DualBase):
          """
          Boolean AND operation, taking 2 or more arguments.
      
          It can also be created by using "&" between two boolean expressions.
      Severity: Major
      Found in ssg/ext/boolean/boolean.py and 1 other location - About 4 hrs to fix
      ssg/ext/boolean/boolean.py on lines 1483..1506

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

      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

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

      if __name__ == "__main__":
          parser = argparse.ArgumentParser()
          parser.add_argument(
              "ssg_root",
              help="Path to the root directory of scap-security-guide")
      Severity: Major
      Found in utils/gen_rendered_policies_index.py and 1 other location - About 4 hrs to fix
      utils/gen_html_guides_index.py on lines 45..55

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

      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

      class OR(DualBase):
          """
          Boolean OR operation, taking 2 or more arguments
      
          It can also be created by using "|" between two boolean expressions.
      Severity: Major
      Found in ssg/ext/boolean/boolean.py and 1 other location - About 4 hrs to fix
      ssg/ext/boolean/boolean.py on lines 1458..1480

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

      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

      Cyclomatic complexity is too high in method simplify. (25)
      Open

          def simplify(self, sort=True):
              """
              Return a new simplified expression in canonical form from this
              expression.
      
      
      Severity: Minor
      Found in ssg/ext/boolean/boolean.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

      File templates.py has 490 lines of code (exceeds 400 allowed). Consider refactoring.
      Open

      """
      Common functions for processing Templates in SSG
      """
      
      from __future__ import absolute_import
      Severity: Minor
      Found in ssg/templates.py - About 4 hrs to fix

        File common.py has 489 lines of code (exceeds 400 allowed). Consider refactoring.
        Open

        from __future__ import print_function
        
        import functools
        import logging
        import os
        Severity: Minor
        Found in tests/ssg_test_suite/common.py - About 4 hrs to fix

          File ansible_playbook_to_role.py has 487 lines of code (exceeds 400 allowed). Consider refactoring.
          Open

          #!/usr/bin/python3
          
          from __future__ import print_function
          
          from tempfile import mkdtemp
          Severity: Minor
          Found in utils/ansible_playbook_to_role.py - About 4 hrs to fix

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

            def has_int_reference(rule_path, rule, rule_lines):
                if 'references' in rule and rule['references'] is not None:
                    for _, value in rule['references'].items():
                        if type(value) != str:
                            return True
            Severity: Major
            Found in utils/fix_rules.py and 1 other location - About 4 hrs to fix
            utils/fix_rules.py on lines 91..96

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

            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

            def has_int_identifier(rule_path, rule, rule_lines):
                if 'identifiers' in rule and rule['identifiers'] is not None:
                    for _, value in rule['identifiers'].items():
                        if type(value) != str:
                            return True
            Severity: Major
            Found in utils/fix_rules.py and 1 other location - About 4 hrs to fix
            utils/fix_rules.py on lines 99..104

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

            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

            Cyclomatic complexity is too high in function print_report. (24)
            Open

            def print_report(current_dict: dict, baseline_dict: dict = None) -> None:
                """Print report with results of profiling to stdout"""
            
                # If the targets/outputfiles have changed between baseline and current, we are using
                # total_time_intersect to calculate delta (ratio of durations of targets) instead of total_time
            Severity: Minor
            Found in utils/build_profiler_report.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

            File test_env.py has 482 lines of code (exceeds 400 allowed). Consider refactoring.
            Open

            from __future__ import print_function
            
            import contextlib
            import json
            import logging
            Severity: Minor
            Found in tests/ssg_test_suite/test_env.py - About 4 hrs to fix

              File build_remediations.py has 480 lines of code (exceeds 400 allowed). Consider refactoring.
              Open

              from __future__ import absolute_import
              from __future__ import print_function
              
              import sys
              import os
              Severity: Minor
              Found in ssg/build_remediations.py - About 3 hrs to fix

                Function get_profile_stats has a Cognitive Complexity of 28 (exceeds 7 allowed). Consider refactoring.
                Open

                    def get_profile_stats(self, profile):
                        """Obtain statistics for the profile"""
                
                        # Holds the intermediary statistics for profile
                        profile_stats = {
                Severity: Minor
                Found in ssg/build_profile.py - About 3 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

                Severity
                Category
                Status
                Source
                Language