73 lines
3.5 KiB
YAML
73 lines
3.5 KiB
YAML
# Prüfwerk's own semgrep rules for Swift (iOS apps; Objective-C is in
|
|
# cra_semgrep_objc.yaml). Written for Prüfwerk, not
|
|
# adapted from any third-party rule set (the Semgrep registry rules may not be
|
|
# used for a service offered to others). mobsfscan already covers ATS, the
|
|
# Keychain accessibility, weak hashes and ciphers, TLS and web views; these
|
|
# rules cover what it does not.
|
|
# Same conventions as cra_semgrep.yaml: each rule id is `cra-ai-<n>-<slug>`,
|
|
# keyed back to its control via the `control-map` LUT, with its CWE and
|
|
# control in the metadata. Keep patterns tight: a false positive that the
|
|
# judge refutes marks the whole finding a false positive.
|
|
# Test cases: cra_semgrep_swift.swift (`semgrep --test compliance-agent/rules`).
|
|
rules:
|
|
# --- cra-ai-14: data at rest -------------------------------------------------
|
|
- id: cra-ai-14-swift-secret-in-userdefaults
|
|
languages: [swift]
|
|
severity: WARNING
|
|
message: A password, token or key is stored in UserDefaults, an unencrypted plist in the app container that backups and device extraction read (CWE-312). Store it in the Keychain (kSecClassGenericPassword, with a ThisDeviceOnly accessibility).
|
|
metadata:
|
|
cwe: ["CWE-312: Cleartext Storage of Sensitive Information"]
|
|
control: cra-ai-14
|
|
patterns:
|
|
- pattern-either:
|
|
# The key names the secret ...
|
|
- patterns:
|
|
- pattern-either: &userdefaults-set
|
|
- pattern: 'UserDefaults.standard.set($V, forKey: $K)'
|
|
- pattern: 'UserDefaults(suiteName: $S)?.set($V, forKey: $K)'
|
|
- pattern: 'UserDefaults(suiteName: $S)!.set($V, forKey: $K)'
|
|
- patterns:
|
|
- pattern-either:
|
|
- pattern-inside: |
|
|
let $D = UserDefaults.standard
|
|
...
|
|
- pattern-inside: |
|
|
let $D = UserDefaults(suiteName: $S)
|
|
...
|
|
- pattern: '$D.set($V, forKey: $K)'
|
|
- metavariable-regex:
|
|
metavariable: $K
|
|
regex: &secret (?i).*(passw|passcode|token|secret|api_?key|credential|private_?key|session_?id)
|
|
# ... or the stored value does.
|
|
- patterns:
|
|
- pattern-either: *userdefaults-set
|
|
- metavariable-regex:
|
|
metavariable: $V
|
|
regex: *secret
|
|
# A flag or a count is not the secret, even if its key names one.
|
|
- metavariable-regex:
|
|
metavariable: $V
|
|
regex: ^(?!(true|false|nil|-?\d+(\.\d+)?|Date\(\))$)
|
|
- id: cra-ai-14-swift-secret-in-appstorage
|
|
languages: [swift]
|
|
severity: WARNING
|
|
message: A password, token or key is kept in @AppStorage, which stores it in UserDefaults, an unencrypted plist in the app container that backups and device extraction read (CWE-312). Store it in the Keychain instead.
|
|
metadata:
|
|
cwe: ["CWE-312: Cleartext Storage of Sensitive Information"]
|
|
control: cra-ai-14
|
|
pattern-either:
|
|
- patterns:
|
|
- pattern-either: &appstorage
|
|
- pattern: |
|
|
@AppStorage($K) var $X: $T = $E
|
|
- pattern: |
|
|
@AppStorage($K) var $X = $E
|
|
- metavariable-regex:
|
|
metavariable: $K
|
|
regex: *secret
|
|
- patterns:
|
|
- pattern-either: *appstorage
|
|
- metavariable-regex:
|
|
metavariable: $X
|
|
regex: *secret
|