yaml.semgrep.duplicate-pattern.duplicate-pattern

profile photo of semgrepsemgrep
Author
672
Download Count*

Two identical pattern clauses were detected. This will cause Semgrep to run the same pattern twice. Remove one of the duplicate pattern clauses.

Run Locally

Run in CI

Defintion

rules:
  - id: duplicate-pattern
    message: Two identical pattern clauses were detected. This will cause Semgrep to
      run the same pattern twice. Remove one of the duplicate pattern clauses.
    severity: ERROR
    languages:
      - yaml
    patterns:
      - pattern-inside: "rules: [..., $RULE, ...]"
      - pattern-inside: |
          - pattern: $X
          ...
          - pattern: $X
          ...
      - pattern: |
          pattern: $X
    metadata:
      category: correctness
      technology:
        - semgrep
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]

Examples

duplicate-pattern.test.yaml

rules:
  - id: unchecked-subprocess-call
    patterns:
      - pattern-either:
          # ruleid: duplicate-pattern
          - pattern: |
              subprocess.call(...)
            # ruleid: duplicate-pattern
          - pattern: |
              subprocess.call(...)
      - pattern-not-inside: |
          $S = subprocess.call(...)
      - pattern-not-inside: |
          subprocess.call(...) == $X
    message: >-
      This is not checking the return value of this subprocess call; if it fails no exception will be raised. Consider subprocess.check_call() instead
    languages: [python]
    severity: WARNING
    fix: subprocess.check_call(...)