@code-sentinel-cli/code-sentinel-cli 3.0.3 → 3.0.5

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 (133) hide show
  1. package/README.md +1 -1
  2. package/dist/bin.js +1191 -816
  3. package/dist/builtin-rules/ai/angular/api-service-contract-risk.prompt.md +71 -0
  4. package/dist/builtin-rules/ai/angular/api-service-contract-risk.rule.yaml +22 -0
  5. package/dist/builtin-rules/ai/angular/component-state-flow.prompt.md +79 -0
  6. package/dist/builtin-rules/ai/angular/component-state-flow.rule.yaml +26 -0
  7. package/dist/builtin-rules/ai/angular/cross-feature-api-drift.prompt.md +70 -0
  8. package/dist/builtin-rules/ai/angular/cross-feature-api-drift.rule.yaml +42 -0
  9. package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.prompt.md +73 -0
  10. package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.rule.yaml +50 -0
  11. package/dist/builtin-rules/ai/angular/reactive-form-flow.prompt.md +82 -0
  12. package/dist/builtin-rules/ai/angular/reactive-form-flow.rule.yaml +23 -0
  13. package/dist/builtin-rules/ai/angular/route-permission-flow.prompt.md +80 -0
  14. package/dist/builtin-rules/ai/angular/route-permission-flow.rule.yaml +23 -0
  15. package/dist/builtin-rules/ai/angular/rxjs-flow-risk.prompt.md +82 -0
  16. package/dist/builtin-rules/ai/angular/rxjs-flow-risk.rule.yaml +24 -0
  17. package/dist/builtin-rules/ai/angular/template-contract-risk.prompt.md +80 -0
  18. package/dist/builtin-rules/ai/angular/template-contract-risk.rule.yaml +25 -0
  19. package/dist/builtin-rules/ai/flutter/dynamic-content-risk.prompt.md +55 -0
  20. package/dist/builtin-rules/ai/flutter/dynamic-content-risk.rule.yaml +18 -0
  21. package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.prompt.md +58 -0
  22. package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.rule.yaml +18 -0
  23. package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.prompt.md +56 -0
  24. package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.rule.yaml +18 -0
  25. package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.prompt.md +57 -0
  26. package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.rule.yaml +19 -0
  27. package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.prompt.md +60 -0
  28. package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.rule.yaml +18 -0
  29. package/dist/builtin-rules/ai/general/code-clarity.prompt.md +57 -0
  30. package/dist/builtin-rules/ai/general/code-clarity.rule.yaml +20 -0
  31. package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.prompt.md +86 -0
  32. package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.rule.yaml +25 -0
  33. package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.prompt.md +80 -0
  34. package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.rule.yaml +25 -0
  35. package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.prompt.md +76 -0
  36. package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.rule.yaml +63 -0
  37. package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.prompt.md +85 -0
  38. package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.rule.yaml +68 -0
  39. package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.prompt.md +121 -0
  40. package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.rule.yaml +84 -0
  41. package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.prompt.md +80 -0
  42. package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.rule.yaml +25 -0
  43. package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.prompt.md +78 -0
  44. package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.rule.yaml +25 -0
  45. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +83 -0
  46. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +25 -0
  47. package/dist/builtin-rules/ai/spring-boot/pagination-risk.prompt.md +81 -0
  48. package/dist/builtin-rules/ai/spring-boot/pagination-risk.rule.yaml +25 -0
  49. package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.prompt.md +75 -0
  50. package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.rule.yaml +26 -0
  51. package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.prompt.md +75 -0
  52. package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.rule.yaml +24 -0
  53. package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.prompt.md +74 -0
  54. package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.rule.yaml +24 -0
  55. package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.prompt.md +75 -0
  56. package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.rule.yaml +25 -0
  57. package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.prompt.md +78 -0
  58. package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.rule.yaml +25 -0
  59. package/dist/builtin-rules/static/angular/component-prefix.rule.js +78 -0
  60. package/dist/builtin-rules/static/angular/image-control-alt-required.rule.js +105 -0
  61. package/dist/builtin-rules/static/angular/img-alt-required.rule.js +96 -0
  62. package/dist/builtin-rules/static/angular/inject-pattern.rule.js +47 -0
  63. package/dist/builtin-rules/static/angular/lifecycle-method-required.rule.js +59 -0
  64. package/dist/builtin-rules/static/angular/no-any-type.rule.yaml +55 -0
  65. package/dist/builtin-rules/static/angular/no-direct-dom-access.rule.js +191 -0
  66. package/dist/builtin-rules/static/angular/no-dom-xss.rule.js +48 -0
  67. package/dist/builtin-rules/static/angular/no-leaky-subscription.rule.js +197 -0
  68. package/dist/builtin-rules/static/angular/no-ngmodule.rule.yaml +44 -0
  69. package/dist/builtin-rules/static/angular/no-non-null-asserted-optional-chain.rule.js +53 -0
  70. package/dist/builtin-rules/static/angular/no-uncalled-signal-in-condition.rule.js +112 -0
  71. package/dist/builtin-rules/static/angular/observable-naming.rule.js +85 -0
  72. package/dist/builtin-rules/static/angular/onpush-required.rule.js +70 -0
  73. package/dist/builtin-rules/static/angular/standalone-component-required.rule.js +65 -0
  74. package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +112 -0
  75. package/dist/builtin-rules/static/angular/template-syntax-modern.rule.js +154 -0
  76. package/dist/builtin-rules/static/angular/trackby-required.rule.js +66 -0
  77. package/dist/builtin-rules/static/flutter/android-exported-component.rule.js +75 -0
  78. package/dist/builtin-rules/static/flutter/android-manifest-hardening.rule.js +117 -0
  79. package/dist/builtin-rules/static/flutter/android-sensitive-permissions.rule.js +87 -0
  80. package/dist/builtin-rules/static/flutter/debug-tooling-release-risk.rule.js +90 -0
  81. package/dist/builtin-rules/static/flutter/dynamic-archive-risk.rule.js +96 -0
  82. package/dist/builtin-rules/static/flutter/hive-sensitive-storage.rule.js +77 -0
  83. package/dist/builtin-rules/static/flutter/ios-privacy-hardening.rule.js +119 -0
  84. package/dist/builtin-rules/static/flutter/packaged-env-risk.rule.js +95 -0
  85. package/dist/builtin-rules/static/flutter/sensitive-log-leak.rule.js +94 -0
  86. package/dist/builtin-rules/static/flutter/webview-bridge-guard.rule.js +102 -0
  87. package/dist/builtin-rules/static/general/file-too-long.rule.js +41 -0
  88. package/dist/builtin-rules/static/general/function-too-long.rule.js +72 -0
  89. package/dist/builtin-rules/static/general/no-circular-import.rule.js +39 -0
  90. package/dist/builtin-rules/static/general/no-code-injection.rule.js +48 -0
  91. package/dist/builtin-rules/static/general/no-console-log.rule.js +110 -0
  92. package/dist/builtin-rules/static/general/no-empty-catch.rule.yaml +56 -0
  93. package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +517 -0
  94. package/dist/builtin-rules/static/general/no-magic-number.rule.js +78 -0
  95. package/dist/builtin-rules/static/general/no-open-redirect.rule.js +46 -0
  96. package/dist/builtin-rules/static/general/no-todo-comment.rule.yaml +30 -0
  97. package/dist/builtin-rules/static/general/no-unresolved-import-symbol.rule.js +80 -0
  98. package/dist/builtin-rules/static/general/no-unused-export.rule.js +140 -0
  99. package/dist/builtin-rules/static/spring-boot/no-autowired-field.rule.js +162 -0
  100. package/dist/builtin-rules/static/spring-boot/no-business-logic-in-controller.rule.js +94 -0
  101. package/dist/builtin-rules/static/spring-boot/no-command-injection.rule.js +47 -0
  102. package/dist/builtin-rules/static/spring-boot/no-entity-in-controller.rule.yaml +52 -0
  103. package/dist/builtin-rules/static/spring-boot/no-nplus1-query-in-loop.rule.js +106 -0
  104. package/dist/builtin-rules/static/spring-boot/no-path-traversal.rule.js +47 -0
  105. package/dist/builtin-rules/static/spring-boot/no-spel-injection.rule.js +41 -0
  106. package/dist/builtin-rules/static/spring-boot/no-sql-string-concat.rule.js +194 -0
  107. package/dist/builtin-rules/static/spring-boot/no-ssrf.rule.js +49 -0
  108. package/dist/builtin-rules/static/spring-boot/no-transactional-self-invocation.rule.js +142 -0
  109. package/dist/builtin-rules/static/spring-boot/no-unclosed-resource.rule.js +108 -0
  110. package/dist/builtin-rules/static/spring-boot/no-unsafe-shared-formatter.rule.js +118 -0
  111. package/dist/builtin-rules/static/spring-boot/repository-naming.rule.yaml +42 -0
  112. package/dist/builtin-rules/static/spring-boot/restful-naming.rule.yaml +39 -0
  113. package/dist/builtin-rules/static/spring-boot/transaction-on-service.rule.yaml +58 -0
  114. package/dist/builtin-rules/static/spring-boot/validate-input.rule.js +123 -0
  115. package/dist/builtin-rules/vauthz/static/spring-boot/require-authz-check.rule.js +101 -0
  116. package/dist/index.d.ts +225 -48
  117. package/dist/index.js +1190 -815
  118. package/node_modules/@code-sentinel/core/index.js +55 -0
  119. package/node_modules/@code-sentinel/core/package.json +6 -0
  120. package/node_modules/@code-sentinel/parsers/index.js +13 -0
  121. package/node_modules/@code-sentinel/parsers/package.json +6 -0
  122. package/package.json +34 -29
  123. package/src/migrations/0000_initial.sql +62 -0
  124. package/src/migrations/0001_add_confidence.sql +7 -0
  125. package/src/migrations/0002_add_ai_stats.sql +21 -0
  126. package/src/migrations/0003_add_fix_recipe.sql +29 -0
  127. package/src/migrations/0004_add_ast_graph.sql +61 -0
  128. package/src/migrations/0005_add_project_id.sql +1 -0
  129. package/src/migrations/0006_add_ai_model.sql +5 -0
  130. package/src/migrations/0006_add_rule_results.sql +1 -0
  131. package/src/migrations/0007_add_finding_metadata.sql +4 -0
  132. package/src/migrations/0008_add_coverage.sql +2 -0
  133. package/src/migrations/0009_run_provenance.sql +5 -0
