@zhuma4/cli 4.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/README.md +42 -0
  2. package/dist/commands/config.d.ts +3 -0
  3. package/dist/commands/config.d.ts.map +1 -0
  4. package/dist/commands/config.js +18 -0
  5. package/dist/commands/config.js.map +1 -0
  6. package/dist/commands/init.d.ts +3 -0
  7. package/dist/commands/init.d.ts.map +1 -0
  8. package/dist/commands/init.js +11 -0
  9. package/dist/commands/init.js.map +1 -0
  10. package/dist/commands/scan.d.ts +3 -0
  11. package/dist/commands/scan.d.ts.map +1 -0
  12. package/dist/commands/scan.js +96 -0
  13. package/dist/commands/scan.js.map +1 -0
  14. package/dist/commands/scan_appid.d.ts +20 -0
  15. package/dist/commands/scan_appid.d.ts.map +1 -0
  16. package/dist/commands/scan_appid.js +301 -0
  17. package/dist/commands/scan_appid.js.map +1 -0
  18. package/dist/commands/scan_manifest.d.ts +13 -0
  19. package/dist/commands/scan_manifest.d.ts.map +1 -0
  20. package/dist/commands/scan_manifest.js +103 -0
  21. package/dist/commands/scan_manifest.js.map +1 -0
  22. package/dist/engine/api-submit.d.ts +16 -0
  23. package/dist/engine/api-submit.d.ts.map +1 -0
  24. package/dist/engine/api-submit.js +66 -0
  25. package/dist/engine/api-submit.js.map +1 -0
  26. package/dist/engine/batch_scan.d.ts +36 -0
  27. package/dist/engine/batch_scan.d.ts.map +1 -0
  28. package/dist/engine/batch_scan.js +192 -0
  29. package/dist/engine/batch_scan.js.map +1 -0
  30. package/dist/engine/config.d.ts +12 -0
  31. package/dist/engine/config.d.ts.map +1 -0
  32. package/dist/engine/config.js +27 -0
  33. package/dist/engine/config.js.map +1 -0
  34. package/dist/engine/errors.d.ts +36 -0
  35. package/dist/engine/errors.d.ts.map +1 -0
  36. package/dist/engine/errors.js +99 -0
  37. package/dist/engine/errors.js.map +1 -0
  38. package/dist/engine/filter.d.ts +13 -0
  39. package/dist/engine/filter.d.ts.map +1 -0
  40. package/dist/engine/filter.js +64 -0
  41. package/dist/engine/filter.js.map +1 -0
  42. package/dist/engine/finding_classifier.d.ts +108 -0
  43. package/dist/engine/finding_classifier.d.ts.map +1 -0
  44. package/dist/engine/finding_classifier.js +440 -0
  45. package/dist/engine/finding_classifier.js.map +1 -0
  46. package/dist/engine/incremental/engine.d.ts +25 -0
  47. package/dist/engine/incremental/engine.d.ts.map +1 -0
  48. package/dist/engine/incremental/engine.js +337 -0
  49. package/dist/engine/incremental/engine.js.map +1 -0
  50. package/dist/engine/incremental/git-diff.d.ts +19 -0
  51. package/dist/engine/incremental/git-diff.d.ts.map +1 -0
  52. package/dist/engine/incremental/git-diff.js +175 -0
  53. package/dist/engine/incremental/git-diff.js.map +1 -0
  54. package/dist/engine/incremental/types.d.ts +33 -0
  55. package/dist/engine/incremental/types.d.ts.map +1 -0
  56. package/dist/engine/incremental/types.js +11 -0
  57. package/dist/engine/incremental/types.js.map +1 -0
  58. package/dist/engine/manifest_scanner.d.ts +48 -0
  59. package/dist/engine/manifest_scanner.d.ts.map +1 -0
  60. package/dist/engine/manifest_scanner.js +599 -0
  61. package/dist/engine/manifest_scanner.js.map +1 -0
  62. package/dist/engine/project.d.ts +22 -0
  63. package/dist/engine/project.d.ts.map +1 -0
  64. package/dist/engine/project.js +279 -0
  65. package/dist/engine/project.js.map +1 -0
  66. package/dist/engine/sarif.d.ts +13 -0
  67. package/dist/engine/sarif.d.ts.map +1 -0
  68. package/dist/engine/sarif.js +44 -0
  69. package/dist/engine/sarif.js.map +1 -0
  70. package/dist/engine/sca-integration.d.ts +36 -0
  71. package/dist/engine/sca-integration.d.ts.map +1 -0
  72. package/dist/engine/sca-integration.js +91 -0
  73. package/dist/engine/sca-integration.js.map +1 -0
  74. package/dist/engine/scanner.d.ts +18 -0
  75. package/dist/engine/scanner.d.ts.map +1 -0
  76. package/dist/engine/scanner.js +138 -0
  77. package/dist/engine/scanner.js.map +1 -0
  78. package/dist/index.d.ts +13 -0
  79. package/dist/index.d.ts.map +1 -0
  80. package/dist/index.js +41 -0
  81. package/dist/index.js.map +1 -0
  82. package/dist/report/render.d.ts +23 -0
  83. package/dist/report/render.d.ts.map +1 -0
  84. package/dist/report/render.js +335 -0
  85. package/dist/report/render.js.map +1 -0
  86. package/package.json +41 -0
  87. package/rules/android/mobile-cleartext-traffic.yaml +46 -0
  88. package/rules/android/mobile-component-security.yaml +107 -0
  89. package/rules/android/mobile-crypto-weakness.yaml +139 -0
  90. package/rules/android/mobile-cwe-1021-tapjacking.yaml +81 -0
  91. package/rules/android/mobile-cwe-114-dynamic-dex-loading.yaml +41 -0
  92. package/rules/android/mobile-cwe-200-clipboard-data-leak.yaml +66 -0
  93. package/rules/android/mobile-cwe-200-debug-builds.yaml +111 -0
  94. package/rules/android/mobile-cwe-200-log-sensitive-data.yaml +61 -0
  95. package/rules/android/mobile-cwe-200-webview-debugging.yaml +56 -0
  96. package/rules/android/mobile-cwe-200-webview-universal-access.yaml +30 -0
  97. package/rules/android/mobile-cwe-200-window-flags.yaml +96 -0
  98. package/rules/android/mobile-cwe-22-content-provider-openfile.yaml +73 -0
  99. package/rules/android/mobile-cwe-22-path-traversal.yaml +86 -0
  100. package/rules/android/mobile-cwe-287-biometric-weakness.yaml +102 -0
  101. package/rules/android/mobile-cwe-295-cert-pinning-missing.yaml +78 -0
  102. package/rules/android/mobile-cwe-295-webview-ssl-bypass.yaml +104 -0
  103. package/rules/android/mobile-cwe-312-cleartext-storage.yaml +109 -0
  104. package/rules/android/mobile-cwe-319-cleartext-communication.yaml +84 -0
  105. package/rules/android/mobile-cwe-321-hardcoded-crypto-keys.yaml +132 -0
  106. package/rules/android/mobile-cwe-326-short-rsa.yaml +108 -0
  107. package/rules/android/mobile-cwe-327-rc4-3des.yaml +107 -0
  108. package/rules/android/mobile-cwe-329-cbc-padding-oracle.yaml +76 -0
  109. package/rules/android/mobile-cwe-470-reflection-injection.yaml +39 -0
  110. package/rules/android/mobile-cwe-489-root-detection-weak.yaml +125 -0
  111. package/rules/android/mobile-cwe-489-stetho-debug.yaml +107 -0
  112. package/rules/android/mobile-cwe-502-insecure-deserialization.yaml +76 -0
  113. package/rules/android/mobile-cwe-552-world-readable-files.yaml +63 -0
  114. package/rules/android/mobile-cwe-749-webview-java-objects.yaml +78 -0
  115. package/rules/android/mobile-cwe-749-webview-jsbridge.yaml +57 -0
  116. package/rules/android/mobile-cwe-749-webview-loadurl-injection.yaml +80 -0
  117. package/rules/android/mobile-cwe-78-command-injection.yaml +77 -0
  118. package/rules/android/mobile-cwe-780-rsa-no-oaep.yaml +80 -0
  119. package/rules/android/mobile-cwe-79-webview-setdata.yaml +78 -0
  120. package/rules/android/mobile-cwe-79-webview-xss.yaml +65 -0
  121. package/rules/android/mobile-cwe-798-hardcoded-credentials.yaml +108 -0
  122. package/rules/android/mobile-cwe-89-sql-injection.yaml +100 -0
  123. package/rules/android/mobile-cwe-927-implicit-intent.yaml +121 -0
  124. package/rules/android/mobile-cwe-927-ipc-file-provider.yaml +102 -0
  125. package/rules/android/mobile-cwe-939-deeplink-validation.yaml +76 -0
  126. package/rules/android/mobile-sdk-google-firebase-open.yaml +117 -0
  127. package/rules/android/mobile-sdk-tencent-tpns-config-leak.yaml +131 -0
  128. package/rules/android/mobile-secrets-storage.yaml +136 -0
  129. package/rules/android/mobile-webview-security.yaml +88 -0
  130. package/rules/common/cwe-200-sensitive-data-exposure.yaml +61 -0
  131. package/rules/common/cwe-22-path-traversal.yaml +47 -0
  132. package/rules/common/cwe-295-ssl-bypass.yaml +217 -0
  133. package/rules/common/cwe-295-ssl-verification-disabled.yaml +64 -0
  134. package/rules/common/cwe-306-missing-authentication.yaml +44 -0
  135. package/rules/common/cwe-326-weak-key-size.yaml +107 -0
  136. package/rules/common/cwe-327-weak-crypto.yaml +177 -0
  137. package/rules/common/cwe-328-weak-hash.yaml +96 -0
  138. package/rules/common/cwe-329-cbc-mode.yaml +26 -0
  139. package/rules/common/cwe-352-csrf.yaml +23 -0
  140. package/rules/common/cwe-434-unrestricted-file-upload.yaml +41 -0
  141. package/rules/common/cwe-502-insecure-deserialization.yaml +44 -0
  142. package/rules/common/cwe-601-url-redirect.yaml +110 -0
  143. package/rules/common/cwe-611-xxe.yaml +70 -0
  144. package/rules/common/cwe-732-incorrect-permission.yaml +49 -0
  145. package/rules/common/cwe-770-resource-exhaustion.yaml +44 -0
  146. package/rules/common/cwe-78-os-command-injection.yaml +43 -0
  147. package/rules/common/cwe-787-out-of-bounds-write.yaml +37 -0
  148. package/rules/common/cwe-79-xss.yaml +51 -0
  149. package/rules/common/cwe-862-missing-authorization.yaml +40 -0
  150. package/rules/common/cwe-89-sqli.yaml +89 -0
  151. package/rules/common/cwe-918-ssrf.yaml +45 -0
  152. package/rules/common/cwe-94-code-injection.yaml +59 -0
  153. package/rules/common/zm-go-cwe22-path-traversal-fs.yaml +117 -0
  154. package/rules/common/zm-go-cwe22-path-traversal.yaml +103 -0
  155. package/rules/common/zm-go-cwe307-brute-force.yaml +129 -0
  156. package/rules/common/zm-go-cwe326-weak-crypto.yaml +124 -0
  157. package/rules/common/zm-go-cwe327-weak-cipher.yaml +152 -0
  158. package/rules/common/zm-go-cwe384-session-fixation.yaml +128 -0
  159. package/rules/common/zm-go-cwe502-deserialization.yaml +120 -0
  160. package/rules/common/zm-go-cwe78-command-injection.yaml +95 -0
  161. package/rules/common/zm-go-cwe79-xss.yaml +104 -0
  162. package/rules/common/zm-go-cwe798-hardcoded-creds.yaml +153 -0
  163. package/rules/common/zm-go-cwe89-sqli.yaml +89 -0
  164. package/rules/common/zm-go-cwe918-ssrf.yaml +117 -0
  165. package/rules/common/zm-java-cwe117-log-injection.yaml +83 -0
  166. package/rules/common/zm-java-cwe117-logforging.yaml +153 -0
  167. package/rules/common/zm-java-cwe200-actuator-exposure.yaml +8 -0
  168. package/rules/common/zm-java-cwe200-info-disclosure.yaml +91 -0
  169. package/rules/common/zm-java-cwe22-file-depth.yaml +135 -0
  170. package/rules/common/zm-java-cwe22-path-traversal-spring.yaml +81 -0
  171. package/rules/common/zm-java-cwe284-missing-auth-spring.yaml +131 -0
  172. package/rules/common/zm-java-cwe295-webview-ssl.yaml +123 -0
  173. package/rules/common/zm-java-cwe327-weakcrypto.yaml +197 -0
  174. package/rules/common/zm-java-cwe347-jwt.yaml +30 -0
  175. package/rules/common/zm-java-cwe352-csrf-depth.yaml +107 -0
  176. package/rules/common/zm-java-cwe352-csrf-disabled.yaml +15 -0
  177. package/rules/common/zm-java-cwe501-trust-boundary.yaml +124 -0
  178. package/rules/common/zm-java-cwe502-deserial-depth.yaml +128 -0
  179. package/rules/common/zm-java-cwe502-fastjson.yaml +137 -0
  180. package/rules/common/zm-java-cwe502-gadget.yaml +158 -0
  181. package/rules/common/zm-java-cwe502-jndi-injection.yaml +91 -0
  182. package/rules/common/zm-java-cwe502-shiro.yaml +108 -0
  183. package/rules/common/zm-java-cwe601-url-redirect-spring.yaml +85 -0
  184. package/rules/common/zm-java-cwe611-xxe-enhanced.yaml +80 -0
  185. package/rules/common/zm-java-cwe611-xxe-transformer.yaml +85 -0
  186. package/rules/common/zm-java-cwe639-idor.yaml +123 -0
  187. package/rules/common/zm-java-cwe79-xss-depth.yaml +98 -0
  188. package/rules/common/zm-java-cwe862-authz-depth.yaml +127 -0
  189. package/rules/common/zm-java-cwe915-mass-assignment.yaml +16 -0
  190. package/rules/common/zm-java-cwe917-expression-injection.yaml +120 -0
  191. package/rules/common/zm-java-cwe918-resttemplate.yaml +67 -0
  192. package/rules/common/zm-java-cwe918-ssrf-depth.yaml +103 -0
  193. package/rules/common/zm-java-cwe918-ssrf-resttemplate.yaml +77 -0
  194. package/rules/common/zm-java-cwe918-webclient.yaml +44 -0
  195. package/rules/common/zm-java-cwe94-ognl.yaml +66 -0
  196. package/rules/common/zm-java-cwe94-spel-injection.yaml +85 -0
  197. package/rules/common/zm-java-cwe94-spel.yaml +112 -0
  198. package/rules/common/zm-java-cwe94-ssti.yaml +22 -0
  199. package/rules/common/zm-java-cwe942-cors.yaml +15 -0
  200. package/rules/common/zm-js-cwe1321-prototype-pollution.yaml +61 -0
  201. package/rules/common/zm-js-cwe200-info-disclosure.yaml +95 -0
  202. package/rules/common/zm-js-cwe22-path-traversal-fs.yaml +113 -0
  203. package/rules/common/zm-js-cwe22-pathtraversal.yaml +111 -0
  204. package/rules/common/zm-js-cwe307-brute-force.yaml +136 -0
  205. package/rules/common/zm-js-cwe345-postmessage.yaml +75 -0
  206. package/rules/common/zm-js-cwe347-jwt-weak.yaml +95 -0
  207. package/rules/common/zm-js-cwe352-csrf.yaml +52 -0
  208. package/rules/common/zm-js-cwe384-session-fixation.yaml +132 -0
  209. package/rules/common/zm-js-cwe502-deserialization.yaml +119 -0
  210. package/rules/common/zm-js-cwe611-xxe.yaml +108 -0
  211. package/rules/common/zm-js-cwe639-idor.yaml +122 -0
  212. package/rules/common/zm-js-cwe693-helmet-missing.yaml +46 -0
  213. package/rules/common/zm-js-cwe78-exec.yaml +37 -0
  214. package/rules/common/zm-js-cwe78-spawn.yaml +37 -0
  215. package/rules/common/zm-js-cwe79-domxss.yaml +84 -0
  216. package/rules/common/zm-js-cwe79-react-xss.yaml +18 -0
  217. package/rules/common/zm-js-cwe79-xss-ejs.yaml +70 -0
  218. package/rules/common/zm-js-cwe89-sqli.yaml +153 -0
  219. package/rules/common/zm-js-cwe915-mass-assignment.yaml +111 -0
  220. package/rules/common/zm-js-cwe918-ssrf-fetch.yaml +134 -0
  221. package/rules/common/zm-js-cwe918-ssrf.yaml +132 -0
  222. package/rules/common/zm-js-cwe94-template-injection.yaml +130 -0
  223. package/rules/common/zm-js-cwe942-cors.yaml +49 -0
  224. package/rules/common/zm-js-cwe943-nosql-injection.yaml +52 -0
  225. package/rules/common/zm-js-cwe95-eval.yaml +59 -0
  226. package/rules/common/zm-js-cwe95-function-ctor.yaml +31 -0
  227. package/rules/common/zm-py-cwe22-path-traversal.yaml +86 -0
  228. package/rules/common/zm-py-cwe327-weak-crypto.yaml +103 -0
  229. package/rules/common/zm-py-cwe502-pickle.yaml +92 -0
  230. package/rules/common/zm-py-cwe611-xxe.yaml +100 -0
  231. package/rules/common/zm-py-cwe78-command-injection.yaml +121 -0
  232. package/rules/common/zm-py-cwe79-xss.yaml +123 -0
  233. package/rules/common/zm-py-cwe798-hardcoded-creds.yaml +86 -0
  234. package/rules/common/zm-py-cwe89-sqli.yaml +59 -0
  235. package/rules/common/zm-py-cwe918-ssrf.yaml +123 -0
  236. package/rules/common/zm-py-cwe94-ssti.yaml +87 -0
  237. package/rules/common/zm-py-cwe943-nosql-injection.yaml +123 -0
  238. package/rules/iac/ansible/zm-ansible-cwe269-privilege-escalation.yaml +63 -0
  239. package/rules/iac/ansible/zm-ansible-cwe78-command-injection.yaml +67 -0
  240. package/rules/iac/ansible/zm-ansible-cwe798-hardcoded-creds.yaml +93 -0
  241. package/rules/iac/terraform/zm-tf-cwe200-s3-bucket-public.yaml +100 -0
  242. package/rules/iac/terraform/zm-tf-cwe284-sg-wide-open.yaml +88 -0
  243. package/rules/iac/terraform/zm-tf-cwe311-iam-wildcard.yaml +83 -0
  244. package/rules/iac/terraform/zm-tf-cwe319-rds-public.yaml +72 -0
  245. package/rules/iac/terraform/zm-tf-cwe798-hardcoded-creds.yaml +102 -0
  246. package/rules/iac/zm-docker-cwe250-root-user.yaml +50 -0
  247. package/rules/iac/zm-docker-cwe400-resource-limit.yaml +92 -0
  248. package/rules/iac/zm-docker-security.yaml +104 -0
  249. package/rules/iac/zm-k8s-cwe200-service-account.yaml +83 -0
  250. package/rules/iac/zm-k8s-cwe250-privileged.yaml +56 -0
  251. package/rules/iac/zm-k8s-security.yaml +79 -0
  252. package/rules/rules_index.yaml.off +477 -0
  253. package/rules/semgrep-registry/anonymous-ldap-bind.yaml +34 -0
  254. package/rules/semgrep-registry/bad-hexa-conversion.yaml +32 -0
  255. package/rules/semgrep-registry/blowfish-insufficient-key-size.yaml +39 -0
  256. package/rules/semgrep-registry/cbc-padding-oracle.yaml +38 -0
  257. package/rules/semgrep-registry/command-injection-formatted-runtime-call.yaml +90 -0
  258. package/rules/semgrep-registry/command-injection-process-builder.yaml +148 -0
  259. package/rules/semgrep-registry/cookie-missing-httponly.yaml +38 -0
  260. package/rules/semgrep-registry/cookie-missing-secure-flag.yaml +38 -0
  261. package/rules/semgrep-registry/crlf-injection-logs.yaml +86 -0
  262. package/rules/semgrep-registry/dangerous-groovy-shell.yaml +46 -0
  263. package/rules/semgrep-registry/el-injection.yaml +137 -0
  264. package/rules/semgrep-registry/formatted-sql-string.yaml +95 -0
  265. package/rules/semgrep-registry/http-response-splitting.yaml +44 -0
  266. package/rules/semgrep-registry/index.txt +1 -0
  267. package/rules/semgrep-registry/insecure-smtp-connection.yaml +34 -0
  268. package/rules/semgrep-registry/java-reverse-shell.yaml +43 -0
  269. package/rules/semgrep-registry/jdbc-sql-formatted-string.yaml +120 -0
  270. package/rules/semgrep-registry/ldap-entry-poisoning.yaml +41 -0
  271. package/rules/semgrep-registry/ldap-injection.yaml +82 -0
  272. package/rules/semgrep-registry/md5-used-as-password.yaml +44 -0
  273. package/rules/semgrep-registry/object-deserialization.yaml +34 -0
  274. package/rules/semgrep-registry/ognl-injection.yaml +839 -0
  275. package/rules/semgrep-registry/overly-permissive-file-permission.yaml +49 -0
  276. package/rules/semgrep-registry/permissive-cors.yaml +77 -0
  277. package/rules/semgrep-registry/script-engine-injection.yaml +66 -0
  278. package/rules/semgrep-registry/tainted-cmd-from-http-request.yaml +74 -0
  279. package/rules/semgrep-registry/tainted-env-from-http-request.yaml +46 -0
  280. package/rules/semgrep-registry/tainted-ldapi-from-http-request.yaml +42 -0
  281. package/rules/semgrep-registry/tainted-session-from-http-request.yaml +70 -0
  282. package/rules/semgrep-registry/tainted-xpath-from-http-request.yaml +38 -0
  283. package/rules/semgrep-registry/unsafe-reflection.yaml +39 -0
  284. package/rules/semgrep-registry/unvalidated-redirect.yaml +127 -0
  285. package/rules/semgrep-registry/url-rewriting.yaml +82 -0
  286. package/rules/semgrep-registry/weak-ssl-context.yaml +34 -0
  287. package/rules/semgrep-registry/xml-decoder.yaml +53 -0
  288. package/rules/semgrep-registry/xssrequestwrapper-is-insecure.yaml +40 -0
