trailofbits.yaml.ansible.apt-key-unencrypted-url.apt-key-unencrypted-url

profile photo of trailofbitstrailofbits
Author
unknown
Download Count*

Found apt key download with unencrypted URL (e.g. HTTP, FTP, etc.)

Run Locally

Run in CI

Defintion

rules:
  - id: apt-key-unencrypted-url
    message: Found apt key download with unencrypted URL (e.g. HTTP, FTP, etc.)
    languages:
      - yaml
    severity: WARNING
    metadata:
      category: security
      cwe: "CWE-319: Cleartext Transmission of Sensitive Information"
      subcategory:
        - audit
      technology:
        - ansible
        - apt
      confidence: HIGH
      likelihood: HIGH
      impact: HIGH
      references:
        - https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_key_module.html#parameter-url
      license: AGPL-3.0 license
      vulnerability_class:
        - Mishandled Sensitive Information
    patterns:
      - pattern-inside: |
          $APTKEY:
            ...
      - metavariable-pattern:
          metavariable: $APTKEY
          pattern-either:
            - pattern: apt_key
            - pattern: ansible.builtin.apt_key
      - pattern: "$KEY: '$VALUE'"
      - metavariable-pattern:
          metavariable: $KEY
          pattern-either:
            - pattern: url
      - metavariable-regex:
          metavariable: $VALUE
          regex: (?i)^(http|ftp)://.*

Examples

apt-key-unencrypted-url.test.yaml

---
- name: Semgrep tests
  hosts: all
  tasks:
    - name: Positive test
      ansible.builtin.apt_key:
        # ruleid: apt-key-unencrypted-url
        url: http://example.com/example-key.asc
        state: present
    - name: Negative test
      ansible.builtin.apt_key:
        # ok: apt-key-unencrypted-url
        url: https://example.com/example-key.asc
        state: present