python.lang.security.audit.hardcoded-password-default-argument.hardcoded-password-default-argument

Community Favorite
profile photo of semgrepsemgrep
Author
47,065
Download Count*

Hardcoded password is used as a default argument to '$FUNC'. This could be dangerous if a real password is not supplied.

Run Locally

Run in CI

Defintion

rules:
  - id: hardcoded-password-default-argument
    message: Hardcoded password is used as a default argument to '$FUNC'. This could
      be dangerous if a real password is not supplied.
    languages:
      - python
    severity: WARNING
    patterns:
      - pattern: |
          def $FUNC(..., password="...", ...):
            ...
      - pattern-not: |
          def $FUNC(..., password="", ...):
            ...
    metadata:
      cwe:
        - "CWE-798: Use of Hard-coded Credentials"
      category: security
      technology:
        - python
      owasp:
        - A07:2021 - Identification and Authentication Failures
      references:
        - https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures
      cwe2022-top25: true
      cwe2021-top25: true
      subcategory:
        - audit
      likelihood: LOW
      impact: MEDIUM
      confidence: LOW
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]
      vulnerability_class:
        - Hard-coded Secrets

Examples

hardcoded-password-default-argument.py

# ok:hardcoded-password-default-argument
password = "this-is-probably-a-test"

def say_something(something):
    print(something)

# ok:hardcoded-password-default-argument
say_something(password)

# ok:hardcoded-password-default-argument
def say_something_else(something_else="something else"):
    print(something_else)

# ruleid:hardcoded-password-default-argument
def whoops(password="this-could-be-bad"):
    print(password)

# ok:hardcoded-password-default-argument
def ok(password=None):
    print(password)

# ok:hardcoded-password-default-argument
def ok(password=""):
    print(password)