@@ -0,0 +1,93 @@
1
+ # 逐码 ZhuMa IaC 规则 — Ansible Playbook 硬编码密码检测
2
+ # V4.1 Sprint — CWE-798: Use of Hard-coded Credentials
3
+
4
+ rules:
5
+ # ZM-ANSIBLE-CWE798-001: vars 中明文密码/secret/token
6
+ - id: zm-ansible-cwe798-creds-001
7
+ severity: CRITICAL
8
+ message: |
9
+ Ansible Playbook 的 `vars` 块中包含明文密码、Secret 或 Token。
10
+ 应使用 `ansible-vault encrypt_string` 加密敏感值,或通过环境变量 lookup 注入:
11
+ ```yaml
12
+ vars:
13
+ db_password: "{{ lookup('env', 'DB_PASSWORD') }}"
14
+ ```
15
+ languages:
16
+ - generic
17
+ pattern-either:
18
+ - pattern: |
19
+ vars:
20
+ ...
21
+ password: "$VAL"
22
+ ...
23
+ - pattern: |
24
+ vars:
25
+ ...
26
+ secret: "$VAL"
27
+ ...
28
+ - pattern: |
29
+ vars:
30
+ ...
31
+ token: "$VAL"
32
+ ...
33
+ - pattern: |
34
+ vars:
35
+ ...
36
+ api_key: "$VAL"
37
+ ...
38
+ metadata:
39
+ cwe: "CWE-798: Use of Hard-coded Credentials"
40
+ category: iac-ansible
41
+ precision: medium
42
+ confidence: high
43
+ tags: [ansible, hardcoded-credentials, secrets, vars]
44
+
45
+ # ZM-ANSIBLE-CWE798-002: module 中 login_password 明文
46
+ - id: zm-ansible-cwe798-creds-002
47
+ severity: CRITICAL
48
+ message: |
49
+ Ansible module 参数中直接硬编码 `login_password`、`password` 或 `secret` 的明文值。
50
+ 应改用 `ansible-vault` 加密变量或环境变量 lookup 传入:
51
+ ```yaml
52
+ login_password: "{{ vault_db_password }}"
53
+ ```
54
+ languages:
55
+ - generic
56
+ pattern-either:
57
+ - pattern: |
58
+ login_password: "$VAL"
59
+ - pattern: |
60
+ password: "$VAL"
61
+ - pattern: |
62
+ login_secret: "$VAL"
63
+ metadata:
64
+ cwe: "CWE-798: Use of Hard-coded Credentials"
65
+ category: iac-ansible
66
+ precision: medium
67
+ confidence: high
68
+ tags: [ansible, hardcoded-credentials, secrets, module]
69
+
70
+ # ZM-ANSIBLE-CWE798-003: set_fact 中硬编码凭证
71
+ - id: zm-ansible-cwe798-creds-003
72
+ severity: HIGH
73
+ message: |
74
+ Ansible `set_fact` 中直接赋值明文密码/密钥 — 该值会出现在 Ansible 日志和执行输出中。
75
+ 应使用 `ansible-vault` 加密后引用,或通过 lookup 插件从外部密钥管理服务获取。
76
+ languages:
77
+ - generic
78
+ pattern-either:
79
+ - pattern: |
80
+ set_fact:
81
+ password: "$VAL"
82
+ - pattern: |
83
+ set_fact:
84
+ secret: "$VAL"
85
+ - pattern: |
86
+ set_fact:
87
+ token: "$VAL"
88
+ metadata:
89
+ cwe: "CWE-798: Use of Hard-coded Credentials"
90
+ category: iac-ansible
91
+ precision: medium
92
+ confidence: high
93
+ tags: [ansible, hardcoded-credentials, secrets, set_fact]
@@ -0,0 +1,100 @@
1
+ # 逐码 ZhuMa IaC 规则 — Terraform S3/OSS Bucket 公开访问检测
2
+ # V4.1 Sprint — CWE-200: Exposure of Sensitive Information to an Unauthorized Actor
3
+
4
+ rules:
5
+ # ZM-TF-CWE200-001: AWS S3 Bucket ACL 公开读
6
+ - id: zm-tf-cwe200-s3-public-001
7
+ severity: CRITICAL
8
+ message: |
9
+ AWS S3 Bucket ACL 设置为 `public-read` 或 `public-read-write` — 存储桶数据可被任意匿名用户读取。
10
+ 检查是否可以改用预签名 URL 或 CloudFront OAC 替代直接公开访问,
11
+ 或将 ACL 改为 `private` 并使用 IAM 策略精细化授权。
12
+ languages:
13
+ - terraform
14
+ pattern-either:
15
+ - pattern: |
16
+ resource "aws_s3_bucket_acl" $NAME {
17
+ ...
18
+ acl = "public-read"
19
+ ...
20
+ }
21
+ - pattern: |
22
+ resource "aws_s3_bucket_acl" $NAME {
23
+ ...
24
+ acl = "public-read-write"
25
+ ...
26
+ }
27
+ - pattern: |
28
+ resource "aws_s3_bucket" $NAME {
29
+ ...
30
+ acl = "public-read"
31
+ ...
32
+ }
33
+ - pattern: |
34
+ resource "aws_s3_bucket" $NAME {
35
+ ...
36
+ acl = "public-read-write"
37
+ ...
38
+ }
39
+ metadata:
40
+ cwe: "CWE-200: Exposure of Sensitive Information to an Unauthorized Actor"
41
+ category: iac-terraform
42
+ precision: very-high
43
+ confidence: high
44
+ tags: [terraform, aws, s3, public-access, data-leak]
45
+
46
+ # ZM-TF-CWE200-002: S3 Bucket Policy 允许公开访问
47
+ - id: zm-tf-cwe200-s3-public-002
48
+ severity: CRITICAL
49
+ message: |
50
+ S3 Bucket Policy 中 Principal 设为 `"*"` 且 Effect 为 `Allow` — 任意主体可访问存储桶。
51
+ 将 Principal 限制为特定 AWS 账户或 IAM 角色 ARN,或将 Action 限制为仅 `s3:GetObject` 等必要操作。
52
+ languages:
53
+ - terraform
54
+ pattern-either:
55
+ - pattern: |
56
+ resource "aws_s3_bucket_policy" $NAME {
57
+ ...
58
+ policy = "...\"Principal\":\"*\"..."
59
+ ...
60
+ }
61
+ - pattern: |
62
+ resource "aws_s3_bucket_policy" $NAME {
63
+ ...
64
+ policy = "...\"Principal\": { \"AWS\": \"*\" }..."
65
+ ...
66
+ }
67
+ metadata:
68
+ cwe: "CWE-200: Exposure of Sensitive Information to an Unauthorized Actor"
69
+ category: iac-terraform
70
+ precision: medium
71
+ confidence: high
72
+ tags: [terraform, aws, s3, policy, public-access]
73
+
74
+ # ZM-TF-CWE200-003: Aliyun OSS Bucket ACL 公开读
75
+ - id: zm-tf-cwe200-s3-public-003
76
+ severity: CRITICAL
77
+ message: |
78
+ 阿里云 OSS Bucket ACL 设置为 `public-read` 或 `public-read-write` — 存储桶数据可被任意匿名用户访问。
79
+ 将 acl 改为 `private` 并使用 RAM 策略或 STS 临时令牌进行精细化访问控制。
80
+ languages:
81
+ - terraform
82
+ pattern-either:
83
+ - pattern: |
84
+ resource "alicloud_oss_bucket" $NAME {
85
+ ...
86
+ acl = "public-read"
87
+ ...
88
+ }
89
+ - pattern: |
90
+ resource "alicloud_oss_bucket" $NAME {
91
+ ...
92
+ acl = "public-read-write"
93
+ ...
94
+ }
95
+ metadata:
96
+ cwe: "CWE-200: Exposure of Sensitive Information to an Unauthorized Actor"
97
+ category: iac-terraform
98
+ precision: very-high
99
+ confidence: high
100
+ tags: [terraform, alicloud, oss, public-access, data-leak]
@@ -0,0 +1,88 @@
1
+ # 逐码 ZhuMa IaC 规则 — Terraform 安全组全网段开放检测
2
+ # V4.1 Sprint — CWE-284: Improper Access Control
3
+
4
+ rules:
5
+ # ZM-TF-CWE284-001: AWS 安全组 ingress 0.0.0.0/0
6
+ - id: zm-tf-cwe284-sg-open-001
7
+ severity: CRITICAL
8
+ message: |
9
+ AWS 安全组规则 cidr_blocks 包含 `0.0.0.0/0` — 入站流量对全网开放。
10
+ 将 cidr_blocks 限制为业务所需的最小 IP 段 (如办公网出口 IP、VPC CIDR),
11
+ 避免数据库端口 (3306/5432/6379/27017)、SSH (22)、RDP (3389) 等管理端口对公网暴露。
12
+ languages:
13
+ - terraform
14
+ pattern-either:
15
+ - pattern: |
16
+ resource "aws_security_group_rule" $NAME {
17
+ ...
18
+ cidr_blocks = ["0.0.0.0/0"]
19
+ ...
20
+ }
21
+ - pattern: |
22
+ resource "aws_security_group_rule" $NAME {
23
+ ...
24
+ cidr_blocks = ["0.0.0.0/0", ...]
25
+ ...
26
+ }
27
+ metadata:
28
+ cwe: "CWE-284: Improper Access Control"
29
+ category: iac-terraform
30
+ precision: very-high
31
+ confidence: high
32
+ tags: [terraform, aws, security-group, 0.0.0.0/0, network-exposure]
33
+
34
+ # ZM-TF-CWE284-002: AWS 安全组 ipv6_cidr_blocks ::/0
35
+ - id: zm-tf-cwe284-sg-open-002
36
+ severity: CRITICAL
37
+ message: |
38
+ AWS 安全组规则 ipv6_cidr_blocks 包含 `::/0` — IPv6 全网段开放入站流量。
39
+ 与 0.0.0.0/0 同理,应将 ipv6_cidr_blocks 限制为最小必要范围。
40
+ languages:
41
+ - terraform
42
+ pattern-either:
43
+ - pattern: |
44
+ resource "aws_security_group_rule" $NAME {
45
+ ...
46
+ ipv6_cidr_blocks = ["::/0"]
47
+ ...
48
+ }
49
+ - pattern: |
50
+ resource "aws_security_group_rule" $NAME {
51
+ ...
52
+ ipv6_cidr_blocks = ["::/0", ...]
53
+ ...
54
+ }
55
+ metadata:
56
+ cwe: "CWE-284: Improper Access Control"
57
+ category: iac-terraform
58
+ precision: very-high
59
+ confidence: high
60
+ tags: [terraform, aws, security-group, ipv6, network-exposure]
61
+
62
+ # ZM-TF-CWE284-003: 阿里云安全组 0.0.0.0/0
63
+ - id: zm-tf-cwe284-sg-open-003
64
+ severity: CRITICAL
65
+ message: |
66
+ 阿里云安全组规则 cidr_ip 为 `0.0.0.0/0` — 入站流量对全网开放。
67
+ 将 cidr_ip 限制为业务所需的最小 IP 段,管理端口(22/3389/3306 等)严禁对 0.0.0.0/0 开放。
68
+ languages:
69
+ - terraform
70
+ pattern-either:
71
+ - pattern: |
72
+ resource "alicloud_security_group_rule" $NAME {
73
+ ...
74
+ cidr_ip = "0.0.0.0/0"
75
+ ...
76
+ }
77
+ - pattern: |
78
+ resource "alicloud_security_group_rule" $NAME {
79
+ ...
80
+ source_cidr_ip = "0.0.0.0/0"
81
+ ...
82
+ }
83
+ metadata:
84
+ cwe: "CWE-284: Improper Access Control"
85
+ category: iac-terraform
86
+ precision: very-high
87
+ confidence: high
88
+ tags: [terraform, alicloud, security-group, 0.0.0.0/0, network-exposure]
@@ -0,0 +1,83 @@
1
+ # 逐码 ZhuMa IaC 规则 — Terraform IAM 策略通配符检测
2
+ # V4.1 Sprint — CWE-311: Missing Encryption of Sensitive Data / Overprivileged Policy
3
+
4
+ rules:
5
+ # ZM-TF-CWE311-001: IAM Policy Action 通配符 "*"
6
+ - id: zm-tf-cwe311-iam-wildcard-001
7
+ severity: HIGH
8
+ message: |
9
+ IAM 策略中 `Action` 包含通配符 `"*"` 且 `Effect` 为 `"Allow"` — 该策略授予了对所有服务的完全访问权限。
10
+ 将 Action 明确限定为所需的具体操作,如 `["s3:GetObject", "s3:PutObject"]`。
11
+ 生产环境严禁使用 `Action = "*"` 的 Allow 策略。
12
+ languages:
13
+ - terraform
14
+ pattern-either:
15
+ - pattern: |
16
+ resource "aws_iam_policy" $NAME {
17
+ ...
18
+ policy = "...\"Action\":\"*\"..."
19
+ ...
20
+ }
21
+ - pattern: |
22
+ resource "aws_iam_policy" $NAME {
23
+ ...
24
+ policy = "...\"Action\": [\"*\"..."
25
+ ...
26
+ }
27
+ metadata:
28
+ cwe: "CWE-311: Missing Encryption of Sensitive Data"
29
+ category: iac-terraform
30
+ precision: medium
31
+ confidence: high
32
+ tags: [terraform, aws, iam, wildcard, overprivileged]
33
+
34
+ # ZM-TF-CWE311-002: IAM Policy Resource 通配符 "*"
35
+ - id: zm-tf-cwe311-iam-wildcard-002
36
+ severity: HIGH
37
+ message: |
38
+ IAM 策略中 `Resource` 包含通配符 `"*"` 且 `Effect` 为 `"Allow"` — 该策略可操作账户下所有资源。
39
+ 将 Resource 限定为具体 ARN,如 `"arn:aws:s3:::my-bucket/*"`。
40
+ 除非是管理员角色,否则应遵循最小权限原则。
41
+ languages:
42
+ - terraform
43
+ pattern-either:
44
+ - pattern: |
45
+ resource "aws_iam_policy" $NAME {
46
+ ...
47
+ policy = "...\"Resource\":\"*\"..."
48
+ ...
49
+ }
50
+ - pattern: |
51
+ resource "aws_iam_policy" $NAME {
52
+ ...
53
+ policy = "...\"Resource\": [\"*\"..."
54
+ ...
55
+ }
56
+ metadata:
57
+ cwe: "CWE-311: Missing Encryption of Sensitive Data"
58
+ category: iac-terraform
59
+ precision: medium
60
+ confidence: high
61
+ tags: [terraform, aws, iam, wildcard, overprivileged]
62
+
63
+ # ZM-TF-CWE311-003: IAM Policy 同时 Action="*" + Resource="*"
64
+ - id: zm-tf-cwe311-iam-wildcard-003
65
+ severity: CRITICAL
66
+ message: |
67
+ IAM 策略中同时使用 `Action = "*"` 和 `Resource = "*"` — 这是最危险的策略配置,
68
+ 授予了对所有 AWS 服务的所有资源的完全访问权限(等效于 AdministratorAccess)。
69
+ 必须立即将该策略替换为细粒度权限,仅授予完成任务所需的最小操作和资源。
70
+ languages:
71
+ - terraform
72
+ pattern: |
73
+ resource "aws_iam_policy" $NAME {
74
+ ...
75
+ policy = "...\"Action\": \"*\"...\"Resource\": \"*\"..."
76
+ ...
77
+ }
78
+ metadata:
79
+ cwe: "CWE-311: Missing Encryption of Sensitive Data"
80
+ category: iac-terraform
81
+ precision: medium
82
+ confidence: high
83
+ tags: [terraform, aws, iam, wildcard, admin, overprivileged]
@@ -0,0 +1,72 @@
1
+ # 逐码 ZhuMa IaC 规则 — Terraform RDS/数据库公网暴露检测
2
+ # V4.1 Sprint — CWE-319: Cleartext Transmission of Sensitive Information
3
+
4
+ rules:
5
+ # ZM-TF-CWE319-001: AWS RDS publicly_accessible = true
6
+ - id: zm-tf-cwe319-rds-public-001
7
+ severity: HIGH
8
+ message: |
9
+ AWS RDS 实例 `publicly_accessible` 设为 `true` — 数据库直接暴露在公网,极易被扫描和暴力破解。
10
+ 将 `publicly_accessible` 改为 `false`,数据库仅通过 VPC 内部访问。
11
+ 如需外部管理,使用堡垒机或 SSM Session Manager 转发。
12
+ languages:
13
+ - terraform
14
+ pattern: |
15
+ resource "aws_db_instance" $NAME {
16
+ ...
17
+ publicly_accessible = true
18
+ ...
19
+ }
20
+ metadata:
21
+ cwe: "CWE-319: Cleartext Transmission of Sensitive Information"
22
+ category: iac-terraform
23
+ precision: very-high
24
+ confidence: high
25
+ tags: [terraform, aws, rds, public-access, database-exposure]
26
+
27
+ # ZM-TF-CWE319-002: AWS RDS publicly_accessible 未显式设 false
28
+ - id: zm-tf-cwe319-rds-public-002
29
+ severity: MEDIUM
30
+ message: |
31
+ AWS RDS 实例未显式设置 `publicly_accessible = false` — 默认值取决于子网是否为公有子网。
32
+ 应在 resource 中显式声明 `publicly_accessible = false` 以确保数据库不对外暴露。
33
+ languages:
34
+ - terraform
35
+ pattern: |
36
+ resource "aws_db_instance" $NAME {
37
+ ...
38
+ }
39
+ pattern-not: |
40
+ resource "aws_db_instance" $NAME {
41
+ ...
42
+ publicly_accessible = ...
43
+ ...
44
+ }
45
+ metadata:
46
+ cwe: "CWE-319: Cleartext Transmission of Sensitive Information"
47
+ category: iac-terraform
48
+ precision: medium
49
+ confidence: medium
50
+ tags: [terraform, aws, rds, public-access, missing-config]
51
+
52
+ # ZM-TF-CWE319-003: 阿里云 RDS address_type "Internet"
53
+ - id: zm-tf-cwe319-rds-public-003
54
+ severity: HIGH
55
+ message: |
56
+ 阿里云 RDS 实例分配了公网连接地址 (`address_type = "Internet"`) — 数据库暴露在公网。
57
+ 移除 `alicloud_db_connection` 中的公网地址配置,仅保留 `Intranet` 类型地址,
58
+ 或通过 DMS 等管控平台进行安全访问。
59
+ languages:
60
+ - terraform
61
+ pattern: |
62
+ resource "alicloud_db_connection" $NAME {
63
+ ...
64
+ address_type = "Internet"
65
+ ...
66
+ }
67
+ metadata:
68
+ cwe: "CWE-319: Cleartext Transmission of Sensitive Information"
69
+ category: iac-terraform
70
+ precision: very-high
71
+ confidence: high
72
+ tags: [terraform, alicloud, rds, public-access, database-exposure]
@@ -0,0 +1,102 @@
1
+ # 逐码 ZhuMa IaC 规则 — Terraform 硬编码凭证检测
2
+ # V4.1 Sprint — CWE-798: Use of Hard-coded Credentials
3
+
4
+ rules:
5
+ # ZM-TF-CWE798-001: variable 默认值含密码/密钥
6
+ - id: zm-tf-cwe798-creds-001
7
+ severity: CRITICAL
8
+ message: |
9
+ Terraform variable 的 default 值中包含疑似密码/密钥/Token 的硬编码明文。
10
+ 应移除默认值,通过环境变量 `TF_VAR_xxx` 或 `.tfvars` 文件(不提交到 Git)传入敏感值,
11
+ 或使用 Vault/AWS Secrets Manager 等密钥管理服务动态获取。
12
+ languages:
13
+ - terraform
14
+ pattern-either:
15
+ - pattern: |
16
+ variable "$VAR" {
17
+ ...
18
+ default = "$SECRET"
19
+ ...
20
+ }
21
+ metadata:
22
+ cwe: "CWE-798: Use of Hard-coded Credentials"
23
+ category: iac-terraform
24
+ precision: medium
25
+ confidence: high
26
+ tags: [terraform, hardcoded-credentials, secrets, variable]
27
+
28
+ # ZM-TF-CWE798-002: resource 中直接写 access_key / secret_key
29
+ - id: zm-tf-cwe798-creds-002
30
+ severity: CRITICAL
31
+ message: |
32
+ Terraform resource 中直接硬编码 `access_key` / `secret_key` / `password` 等凭证字段。
33
+ 应改用 variable + 敏感标记 (`sensitive = true`),并通过环境变量或密钥管理服务注入值。
34
+ 示例:
35
+ ```hcl
36
+ variable "db_password" {
37
+ type = string
38
+ sensitive = true
39
+ }
40
+ ```
41
+ languages:
42
+ - terraform
43
+ pattern-either:
44
+ - pattern: |
45
+ resource "$TYPE" "$NAME" {
46
+ ...
47
+ access_key = "$VAL"
48
+ ...
49
+ }
50
+ - pattern: |
51
+ resource "$TYPE" "$NAME" {
52
+ ...
53
+ secret_key = "$VAL"
54
+ ...
55
+ }
56
+ - pattern: |
57
+ resource "$TYPE" "$NAME" {
58
+ ...
59
+ password = "$VAL"
60
+ ...
61
+ }
62
+ metadata:
63
+ cwe: "CWE-798: Use of Hard-coded Credentials"
64
+ category: iac-terraform
65
+ precision: medium
66
+ confidence: high
67
+ tags: [terraform, hardcoded-credentials, secrets, resource]
68
+
69
+ # ZM-TF-CWE798-003: provider 块中硬编码凭证
70
+ - id: zm-tf-cwe798-creds-003
71
+ severity: CRITICAL
72
+ message: |
73
+ Terraform provider 块中硬编码 `access_key` / `secret_key` / `token` — 这些凭证会被写入 state 文件和执行日志。
74
+ 应使用环境变量 (`AWS_ACCESS_KEY_ID` / `ALICLOUD_ACCESS_KEY`) 或 shared_credentials_file,
75
+ 切勿在 provider 块中直接写入凭证。
76
+ languages:
77
+ - terraform
78
+ pattern-either:
79
+ - pattern: |
80
+ provider "$PROVIDER" {
81
+ ...
82
+ access_key = "$VAL"
83
+ ...
84
+ }
85
+ - pattern: |
86
+ provider "$PROVIDER" {
87
+ ...
88
+ secret_key = "$VAL"
89
+ ...
90
+ }
91
+ - pattern: |
92
+ provider "$PROVIDER" {
93
+ ...
94
+ token = "$VAL"
95
+ ...
96
+ }
97
+ metadata:
98
+ cwe: "CWE-798: Use of Hard-coded Credentials"
99
+ category: iac-terraform
100
+ precision: very-high
101
+ confidence: high
102
+ tags: [terraform, hardcoded-credentials, secrets, provider]
@@ -0,0 +1,50 @@
1
+ # 逐码 ZhuMa IaC 规则 — Dockerfile USER root / 未指定 USER 检测
2
+ # V4.1 Sprint — CWE-250: Execution with Unnecessary Privileges
3
+
4
+ rules:
5
+ # ZM-DOCKER-CWE250-001: USER root 或未指定 USER
6
+ - id: zm-docker-cwe250-root-001
7
+ severity: HIGH
8
+ message: |
9
+ Dockerfile 中 `USER root` 或未指定 `USER` 指令 — 容器默认以 root (UID 0) 运行。
10
+ 攻击者一旦逃逸容器即可获得宿主机 root 权限。
11
+ 在 Dockerfile 末尾添加 `USER 1000` 切换到非 root 用户,配合 Kubernetes SecurityContext:
12
+ ```yaml
13
+ securityContext:
14
+ runAsNonRoot: true
15
+ runAsUser: 1000
16
+ ```
17
+ languages:
18
+ - dockerfile
19
+ pattern: |
20
+ USER root
21
+ metadata:
22
+ cwe: "CWE-250: Execution with Unnecessary Privileges"
23
+ category: iac-dockerfile
24
+ precision: very-high
25
+ confidence: high
26
+ tags: [docker, root, privilege-escalation, securitycontext]
27
+
28
+ # ZM-DOCKER-CWE250-002: 未设置任何 USER 指令
29
+ - id: zm-docker-cwe250-root-002
30
+ severity: MEDIUM
31
+ message: |
32
+ Dockerfile 中未设置任何 `USER` 指令 — 容器默认以 root 身份运行。
33
+ 在 Dockerfile 中创建专用非 root 用户并切换到该用户:
34
+ ```dockerfile
35
+ RUN addgroup -S appgroup && adduser -S appuser -G appgroup
36
+ USER appuser
37
+ ```
38
+ 注意确保 `USER` 指令在 `COPY`/文件操作之后,避免权限问题。
39
+ languages:
40
+ - dockerfile
41
+ pattern: |
42
+ FROM $IMAGE
43
+ pattern-not: |
44
+ USER $USER
45
+ metadata:
46
+ cwe: "CWE-250: Execution with Unnecessary Privileges"
47
+ category: iac-dockerfile
48
+ precision: low
49
+ confidence: medium
50
+ tags: [docker, root, missing-user, privilege-escalation]
@@ -0,0 +1,92 @@
1
+ # 逐码 ZhuMa IaC 规则 — Docker 资源限制缺失检测
2
+ # V4.1 Sprint — CWE-400: Uncontrolled Resource Consumption
3
+ # 检测: 无--cpus/--memory限制、HEALTHCHECK未配置
4
+
5
+ rules:
6
+ # ZM-DOCKER-CWE400-RES-001: docker run / compose 缺少 CPU 限制
7
+ - id: zm-docker-cwe400-res-001
8
+ severity: MEDIUM
9
+ message: |
10
+ Docker 容器未设置 CPU 限制(`--cpus` 或 `cpus:` 或 `resources.limits.cpu`)。
11
+ 无 CPU 限制的容器可消耗全部宿主 CPU 资源,导致 DoS 或资源争抢。
12
+
13
+ 修复:
14
+ 1. docker run: `--cpus=1.5` 限制 CPU 使用核心数
15
+ 2. docker compose: `deploy.resources.limits.cpus: '1.5'`
16
+ 3. docker compose v2: `cpus: 1.5` (deprecated but still common)
17
+ 4. K8s: `resources.limits.cpu: "1"`
18
+ languages:
19
+ - generic
20
+ pattern-either:
21
+ - pattern: docker run ... $IMAGE
22
+ - pattern: docker run $OPTS $IMAGE
23
+ metadata:
24
+ cwe: "CWE-400: Uncontrolled Resource Consumption"
25
+ category: iac-docker
26
+ precision: low
27
+ confidence: low
28
+ tags: [docker, resource-exhaustion, dos, resource-limits]
29
+
30
+ # ZM-DOCKER-CWE400-RES-002: docker run / compose 缺少内存限制
31
+ - id: zm-docker-cwe400-res-002
32
+ severity: MEDIUM
33
+ message: |
34
+ Docker 容器未设置内存限制(`--memory` 或 `mem_limit:` 或 `resources.limits.memory`)。
35
+ 无内存限制的容器可耗尽宿主内存,触发 OOM Killer 杀死关键进程。
36
+
37
+ 修复:
38
+ 1. docker run: `--memory=512m --memory-swap=512m` 限制内存
39
+ 2. docker compose: `deploy.resources.limits.memory: 512M`
40
+ 3. docker compose v2: `mem_limit: 512m`
41
+ 4. K8s: `resources.limits.memory: "512Mi"`
42
+ 5. memory-swap 应与 memory 等值以避免使用磁盘swap
43
+ languages:
44
+ - generic
45
+ pattern-either:
46
+ - pattern: docker run ... $IMAGE
47
+ - pattern: docker run $OPTS $IMAGE
48
+ metadata:
49
+ cwe: "CWE-400: Uncontrolled Resource Consumption"
50
+ category: iac-docker
51
+ precision: low
52
+ confidence: low
53
+ tags: [docker, resource-exhaustion, dos, resource-limits]
54
+
55
+ # ZM-DOCKER-CWE400-RES-003: Dockerfile 缺少 HEALTHCHECK 指令
56
+ - id: zm-docker-cwe400-res-003
57
+ severity: LOW
58
+ message: |
59
+ Dockerfile 未配置 `HEALTHCHECK` 指令 — 容器运行时Docker无法判断服务是否健康。
60
+ 缺少健康检查导致:
61
+ 1. 服务启动失败时无法自动重启(需配合 restart policy)
62
+ 2. 滚动更新时无法判断新容器是否就绪
63
+ 3. 编排系统(K8s/Swarm)无法做健康决策
64
+
65
+ 修复:
66
+ 添加 HEALTHCHECK 指令:
67
+ # HTTP服务:
68
+ HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
69
+ CMD curl -f http://localhost:8080/health || exit 1
70
+
71
+ # 进程检查:
72
+ HEALTHCHECK --interval=30s --timeout=3s \
73
+ CMD pgrep -x node || exit 1
74
+
75
+ 常用参数:
76
+ - --interval=DURATION (默认30s) 检查间隔
77
+ - --timeout=DURATION (默认30s) 超时时间
78
+ - --start-period=DURATION (默认0s) 启动缓冲时间
79
+ - --retries=N (默认3) 失败重试次数
80
+ languages:
81
+ - dockerfile
82
+ patterns:
83
+ - pattern-not: |
84
+ HEALTHCHECK ...
85
+ - pattern: |
86
+ CMD ...
87
+ metadata:
88
+ cwe: "CWE-400: Uncontrolled Resource Consumption"
89
+ category: iac-docker
90
+ precision: low
91
+ confidence: medium
92
+ tags: [docker, healthcheck, reliability, best-practice]