Spaces:
Paused
Paused
Create rules/semgrep-ruleset-v1.yaml
Browse files- rules/semgrep-ruleset-v1.yaml +106 -0
rules/semgrep-ruleset-v1.yaml
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# rules/semgrep-ruleset-v1.yaml
|
| 2 |
+
# Semgrep Ruleset v1 – Flask + FastAPI + Secrets + OWASP Mapping
|
| 3 |
+
|
| 4 |
+
rules:
|
| 5 |
+
# -------------------------------
|
| 6 |
+
# A03:2021 – Injection (Command Injection)
|
| 7 |
+
# -------------------------------
|
| 8 |
+
- id: python.command-injection
|
| 9 |
+
languages: [python]
|
| 10 |
+
mode: taint
|
| 11 |
+
severity: ERROR
|
| 12 |
+
message: Untrusted input flows into command execution.
|
| 13 |
+
|
| 14 |
+
metadata:
|
| 15 |
+
owasp:
|
| 16 |
+
- A03:2021-Injection
|
| 17 |
+
cwe:
|
| 18 |
+
- CWE-78
|
| 19 |
+
category: command-injection
|
| 20 |
+
autofix: false
|
| 21 |
+
|
| 22 |
+
pattern-sources:
|
| 23 |
+
- pattern: flask.request.args[$X]
|
| 24 |
+
- pattern: flask.request.json[$X]
|
| 25 |
+
- pattern: fastapi.params.Query($X)
|
| 26 |
+
- pattern: fastapi.params.Body($X)
|
| 27 |
+
- pattern: sys.argv[$X]
|
| 28 |
+
|
| 29 |
+
pattern-sinks:
|
| 30 |
+
- pattern: subprocess.run($CMD, shell=True)
|
| 31 |
+
- pattern: subprocess.Popen($CMD, shell=True)
|
| 32 |
+
- pattern: os.system($CMD)
|
| 33 |
+
|
| 34 |
+
pattern-sanitizers:
|
| 35 |
+
- pattern: shlex.quote($X)
|
| 36 |
+
|
| 37 |
+
# -------------------------------
|
| 38 |
+
# A08:2021 – Software and Data Integrity Failures
|
| 39 |
+
# -------------------------------
|
| 40 |
+
- id: python.unsafe-deserialization
|
| 41 |
+
languages: [python]
|
| 42 |
+
mode: taint
|
| 43 |
+
severity: ERROR
|
| 44 |
+
message: Untrusted input reaches unsafe deserialization.
|
| 45 |
+
|
| 46 |
+
metadata:
|
| 47 |
+
owasp:
|
| 48 |
+
- A08:2021-Software_and_Data_Integrity_Failures
|
| 49 |
+
cwe:
|
| 50 |
+
- CWE-502
|
| 51 |
+
category: deserialization
|
| 52 |
+
|
| 53 |
+
pattern-sources:
|
| 54 |
+
- pattern: flask.request.data
|
| 55 |
+
- pattern: fastapi.params.Body($X)
|
| 56 |
+
- pattern: open($F).read()
|
| 57 |
+
|
| 58 |
+
pattern-sinks:
|
| 59 |
+
- pattern: pickle.loads($X)
|
| 60 |
+
- pattern: yaml.load($X)
|
| 61 |
+
|
| 62 |
+
pattern-sanitizers:
|
| 63 |
+
- pattern: yaml.safe_load($X)
|
| 64 |
+
|
| 65 |
+
# -------------------------------
|
| 66 |
+
# A05:2021 – Security Misconfiguration
|
| 67 |
+
# -------------------------------
|
| 68 |
+
- id: python.requests-without-timeout
|
| 69 |
+
languages: [python]
|
| 70 |
+
severity: WARNING
|
| 71 |
+
message: HTTP request without timeout can cause denial of service.
|
| 72 |
+
|
| 73 |
+
metadata:
|
| 74 |
+
owasp:
|
| 75 |
+
- A05:2021-Security_Misconfiguration
|
| 76 |
+
cwe:
|
| 77 |
+
- CWE-400
|
| 78 |
+
category: availability
|
| 79 |
+
|
| 80 |
+
pattern: requests.$METHOD(...)
|
| 81 |
+
metavariable-regex:
|
| 82 |
+
metavariable: $METHOD
|
| 83 |
+
regex: (get|post|put|delete|patch)
|
| 84 |
+
pattern-not: requests.$METHOD(..., timeout=...)
|
| 85 |
+
|
| 86 |
+
# -------------------------------
|
| 87 |
+
# A02:2021 – Cryptographic Failures
|
| 88 |
+
# -------------------------------
|
| 89 |
+
- id: python.hardcoded-secrets
|
| 90 |
+
languages: [python]
|
| 91 |
+
severity: ERROR
|
| 92 |
+
message: Potential hardcoded secret detected.
|
| 93 |
+
|
| 94 |
+
metadata:
|
| 95 |
+
owasp:
|
| 96 |
+
- A02:2021-Cryptographic_Failures
|
| 97 |
+
cwe:
|
| 98 |
+
- CWE-798
|
| 99 |
+
category: secrets
|
| 100 |
+
|
| 101 |
+
patterns:
|
| 102 |
+
- pattern: $X = "sk_live_..."
|
| 103 |
+
- pattern: $X = "hf_..."
|
| 104 |
+
- pattern: $X = "AKIA..."
|
| 105 |
+
- pattern: $X = "AIza..."
|
| 106 |
+
``
|