@@ -0,0 +1,517 @@
1
+ // builtin-rules/static/general/no-hardcoded-secret.rule.ts
2
+ var PROVIDER_PATTERNS = [
3
+ // ---- AWS ----
4
+ {
5
+ name: "aws-access-key-id",
6
+ regex: /\bAKIA[0-9A-Z]{16}\b/g,
7
+ confidence: 95,
8
+ message: "AWS Access Key ID detected."
9
+ },
10
+ {
11
+ name: "aws-secret-access-key",
12
+ regex: /\baws[_\- ]?(?:secret|sk)[_\- ]?(?:access[_\- ]?key)?\s*[:=]\s*["']([A-Za-z0-9/+=]{40})["']/gi,
13
+ confidence: 90,
14
+ message: "AWS Secret Access Key detected.",
15
+ payloadGroup: 1
16
+ },
17
+ // ---- GitHub ----
18
+ {
19
+ name: "github-pat-classic",
20
+ regex: /\bghp_[A-Za-z0-9]{36}\b/g,
21
+ confidence: 95,
22
+ message: "GitHub personal access token (classic) detected."
23
+ },
24
+ {
25
+ name: "github-oauth",
26
+ regex: /\bgho_[A-Za-z0-9]{36}\b/g,
27
+ confidence: 95,
28
+ message: "GitHub OAuth token detected."
29
+ },
30
+ {
31
+ name: "github-user-to-server",
32
+ regex: /\bghu_[A-Za-z0-9]{36}\b/g,
33
+ confidence: 95,
34
+ message: "GitHub user-to-server token detected."
35
+ },
36
+ {
37
+ name: "github-server-to-server",
38
+ regex: /\bghs_[A-Za-z0-9]{36}\b/g,
39
+ confidence: 95,
40
+ message: "GitHub server-to-server token detected."
41
+ },
42
+ {
43
+ name: "github-refresh",
44
+ regex: /\bghr_[A-Za-z0-9]{76}\b/g,
45
+ confidence: 95,
46
+ message: "GitHub refresh token detected."
47
+ },
48
+ {
49
+ name: "github-fine-grained-pat",
50
+ regex: /\bgithub_pat_[A-Za-z0-9_]{82}\b/g,
51
+ confidence: 95,
52
+ message: "GitHub fine-grained personal access token detected."
53
+ },
54
+ {
55
+ name: "gitlab-pat",
56
+ regex: /\bglpat-[A-Za-z0-9_-]{20,}\b/g,
57
+ confidence: 95,
58
+ message: "GitLab personal access token detected."
59
+ },
60
+ // ---- Slack ----
61
+ {
62
+ name: "slack-token",
63
+ regex: /\bxox[abprs]-[0-9A-Za-z-]{10,}\b/g,
64
+ confidence: 95,
65
+ message: "Slack token detected."
66
+ },
67
+ {
68
+ name: "slack-webhook",
69
+ regex: /\bhttps:\/\/hooks\.slack\.com\/services\/T[A-Z0-9]+\/B[A-Z0-9]+\/[A-Za-z0-9]+\b/g,
70
+ confidence: 95,
71
+ message: "Slack incoming webhook URL detected."
72
+ },
73
+ // ---- Stripe ----
74
+ {
75
+ name: "stripe-live-secret",
76
+ regex: /\bsk_live_[A-Za-z0-9]{24,}\b/g,
77
+ confidence: 95,
78
+ message: "Stripe LIVE secret key detected \u2014 IMMEDIATE rotation required."
79
+ },
80
+ {
81
+ name: "stripe-test-secret",
82
+ regex: /\bsk_test_[A-Za-z0-9]{24,}\b/g,
83
+ confidence: 90,
84
+ message: "Stripe test secret key detected \u2014 rotate before going live."
85
+ },
86
+ {
87
+ name: "stripe-publishable",
88
+ regex: /\bpk_(?:live|test)_[A-Za-z0-9]{24,}\b/g,
89
+ confidence: 70,
90
+ message: "Stripe publishable key detected \u2014 these are technically public, but should still come from env vars."
91
+ },
92
+ {
93
+ name: "stripe-restricted",
94
+ regex: /\brk_(?:live|test)_[A-Za-z0-9]{24,}\b/g,
95
+ confidence: 95,
96
+ message: "Stripe restricted API key detected."
97
+ },
98
+ // ---- Google / Firebase ----
99
+ {
100
+ name: "google-api-key",
101
+ regex: /\bAIza[0-9A-Za-z_-]{35}\b/g,
102
+ confidence: 90,
103
+ message: "Google API key detected."
104
+ },
105
+ {
106
+ name: "google-oauth-access",
107
+ regex: /\bya29\.[0-9A-Za-z_-]+/g,
108
+ confidence: 90,
109
+ message: "Google OAuth access token detected."
110
+ },
111
+ {
112
+ name: "firebase-cloud-messaging",
113
+ regex: /\bAAAA[A-Za-z0-9_-]{7}:[A-Za-z0-9_-]{140}\b/g,
114
+ confidence: 95,
115
+ message: "Firebase Cloud Messaging server key detected."
116
+ },
117
+ // ---- Azure ----
118
+ {
119
+ name: "azure-storage-connection",
120
+ regex: /\bDefaultEndpointsProtocol=https;AccountName=[a-zA-Z0-9]+;AccountKey=[A-Za-z0-9+/=]+/g,
121
+ confidence: 95,
122
+ message: "Azure Storage connection string detected."
123
+ },
124
+ // ---- Twilio ----
125
+ {
126
+ name: "twilio-account-sid",
127
+ regex: /\bAC[a-f0-9]{32}\b/g,
128
+ confidence: 90,
129
+ message: "Twilio Account SID detected."
130
+ },
131
+ {
132
+ name: "twilio-api-key",
133
+ regex: /\bSK[a-f0-9]{32}\b/g,
134
+ confidence: 90,
135
+ message: "Twilio API key detected."
136
+ },
137
+ // ---- Mailgun / SendGrid ----
138
+ {
139
+ name: "sendgrid-api-key",
140
+ regex: /\bSG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}\b/g,
141
+ confidence: 95,
142
+ message: "SendGrid API key detected."
143
+ },
144
+ {
145
+ name: "mailgun-api-key",
146
+ regex: /\bkey-[a-f0-9]{32}\b/g,
147
+ confidence: 90,
148
+ message: "Mailgun API key detected."
149
+ },
150
+ // ---- Telegram / Discord ----
151
+ {
152
+ name: "telegram-bot-token",
153
+ regex: /\b\d{8,10}:[A-Za-z0-9_-]{35}\b/g,
154
+ confidence: 85,
155
+ message: "Telegram bot token detected."
156
+ },
157
+ {
158
+ name: "discord-bot-token",
159
+ regex: /\b[MN][A-Za-z\d]{23}\.[\w-]{6}\.[\w-]{27}\b/g,
160
+ confidence: 85,
161
+ message: "Discord bot token detected."
162
+ },
163
+ {
164
+ name: "discord-webhook",
165
+ regex: /\bhttps:\/\/(?:ptb\.|canary\.)?discord(?:app)?\.com\/api\/webhooks\/\d+\/[A-Za-z0-9_-]+/g,
166
+ confidence: 95,
167
+ message: "Discord webhook URL detected."
168
+ },
169
+ // ---- Package registry ----
170
+ {
171
+ name: "npm-token",
172
+ regex: /\bnpm_[A-Za-z0-9]{36}\b/g,
173
+ confidence: 95,
174
+ message: "NPM access token detected."
175
+ },
176
+ {
177
+ name: "pypi-token",
178
+ regex: /\bpypi-AgEIcHlwaS5vcmc[A-Za-z0-9_-]+/g,
179
+ confidence: 95,
180
+ message: "PyPI API token detected."
181
+ },
182
+ // ---- Cloud platforms ----
183
+ {
184
+ name: "digitalocean-pat",
185
+ regex: /\bdop_v1_[a-f0-9]{64}\b/g,
186
+ confidence: 95,
187
+ message: "DigitalOcean personal access token detected."
188
+ },
189
+ {
190
+ name: "dockerhub-pat",
191
+ regex: /\bdckr_pat_[A-Za-z0-9_-]{20,}\b/g,
192
+ confidence: 95,
193
+ message: "Docker Hub personal access token detected."
194
+ },
195
+ {
196
+ name: "heroku-api-key",
197
+ regex: /\bheroku[_\- ]?(?:api[_\- ]?key|token)\s*[:=]\s*["']([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})["']/gi,
198
+ confidence: 85,
199
+ message: "Heroku API key detected.",
200
+ payloadGroup: 1
201
+ },
202
+ {
203
+ name: "cloudflare-api-token",
204
+ regex: /\bcloudflare[_\- ]?(?:api[_\- ]?)?token\s*[:=]\s*["']([A-Za-z0-9_-]{40})["']/gi,
205
+ confidence: 85,
206
+ message: "Cloudflare API token detected.",
207
+ payloadGroup: 1
208
+ },
209
+ {
210
+ name: "datadog-api-key",
211
+ regex: /\b(?:datadog|dd)[_\- ]?api[_\- ]?key\s*[:=]\s*["']([a-f0-9]{32})["']/gi,
212
+ confidence: 85,
213
+ message: "DataDog API key detected.",
214
+ payloadGroup: 1
215
+ },
216
+ {
217
+ name: "new-relic-license",
218
+ regex: /\b(?:new[_\- ]?relic|nr)[_\- ]?license[_\- ]?key\s*[:=]\s*["']([A-Za-z0-9]{40})["']/gi,
219
+ confidence: 85,
220
+ message: "New Relic license key detected.",
221
+ payloadGroup: 1
222
+ }
223
+ ];
224
+ var PEM_PATTERNS = [
225
+ {
226
+ name: "private-key-rsa",
227
+ regex: /-----BEGIN RSA PRIVATE KEY-----/g,
228
+ confidence: 95,
229
+ message: "RSA private key block detected."
230
+ },
231
+ {
232
+ name: "private-key-openssh",
233
+ regex: /-----BEGIN OPENSSH PRIVATE KEY-----/g,
234
+ confidence: 95,
235
+ message: "OpenSSH private key block detected."
236
+ },
237
+ {
238
+ name: "private-key-ec",
239
+ regex: /-----BEGIN EC PRIVATE KEY-----/g,
240
+ confidence: 95,
241
+ message: "Elliptic-curve private key block detected."
242
+ },
243
+ {
244
+ name: "private-key-dsa",
245
+ regex: /-----BEGIN DSA PRIVATE KEY-----/g,
246
+ confidence: 95,
247
+ message: "DSA private key block detected."
248
+ },
249
+ {
250
+ name: "private-key-pgp",
251
+ regex: /-----BEGIN PGP PRIVATE KEY BLOCK-----/g,
252
+ confidence: 95,
253
+ message: "PGP private key block detected."
254
+ },
255
+ {
256
+ name: "private-key-pkcs8",
257
+ regex: /-----BEGIN PRIVATE KEY-----/g,
258
+ confidence: 95,
259
+ message: "PKCS#8 private key block detected."
260
+ },
261
+ {
262
+ name: "private-key-encrypted",
263
+ regex: /-----BEGIN ENCRYPTED PRIVATE KEY-----/g,
264
+ confidence: 95,
265
+ message: "Encrypted private key block detected."
266
+ }
267
+ ];
268
+ var CONNECTION_PATTERNS = [
269
+ {
270
+ name: "postgres-url-with-creds",
271
+ regex: /\bpostgres(?:ql)?:\/\/[^\s:/@'"]+:[^\s/@'"]{4,}@[^\s/'":]+/g,
272
+ confidence: 80,
273
+ message: "PostgreSQL URL with inline credentials detected."
274
+ },
275
+ {
276
+ name: "mysql-url-with-creds",
277
+ regex: /\bmysql:\/\/[^\s:/@'"]+:[^\s/@'"]{4,}@[^\s/'":]+/g,
278
+ confidence: 80,
279
+ message: "MySQL URL with inline credentials detected."
280
+ },
281
+ {
282
+ name: "mongodb-url-with-creds",
283
+ regex: /\bmongodb(?:\+srv)?:\/\/[^\s:/@'"]+:[^\s/@'"]{4,}@[^\s/'":]+/g,
284
+ confidence: 80,
285
+ message: "MongoDB URL with inline credentials detected."
286
+ },
287
+ {
288
+ name: "redis-url-with-creds",
289
+ regex: /\bredis:\/\/[^\s:/@'"]*:[^\s/@'"]{4,}@[^\s/'":]+/g,
290
+ confidence: 80,
291
+ message: "Redis URL with inline credentials detected."
292
+ },
293
+ {
294
+ name: "amqp-url-with-creds",
295
+ regex: /\bamqps?:\/\/[^\s:/@'"]+:[^\s/@'"]{4,}@[^\s/'":]+/g,
296
+ confidence: 80,
297
+ message: "AMQP URL with inline credentials detected."
298
+ }
299
+ ];
300
+ var JWT_PATTERNS = [
301
+ {
302
+ // Three base64url segments separated by dots; payload segment starts
303
+ // with `eyJ` (base64url of `{"`) to filter random dotted IDs.
304
+ name: "jwt-token",
305
+ regex: /\beyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_.+/=-]+/g,
306
+ confidence: 75,
307
+ message: "JSON Web Token (JWT) detected."
308
+ }
309
+ ];
310
+ var GENERIC_PATTERNS = [
311
+ {
312
+ name: "generic-password-assignment",
313
+ regex: /\b(?:[A-Za-z_$][\w$]*(?:password|passwd|pwd)|password|passwd|pwd)\s*[:=]\s*["']([^"'\s]{8,})["']/gi,
314
+ confidence: 65,
315
+ message: "Hard-coded password assignment detected.",
316
+ payloadGroup: 1
317
+ },
318
+ {
319
+ name: "generic-api-key-assignment",
320
+ regex: /\b(?:api[_-]?key|apikey|access[_-]?token|auth[_-]?token)\s*[:=]\s*["']([A-Za-z0-9_\-./+=]{16,})["']/gi,
321
+ confidence: 70,
322
+ message: "Hard-coded API key / access token assignment detected.",
323
+ payloadGroup: 1
324
+ },
325
+ {
326
+ name: "generic-secret-assignment",
327
+ regex: /\b(?:secret|client[_-]?secret|private[_-]?key)\s*[:=]\s*["']([A-Za-z0-9_\-./+=]{16,})["']/gi,
328
+ confidence: 70,
329
+ message: "Hard-coded secret / client_secret assignment detected.",
330
+ payloadGroup: 1
331
+ }
332
+ ];
333
+ var CONFIG_SECRET_PATTERNS = [
334
+ {
335
+ name: "config-secret-assignment",
336
+ regex: /^\s*(?:[-\w.]+\.)?(?:password|passwd|pwd|secret|client[_-]?secret|api[_-]?key|apikey|access[_-]?token|auth[_-]?token)\s*[:=]\s*([^\s#'"][^\r\n#]*)/gim,
337
+ confidence: 75,
338
+ message: "Config file secret value detected.",
339
+ payloadGroup: 1
340
+ }
341
+ ];
342
+ var BUILTIN_PATTERNS = [
343
+ ...PROVIDER_PATTERNS,
344
+ ...PEM_PATTERNS,
345
+ ...CONNECTION_PATTERNS,
346
+ ...JWT_PATTERNS,
347
+ ...GENERIC_PATTERNS
348
+ ];
349
+ var PLACEHOLDER_NEEDLES = [
350
+ "your-",
351
+ "your_",
352
+ "yourpassword",
353
+ "yourapikey",
354
+ "yoursecret",
355
+ "placeholder",
356
+ "example",
357
+ "changeme",
358
+ "change-me",
359
+ "change_me",
360
+ "replace-me",
361
+ "replace_me",
362
+ "todo",
363
+ "fixme",
364
+ "xxxxx",
365
+ "<your",
366
+ "<replace",
367
+ "<insert",
368
+ "somepass",
369
+ "someapikey",
370
+ "somesecret"
371
+ ];
372
+ var looksLikePlaceholder = (payload) => {
373
+ const lower = payload.toLowerCase();
374
+ for (const needle of PLACEHOLDER_NEEDLES) {
375
+ if (lower.includes(needle)) return true;
376
+ }
377
+ if (payload.length >= 8 && /^(.)\1{7,}$/.test(payload)) return true;
378
+ return false;
379
+ };
380
+ var FIELD_NAME_ECHOES = [
381
+ "password",
382
+ "passwd",
383
+ "pwd",
384
+ "secret",
385
+ "apikey",
386
+ "api_key",
387
+ "api-key",
388
+ "token",
389
+ "accesstoken",
390
+ "access_token",
391
+ "access-token",
392
+ "authtoken",
393
+ "auth_token",
394
+ "auth-token",
395
+ "key",
396
+ "clientsecret",
397
+ "client_secret",
398
+ "client-secret"
399
+ ];
400
+ var isFieldNameEcho = (payload) => FIELD_NAME_ECHOES.includes(payload.toLowerCase());
401
+ var looksExternalized = (payload) => {
402
+ const trimmed = payload.trim();
403
+ const lower = trimmed.toLowerCase();
404
+ return trimmed.startsWith("${") || lower.startsWith("enc(") || lower.startsWith("{cipher}") || lower.startsWith("vault://") || lower.startsWith("optional:vault://");
405
+ };
406
+ var isConfigLanguage = (language) => language === "yaml" || language === "text";
407
+ var lineColAt = (content, offset) => {
408
+ let line = 1;
409
+ let lastNl = -1;
410
+ for (let i = 0; i < offset && i < content.length; i++) {
411
+ if (content.charCodeAt(i) === 10) {
412
+ line++;
413
+ lastNl = i;
414
+ }
415
+ }
416
+ return { line, column: offset - lastNl };
417
+ };
418
+ var compileExtra = (extras, logger) => {
419
+ const out = [];
420
+ if (!Array.isArray(extras)) return out;
421
+ for (const e of extras) {
422
+ if (!e || typeof e.name !== "string" || typeof e.regex !== "string") {
423
+ logger.debug({ entry: e }, "invalid extraPatterns entry \u2014 missing name/regex string");
424
+ continue;
425
+ }
426
+ try {
427
+ const re = new RegExp(e.regex, "g");
428
+ out.push({
429
+ name: e.name,
430
+ regex: re,
431
+ confidence: typeof e.confidence === "number" ? e.confidence : 70,
432
+ message: typeof e.message === "string" ? e.message : `Custom secret pattern "${e.name}" matched.`
433
+ });
434
+ } catch (err) {
435
+ logger.debug(
436
+ { name: e.name, err: err.message },
437
+ "invalid extraPatterns entry \u2014 skipped"
438
+ );
439
+ }
440
+ }
441
+ return out;
442
+ };
443
+ var isOwnTestFile = (filePath) => {
444
+ const basename = filePath.split(/[/\\]/).pop() ?? filePath;
445
+ return basename === "no-hardcoded-secret.test.ts" || basename === "no-hardcoded-secret.rule.ts";
446
+ };
447
+ var rule = {
448
+ id: "general/no-hardcoded-secret",
449
+ // v4: source-only execution + YAML/text support for Spring Boot application
450
+ // config files. `.properties` is classified as `text`.
451
+ // v3: generic password assignment also catches suffixed identifiers such as
452
+ // `dbPassword`, so cached v2 rule results must be invalidated.
453
+ // v2 (1.2.1): added FIELD_NAME_ECHOES filter for enum-value / label-dict
454
+ // FPs (e.g. `PASSWORD = 'password'`). Bumped so the rule cache invalidates
455
+ // stale v1 findings — Phase 9 cache key is (id, version, file.hash).
456
+ version: 4,
457
+ kind: "static-ts",
458
+ title: "Kh\xF4ng hardcode secrets / API keys / private keys v\xE0o source",
459
+ description: "Qu\xE9t credentials, API keys, tokens, private keys committed v\xE0o code. H\u1ED7 tr\u1EE3 AWS / GitHub / GitLab / Slack / Stripe / Google / Azure / Twilio / SendGrid / Mailgun / NPM / PyPI / Discord / Telegram / DataDog / New Relic / Cloudflare / DigitalOcean / Docker Hub + PEM private keys + connection strings c\xF3 inline credentials + JWT + generic password/secret/apiKey assignments. Severity = error (CI gate). Confidence t\u1EEB 65 (generic, c\xF3 false positive) t\u1EDBi 95 (provider-prefixed, near-zero false positive). Tune qua options.disabledPatterns + options.extraPatterns.",
460
+ severity: "error",
461
+ category: "security",
462
+ // Pure content scan: can run on YAML and text-classified config files.
463
+ languages: ["typescript", "javascript", "java", "yaml", "text"],
464
+ scope: "general",
465
+ usesParser: false,
466
+ baseConfidence: 80,
467
+ defaultOptions: {
468
+ disabledPatterns: [],
469
+ extraPatterns: []
470
+ },
471
+ check(ctx) {
472
+ if (isOwnTestFile(ctx.file.path)) return [];
473
+ const disabled = new Set(ctx.options.disabledPatterns);
474
+ const extras = compileExtra(ctx.options.extraPatterns, ctx.logger);
475
+ const patterns = [
476
+ ...BUILTIN_PATTERNS.filter((p) => !disabled.has(p.name)),
477
+ ...isConfigLanguage(ctx.file.language) ? CONFIG_SECRET_PATTERNS.filter((p) => !disabled.has(p.name)) : [],
478
+ ...extras
479
+ ];
480
+ const content = ctx.file.content;
481
+ const findings = [];
482
+ const reportedRanges = [];
483
+ const overlapsReported = (start, end) => {
484
+ for (const r of reportedRanges) {
485
+ if (start < r.end && end > r.start) return true;
486
+ }
487
+ return false;
488
+ };
489
+ for (const pattern of patterns) {
490
+ pattern.regex.lastIndex = 0;
491
+ let match;
492
+ while ((match = pattern.regex.exec(content)) !== null) {
493
+ const matchStart = match.index;
494
+ const matchEnd = matchStart + match[0].length;
495
+ if (overlapsReported(matchStart, matchEnd)) continue;
496
+ const payload = pattern.payloadGroup !== void 0 ? match[pattern.payloadGroup] : match[0];
497
+ if (payload && (looksLikePlaceholder(payload) || isFieldNameEcho(payload) || looksExternalized(payload) || pattern.name === "config-secret-assignment" && payload.trim().length < 8)) {
498
+ continue;
499
+ }
500
+ const { line, column } = lineColAt(content, matchStart);
501
+ findings.push({
502
+ message: `${pattern.message} [pattern=${pattern.name}]`,
503
+ file: ctx.file.path,
504
+ range: { line, column },
505
+ confidence: pattern.confidence,
506
+ suggestion: "Move the secret to an environment variable (vd `process.env.X`) v\xE0 rotate gi\xE1 tr\u1ECB \u0111\xE3 commit ngay. Th\xEAm `.env` v\xE0o `.gitignore`. N\u1EBFu l\xE0 test fixture, \u0111\u1EB7t file v\xE0o path \u0111\xE3 exclude ho\u1EB7c d\xF9ng `// code-sentinel-disable-next-line general/no-hardcoded-secret`."
507
+ });
508
+ reportedRanges.push({ start: matchStart, end: matchEnd });
509
+ }
510
+ }
511
+ return findings;
512
+ }
513
+ };
514
+
515
+ export { rule };
516
+ //# sourceMappingURL=no-hardcoded-secret.rule.js.map
517
+ //# sourceMappingURL=no-hardcoded-secret.rule.js.map
@@ -0,0 +1,78 @@
1
+ import { asTsMorphSourceFile } from '@code-sentinel/parsers';
2
+ import { Node } from 'ts-morph';
3
+
4
+ // builtin-rules/static/general/no-magic-number.rule.ts
5
+ var DEFAULT_WHITELIST = [0, 1, 2, 3, 8, 10, 16, 24, 32, 60, 100, 1e3, 1024];
6
+ var isArrayIndex = (node) => {
7
+ const parent = node.getParent();
8
+ return parent !== void 0 && Node.isElementAccessExpression(parent) && parent.getArgumentExpression() === node;
9
+ };
10
+ var isInNamedDeclaration = (node) => {
11
+ const parent = node.getParent();
12
+ if (!parent) return false;
13
+ if (Node.isVariableDeclaration(parent) && parent.getInitializer() === node) {
14
+ return true;
15
+ }
16
+ if (Node.isPropertyDeclaration(parent) && parent.getInitializer() === node) {
17
+ return true;
18
+ }
19
+ if (Node.isEnumMember(parent) && parent.getInitializer() === node) {
20
+ return true;
21
+ }
22
+ if (Node.isParameterDeclaration(parent) && parent.getInitializer() === node) {
23
+ return true;
24
+ }
25
+ if (Node.isPropertyAssignment(parent) && parent.getInitializer() === node) {
26
+ const name = parent.getName();
27
+ if (/^[A-Z][A-Z0-9_]*$/.test(name) || /^[A-Z][a-zA-Z0-9]*$/.test(name)) {
28
+ return true;
29
+ }
30
+ }
31
+ return false;
32
+ };
33
+ var rule = {
34
+ id: "general/no-magic-number",
35
+ version: 4,
36
+ kind: "static-ts",
37
+ title: "Tr\xE1nh magic number \u2014 \u0111\u1EB7t t\xEAn constant cho gi\xE1 tr\u1ECB c\xF3 \xFD ngh\u0129a",
38
+ description: "Magic number = s\u1ED1 literal xu\u1EA5t hi\u1EC7n inline m\xE0 \xFD ngh\u0129a kh\xF4ng hi\u1EC3n nhi\xEAn. Rule n\xE0y v3 d\xF9ng context filter: b\u1ECF qua c\xE1c literal \u0111\xE3 \u0111\u01B0\u1EE3c \u0111\u1EB7t t\xEAn qua `const X = N`, class field `count = 5`, enum member, default param. Whitelist m\u1EB7c \u0111\u1ECBnh: 0,1,2,3,8,10,16,24,32,60,100,1000,1024. Tune qua `options.whitelist` + `options.skipInDeclarations`.",
39
+ severity: "info",
40
+ category: "maintainability",
41
+ languages: ["typescript", "javascript"],
42
+ scope: "general",
43
+ requires: "semantic-ts",
44
+ baseConfidence: 55,
45
+ defaultOptions: {
46
+ whitelist: [...DEFAULT_WHITELIST],
47
+ skipInDeclarations: true,
48
+ ignoreArrayIndexes: true
49
+ },
50
+ check(ctx) {
51
+ const whitelist = new Set(ctx.options.whitelist);
52
+ const skipInDecl = ctx.options.skipInDeclarations;
53
+ const skipArrayIndex = ctx.options.ignoreArrayIndexes;
54
+ const sf = asTsMorphSourceFile(ctx.parsed);
55
+ const findings = [];
56
+ sf.forEachDescendant((node) => {
57
+ if (!Node.isNumericLiteral(node)) return;
58
+ const raw = node.getText();
59
+ const value = Number(raw);
60
+ if (!Number.isFinite(value)) return;
61
+ if (whitelist.has(value)) return;
62
+ if (skipInDecl && isInNamedDeclaration(node)) return;
63
+ if (skipArrayIndex && isArrayIndex(node)) return;
64
+ const { line, column } = sf.getLineAndColumnAtPos(node.getStart());
65
+ findings.push({
66
+ message: `Magic number ${raw} \u2014 c\xE2n nh\u1EAFc \u0111\u1EB7t t\xEAn constant \u0111\u1EC3 code r\xF5 ngh\u0129a h\u01A1n.`,
67
+ file: ctx.file.path,
68
+ range: { line, column },
69
+ suggestion: `Tr\xEDch ra th\xE0nh const t\xEAn \u0111\u1EA7y \u0111\u1EE7, vd \`const DAY_IN_MS = ${raw};\`.`
70
+ });
71
+ });
72
+ return findings;
73
+ }
74
+ };
75
+
76
+ export { rule };
77
+ //# sourceMappingURL=no-magic-number.rule.js.map
78
+ //# sourceMappingURL=no-magic-number.rule.js.map
@@ -0,0 +1,46 @@
1
+ // builtin-rules/static/general/no-open-redirect.rule.ts
2
+ var OPEN_REDIRECT_SINK_IDS = /* @__PURE__ */ new Set([
3
+ "general/location-redirect",
4
+ "angular/router-navigate"
5
+ ]);
6
+ var SINK_LABEL = {
7
+ "general/location-redirect": "location.href / window.location",
8
+ "angular/router-navigate": "Router.navigateByUrl"
9
+ };
10
+ var rule = {
11
+ id: "general/no-open-redirect",
12
+ version: 1,
13
+ kind: "static-ts",
14
+ title: "Kh\xF4ng \u0111i\u1EC1u h\u01B0\u1EDBng t\u1EDBi URL ch\u01B0a ki\u1EC3m so\xE1t (location.href / window.location / Router.navigateByUrl)",
15
+ description: "D\u1EEF li\u1EC7u t\u1EEB URL/ng\u01B0\u1EDDi d\xF9ng (query params, ActivatedRoute, location.*, document.referrer, \u2026) ch\u1EA3y th\u1EB3ng v\xE0o \u0111\xEDch \u0111i\u1EC1u h\u01B0\u1EDBng (g\xE1n `location.href` / `window.location`, ho\u1EB7c `Router.navigateByUrl(...)`) m\xE0 kh\xF4ng ki\u1EC3m tra l\xE0 l\u1ED7 h\u1ED5ng Open Redirect \u2014 k\u1EBB t\u1EA5n c\xF4ng c\xF3 th\u1EC3 l\u1EEBa ng\u01B0\u1EDDi d\xF9ng chuy\u1EC3n sang site l\u1EEBa \u0111\u1EA3o. Rule d\xF9ng taint analysis (Tier-2 li\xEAn h\xE0m/li\xEAn file) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u. Kh\u1EAFc ph\u1EE5c: ki\u1EC3m tra URL v\u1EDBi allow-list (ch\u1EC9 cho ph\xE9p \u0111\u01B0\u1EDDng d\u1EABn n\u1ED9i b\u1ED9 / host tin c\u1EADy) tr\u01B0\u1EDBc khi \u0111i\u1EC1u h\u01B0\u1EDBng.",
16
+ severity: "warning",
17
+ category: "security",
18
+ languages: ["typescript"],
19
+ scope: "general",
20
+ requires: "syntactic",
21
+ usesTaint: true,
22
+ usesAstGraph: true,
23
+ baseConfidence: 75,
24
+ check(ctx) {
25
+ const findings = [];
26
+ for (const tf of ctx.taintFindings ?? []) {
27
+ if (!OPEN_REDIRECT_SINK_IDS.has(tf.sinkId)) continue;
28
+ const sources = [...new Set(tf.sourceIds)].join(", ");
29
+ const laundered = (tf.path?.length ?? 0) > 0;
30
+ const sinkLabel = SINK_LABEL[tf.sinkId] ?? tf.sinkId;
31
+ const trace = laundered ? " (truy v\u1EBFt li\xEAn h\xE0m/li\xEAn file)" : "";
32
+ findings.push({
33
+ message: `\u26A0 Open Redirect: d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (${sources}) ch\u1EA3y v\xE0o ${sinkLabel} m\xE0 kh\xF4ng ki\u1EC3m tra \u2014 nguy c\u01A1 \u0111i\u1EC1u h\u01B0\u1EDBng t\u1EDBi site \u0111\u1ED9c h\u1EA1i.${trace}`,
34
+ file: ctx.file.path,
35
+ range: { line: tf.line, column: tf.column ?? 1 },
36
+ confidence: laundered ? 70 : 80,
37
+ suggestion: "Ki\u1EC3m tra URL tr\u01B0\u1EDBc khi \u0111i\u1EC1u h\u01B0\u1EDBng: d\xF9ng allow-list host/\u0111\u01B0\u1EDDng d\u1EABn n\u1ED9i b\u1ED9, t\u1EEB ch\u1ED1i URL tuy\u1EC7t \u0111\u1ED1i (`http(s)://`, `//`) ho\u1EB7c ch\u1EC9 \u0111i\u1EC1u h\u01B0\u1EDBng b\u1EB1ng route name c\u1ED1 \u0111\u1ECBnh. Tr\xE1nh g\xE1n tr\u1EF1c ti\u1EBFp location.href / window.location hay g\u1ECDi Router.navigateByUrl v\u1EDBi gi\xE1 tr\u1ECB t\u1EEB URL/ng\u01B0\u1EDDi d\xF9ng."
38
+ });
39
+ }
40
+ return findings;
41
+ }
42
+ };
43
+
44
+ export { rule };
45
+ //# sourceMappingURL=no-open-redirect.rule.js.map
46
+ //# sourceMappingURL=no-open-redirect.rule.js.map
@@ -0,0 +1,30 @@
1
+ id: general/no-todo-comment
2
+ version: 1
3
+ kind: static-yaml
4
+ title: "Không để TODO/FIXME/HACK/XXX trong code đã commit"
5
+ description: |
6
+ TODO comments không phải là cách tracking công việc — chúng tích tụ và bị quên.
7
+ Hãy tạo issue trong tracker (Jira/Linear), commit code đã hoàn thành, và để comment
8
+ giải thích "tại sao" thay vì "còn thiếu gì". Rule này flag mọi comment chứa
9
+ TODO, FIXME, HACK, XXX (không phân biệt hoa thường).
10
+ severity: info
11
+ category: maintainability
12
+ languages: [typescript, javascript]
13
+ scope: general
14
+ baseConfidence: 100
15
+ detection:
16
+ type: tree-sitter
17
+ captureName: violation
18
+ query: |
19
+ (comment) @violation
20
+ (#match? @violation "\\b([Tt][Oo][Dd][Oo]|[Ff][Ii][Xx][Mm][Ee]|[Hh][Aa][Cc][Kk]|XXX|xxx)\\b")
21
+ message: "Comment chứa TODO/FIXME/HACK/XXX — tạo issue trong tracker thay vì để trong code."
22
+ suggestion: "Tạo ticket trong Jira/Linear với context cụ thể, xoá comment khi đã có ticket."
23
+ examples:
24
+ good: |
25
+ // Cache layer luôn invalidate khi project changes — xem ADR-0007 để hiểu vì sao.
26
+ const cache = createCache();
27
+ bad: |
28
+ // TODO: handle errors here
29
+ // FIXME: this breaks when user is null
30
+ function process() {}