Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lint to validate options #3107

Merged
merged 10 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/semgrep-rule-lints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
--config yaml/semgrep/metadata-likelihood-incorrect-value.yaml \
--config yaml/semgrep/metadata-impact-incorrect-value.yaml \
--config yaml/semgrep/metadata-subcategory-incorrect-value.yaml \
--config yaml/semgrep/metadata-incorrect-option.yaml \
--config yaml/semgrep/metadata-technology.yaml \
--config yaml/semgrep/metadata-category.yaml \
--config yaml/semgrep/multi-line-message.yaml \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
rules:
- id: handler-assignment-from-multiple-sources
options:
taint_unified_mvars: true
metadata:
cwe:
- 'CWE-289: Authentication Bypass by Alternate Name'
Expand Down
2 changes: 1 addition & 1 deletion swift/lang/storage/sensitive-storage-userdefaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rules:
languages:
- swift
options:
taint_propagation: true
symbolic_propagation: true
patterns:
- pattern-either:
- patterns:
Expand Down
37 changes: 37 additions & 0 deletions yaml/semgrep/metadata-incorrect-option.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
rules:
- id: swift-user-defaults
message: Potentially sensitive data was observed to be stored in UserDefaults,
which is not adequate protection of sensitive information. For data of a
sensitive nature, applications should leverage the Keychain.
severity: WARNING
metadata:
likelihood: LOW
impact: HIGH
confidence: MEDIUM
category: security
cwe:
- "CWE-311: Missing Encryption of Sensitive Data"
masvs:
- "MASVS-STORAGE-1: The app securely stores sensitive data"
owasp:
- A03:2017 - Sensitive Data Exposure
- A04:2021 - Insecure Design
references:
- https://developer.apple.com/library/archive/documentation/Security/Conceptual/SecureCodingGuide/Articles/ValidatingInput.html
- https://mas.owasp.org/MASVS/controls/MASVS-STORAGE-1/
subcategory:
- vuln
technology:
- ios
- macos
license: Commons Clause License Condition v1.0[LGPL-2.1-only]
vulnerability_class:
- Cryptographic Issues
languages:
- swift
options:
# ruleid: metadata-incorrect-option
taint_propagation: true
# ruleid: metadata-incorrect-option
value: 2
patterns:
25 changes: 25 additions & 0 deletions yaml/semgrep/metadata-incorrect-option.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
rules:
- id: metadata-incorrect-option
message: >-
It looks like $KEY is not in the default list of expected options, if this is a new key update this rule
languages:
- yaml
severity: INFO
metadata:
references:
- https://semgrep.dev/docs/contributing/contributing-to-semgrep-rules-repository
category: correctness
technology:
- semgrep
patterns:
- pattern-inside: |
rules: ...
- pattern-inside: |
options:
$A
- focus-metavariable: $A
- pattern: |
$KEY: $VALUE
- metavariable-regex:
metavariable: $KEY
regex: (?!options|constant_propagation|symbolic_propagation|taint_unify_mvars|taint_assume_safe_functions|taint_assume_safe_indexes|taint_assume_safe_comparisons|taint_assume_safe_booleans|taint_assume_safe_numbers|ac_matching|commutative_boolop|flddef_assign|arrow_is_function|let_is_var|go_deeper_expr|go_deeper_stmt|implicit_deep_exprstmt|implicit_ellipsis|xml_singleton_loose_matching|xml_attrs_implicit_ellipsis|xml_children_ordered|generic_engine|generic_multiline|generic_braces|generic_extra_braces|generic_extra_word_characters|generic_caseless|generic_ellipsis_max_span|generic_comment_style|interfile|generic_engine)