loadwise 0.7.0 → 0.8.0

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 (228) hide show
  1. package/README.md +23 -15
  2. package/dist/bin/loadwise.js +12 -24
  3. package/dist/lib/accessibility/analyze.js +5 -3
  4. package/dist/lib/accessibility/angular-inline.js +9 -11
  5. package/dist/lib/accessibility/angular-literal.js +39 -0
  6. package/dist/lib/accessibility/form-context.js +36 -0
  7. package/dist/lib/accessibility/frame-head.js +92 -0
  8. package/dist/lib/accessibility/frame-viewport.js +149 -0
  9. package/dist/lib/accessibility/jsx-elements.js +13 -3
  10. package/dist/lib/accessibility/markup-files.js +7 -2
  11. package/dist/lib/accessibility/rule-ids.js +3 -0
  12. package/dist/lib/accessibility/rules.js +128 -41
  13. package/dist/lib/accessibility/site-fixes/buttons.js +5 -1
  14. package/dist/lib/accessibility/template-attributes.js +5 -3
  15. package/dist/lib/accessibility/template-elements.js +25 -6
  16. package/dist/lib/accessibility/template-file.js +40 -25
  17. package/dist/lib/editor/accessibility-examples.js +6 -1
  18. package/dist/lib/editor/actions.js +46 -7
  19. package/dist/lib/editor/apply-fix.js +69 -4
  20. package/dist/lib/editor/configured-setup.js +5 -3
  21. package/dist/lib/editor/diagnostics.js +206 -17
  22. package/dist/lib/editor/dismissals.js +85 -26
  23. package/dist/lib/editor/editor-document.js +5 -2
  24. package/dist/lib/editor/editor-launcher.js +7 -2
  25. package/dist/lib/editor/language-server.js +64 -25
  26. package/dist/lib/editor/native-setup.js +3 -2
  27. package/dist/lib/editor/perf-watch.js +8 -6
  28. package/dist/lib/editor/reliability-examples.js +15 -0
  29. package/dist/lib/editor/scan-session.js +29 -8
  30. package/dist/lib/editor/server-commands.js +36 -9
  31. package/dist/lib/editor/setup-server.js +1 -1
  32. package/dist/lib/editor/setup-vim.js +6 -4
  33. package/dist/lib/editor/workspace-files.js +61 -7
  34. package/dist/lib/editor/workspace-paths.js +41 -1
  35. package/dist/lib/maintainability/analysis/analyze-source.js +1 -1
  36. package/dist/lib/maintainability/architecture/architecture.js +4 -4
  37. package/dist/lib/maintainability/cli/changed-lines.js +20 -2
  38. package/dist/lib/maintainability/cli/inputs.js +9 -1
  39. package/dist/lib/maintainability/cli.js +4 -0
  40. package/dist/lib/maintainability/entry-points/entry-points.js +44 -15
  41. package/dist/lib/maintainability/entry-points/html-entry-points.js +5 -1
  42. package/dist/lib/maintainability/quality/functions.js +9 -6
  43. package/dist/lib/maintainability/quality/limits.js +19 -0
  44. package/dist/lib/maintainability/quality/size-limits.js +8 -2
  45. package/dist/lib/maintainability/quality/stray-console.js +62 -1
  46. package/dist/lib/maintainability/quality/tsconfig-strict.js +2 -0
  47. package/dist/lib/maintainability/scan-changed.js +4 -1
  48. package/dist/lib/maintainability/scan-worker.js +6 -2
  49. package/dist/lib/maintainability/scan.js +21 -8
  50. package/dist/lib/maintainability/unused/module-usage.js +43 -21
  51. package/dist/lib/maintainability/unused/unused-modules.js +5 -10
  52. package/dist/lib/performance/analysis/source-inputs.js +7 -2
  53. package/dist/lib/performance/analysis/source-options.js +7 -6
  54. package/dist/lib/performance/analyze.js +16 -3
  55. package/dist/lib/performance/cli/cli-output.js +1 -0
  56. package/dist/lib/performance/cli/cli-scan.js +21 -2
  57. package/dist/lib/performance/cli.js +8 -3
  58. package/dist/lib/performance/collections/memory-growth.js +55 -12
  59. package/dist/lib/performance/contracts/openapi.js +13 -4
  60. package/dist/lib/performance/datastores/pg-integrity.js +61 -22
  61. package/dist/lib/performance/datastores/pg-session-release.js +114 -0
  62. package/dist/lib/performance/datastores/pg-session-sql.js +144 -0
  63. package/dist/lib/performance/datastores/pooling.js +56 -2
  64. package/dist/lib/performance/datastores/redis.js +94 -18
  65. package/dist/lib/performance/datastores/session-store.js +2 -1
  66. package/dist/lib/performance/db/checks.js +19 -8
  67. package/dist/lib/performance/db/gateway.js +3 -1
  68. package/dist/lib/performance/db/plan-estimates.js +4 -4
  69. package/dist/lib/performance/engine/native.js +11 -7
  70. package/dist/lib/performance/evidence/plans.js +7 -5
  71. package/dist/lib/performance/evidence/traces.js +21 -1
  72. package/dist/lib/performance/frontend/angular-teardown.js +96 -0
  73. package/dist/lib/performance/frontend/effect-cleanup.js +148 -0
  74. package/dist/lib/performance/frontend/frontend-dom-perf.js +14 -2
  75. package/dist/lib/performance/frontend/frontend-helpers.js +1 -9
  76. package/dist/lib/performance/frontend/frontend-perf.js +72 -57
  77. package/dist/lib/performance/migrations/extract-code-sql.js +16 -4
  78. package/dist/lib/performance/migrations/extract-code.js +13 -5
  79. package/dist/lib/performance/migrations/extract-sql.js +82 -38
  80. package/dist/lib/performance/migrations/operations.js +56 -13
  81. package/dist/lib/performance/migrations/postgres-lock-timeout.js +52 -0
  82. package/dist/lib/performance/migrations/postgres-registry.js +127 -26
  83. package/dist/lib/performance/migrations/postgres-settings.js +78 -0
  84. package/dist/lib/performance/migrations/rules-postgres-add-column.js +3 -3
  85. package/dist/lib/performance/migrations/rules-postgres-shared.js +9 -0
  86. package/dist/lib/performance/migrations/rules-postgres.js +88 -39
  87. package/dist/lib/performance/orm/offset-pagination.js +6 -4
  88. package/dist/lib/performance/orm/prisma-aggregates.js +69 -18
  89. package/dist/lib/performance/orm/unbounded-list-chain.js +29 -0
  90. package/dist/lib/performance/orm/unbounded-list-queries.js +18 -13
  91. package/dist/lib/performance/polyglot.js +111 -14
  92. package/dist/lib/performance/projects.js +3 -3
  93. package/dist/lib/performance/query-loops/sequential-loops.js +1 -0
  94. package/dist/lib/performance/request/backend-mastery.js +151 -42
  95. package/dist/lib/performance/request/mongoose-lean.js +175 -10
  96. package/dist/lib/performance/request/phase5-rules.js +74 -13
  97. package/dist/lib/performance/request/sql-select-star.js +150 -0
  98. package/dist/lib/performance/request/unbounded-promise-all.js +54 -29
  99. package/dist/lib/performance/request/upload-limits.js +5 -1
  100. package/dist/lib/performance/site-fix.js +4 -4
  101. package/dist/lib/performance/site-fixes/backend-mastery-fixes.js +298 -16
  102. package/dist/lib/performance/site-fixes/frontend-fixes.js +350 -10
  103. package/dist/lib/performance/site-fixes/migration-context.js +8 -1
  104. package/dist/lib/performance/site-fixes/migration-lock-rules.js +66 -30
  105. package/dist/lib/performance/site-fixes/prisma-aggregates.js +29 -9
  106. package/dist/lib/performance/site-fixes/small-rewrites.js +168 -10
  107. package/dist/lib/performance/site-fixes/sync-calls.js +14 -12
  108. package/dist/lib/performance/site-fixes/upload-limits.js +13 -7
  109. package/dist/lib/performance/sql/mysql-tokens.js +38 -12
  110. package/dist/lib/reliability/boundary-access.js +114 -57
  111. package/dist/lib/reliability/react-bugs.js +18 -4
  112. package/dist/lib/reliability/resource-leak-intervals.js +258 -0
  113. package/dist/lib/reliability/resource-leaks.js +209 -195
  114. package/dist/lib/reliability/rule-ids.js +10 -1
  115. package/dist/lib/reliability/site-fixes/resource-leaks.js +16 -1
  116. package/dist/lib/reliability/swallowed-errors.js +107 -21
  117. package/dist/lib/reliability/test-cleanup-after-await.js +92 -18
  118. package/dist/lib/reliability/walk.js +3 -2
  119. package/dist/lib/security/auth-crypto/hashing.js +24 -8
  120. package/dist/lib/security/auth-crypto/jwt.js +21 -6
  121. package/dist/lib/security/auth-crypto/secrets.js +44 -1
  122. package/dist/lib/security/auth-crypto/shared.js +3 -1
  123. package/dist/lib/security/auth-crypto/signing-algorithm.js +79 -0
  124. package/dist/lib/security/auth-crypto/transport-and-ciphers.js +85 -1
  125. package/dist/lib/security/cli.js +6 -2
  126. package/dist/lib/security/cookie-credentials.js +115 -0
  127. package/dist/lib/security/cookie-csrf.js +241 -0
  128. package/dist/lib/security/deps/advisory.js +50 -109
  129. package/dist/lib/security/deps/cli.js +1 -1
  130. package/dist/lib/security/deps/cvss-score.js +14 -0
  131. package/dist/lib/security/deps/fixed-version.js +97 -0
  132. package/dist/lib/security/deps/lockfiles.js +135 -74
  133. package/dist/lib/security/deps/osv.js +11 -3
  134. package/dist/lib/security/deps/scan.js +47 -20
  135. package/dist/lib/security/deps/yarn-lock.js +158 -0
  136. package/dist/lib/security/examples/injection.cjs +4 -0
  137. package/dist/lib/security/exposure/cookies.js +17 -2
  138. package/dist/lib/security/exposure/cors-origin-regex.js +2 -3
  139. package/dist/lib/security/exposure/frontend-security.js +21 -14
  140. package/dist/lib/security/exposure/jsx-url.js +18 -33
  141. package/dist/lib/security/exposure/logging.js +49 -10
  142. package/dist/lib/security/exposure/prototype-pollution.js +126 -56
  143. package/dist/lib/security/exposure/react-html.js +26 -0
  144. package/dist/lib/security/exposure/reflected-xss.js +34 -5
  145. package/dist/lib/security/files/compose.js +126 -1
  146. package/dist/lib/security/files/dockerfile.js +62 -4
  147. package/dist/lib/security/files/index.js +1 -1
  148. package/dist/lib/security/injection/command.js +46 -18
  149. package/dist/lib/security/injection/index.js +2 -0
  150. package/dist/lib/security/injection/ldap.js +86 -0
  151. package/dist/lib/security/injection/nosql.js +28 -4
  152. package/dist/lib/security/injection/redos.js +1 -1
  153. package/dist/lib/security/injection/rule-ids.js +1 -0
  154. package/dist/lib/security/injection/shared.js +5 -1
  155. package/dist/lib/security/injection/sql.js +28 -13
  156. package/dist/lib/security/lexical-declaration.js +113 -0
  157. package/dist/lib/security/pg-dynamic-query.js +28 -1
  158. package/dist/lib/security/pg-identifier-guards.js +107 -3
  159. package/dist/lib/security/phase5-rules.js +26 -135
  160. package/dist/lib/security/polyglot.js +2 -2
  161. package/dist/lib/security/redirect-settings.js +98 -0
  162. package/dist/lib/security/request-forgery/open-redirect.js +18 -5
  163. package/dist/lib/security/request-forgery/path-traversal.js +84 -6
  164. package/dist/lib/security/request-forgery/shared.js +1 -7
  165. package/dist/lib/security/request-forgery/ssrf.js +176 -14
  166. package/dist/lib/security/rule-descriptions.js +5 -1
  167. package/dist/lib/security/rule-ids.js +7 -0
  168. package/dist/lib/security/site-fixes/auth-crypto.js +5 -78
  169. package/dist/lib/security/site-fixes/exposure.js +21 -3
  170. package/dist/lib/security/site-fixes/files.js +11 -13
  171. package/dist/lib/security/site-fixes/frontend-security-fixes.js +2 -2
  172. package/dist/lib/security/site-fixes/injection.js +17 -4
  173. package/dist/lib/security/site-fixes/jwt.js +1 -20
  174. package/dist/lib/security/site-fixes/request-forgery.js +37 -29
  175. package/dist/lib/security/taint/binding-inputs.js +236 -0
  176. package/dist/lib/security/taint/filename-guard.js +45 -45
  177. package/dist/lib/security/taint/guards.js +14 -8
  178. package/dist/lib/security/taint/index.js +126 -154
  179. package/dist/lib/security/taint/propagate.js +43 -9
  180. package/dist/lib/security/taint/record-writes.js +161 -0
  181. package/dist/lib/security/taint/resolution-cache.js +13 -7
  182. package/dist/lib/security/taint/sanitizers.js +89 -5
  183. package/dist/lib/security/taint/trace-nodes.js +61 -0
  184. package/dist/lib/security/taint/validators.js +89 -9
  185. package/dist/lib/shared/agent/agent-init.js +2 -1
  186. package/dist/lib/shared/agent/agent-verify.js +4 -1
  187. package/dist/lib/shared/agent/git-hook.js +17 -6
  188. package/dist/lib/shared/agent/review-mcp.js +8 -2
  189. package/dist/lib/shared/analysis/ast-semantics.js +2 -2
  190. package/dist/lib/shared/analysis/scan-cache.js +96 -12
  191. package/dist/lib/shared/cli-dispatch.js +17 -0
  192. package/dist/lib/shared/config.js +27 -10
  193. package/dist/lib/shared/explain.js +1 -1
  194. package/dist/lib/shared/fix/fix-convergence.js +5 -3
  195. package/dist/lib/shared/fix/fix-imports.js +4 -171
  196. package/dist/lib/shared/fix/fix-presentation-comments.js +23 -9
  197. package/dist/lib/shared/fix/fix-presentation.js +5 -3
  198. package/dist/lib/shared/fix/fix-safety.js +7 -1
  199. package/dist/lib/shared/fix/fix-typecheck.js +8 -4
  200. package/dist/lib/shared/fix/import-text-edits.js +148 -0
  201. package/dist/lib/shared/fix.js +31 -7
  202. package/dist/lib/shared/formats/finding-location.js +4 -1
  203. package/dist/lib/shared/formats/github.js +3 -3
  204. package/dist/lib/shared/formats/sarif.js +9 -3
  205. package/dist/lib/shared/report-fp.js +6 -2
  206. package/dist/lib/shared/reporting/baseline.js +7 -5
  207. package/dist/lib/shared/reporting/pillars.js +9 -3
  208. package/dist/lib/shared/reporting/source-report.js +1 -0
  209. package/dist/lib/shared/system/glob.js +34 -8
  210. package/dist/lib/shared/system/sentry.js +26 -7
  211. package/dist/lib/shared/workspaces.js +15 -3
  212. package/package.json +5 -1
  213. package/plugin/.claude-plugin/plugin.json +1 -1
  214. package/plugin/hooks/check-edited-file.mjs +27 -5
  215. package/polyglot/performance/rules/csharp.yml +34 -5
  216. package/polyglot/performance/rules/java.yml +24 -1
  217. package/polyglot/performance/rules/python.yml +74 -2
  218. package/polyglot/performance/sgconfig.yml +1 -0
  219. package/polyglot/reliability/rules/csharp.yml +12 -6
  220. package/polyglot/reliability/rules/go.yml +86 -6
  221. package/polyglot/reliability/rules/java.yml +22 -1
  222. package/polyglot/reliability/sgconfig.yml +1 -0
  223. package/polyglot/security/rules/go.yml +100 -22
  224. package/polyglot/security/rules/python.yml +74 -6
  225. package/polyglot/security/rules/rust.yml +65 -0
  226. package/polyglot/security/sgconfig.yml +1 -0
  227. package/schema/loadwise.config.schema.json +554 -76
  228. /package/polyglot/{performance/rules → shared-rules}/input.yml +0 -0
@@ -73,8 +73,14 @@ function findingsFor(report, relativeFile, checkerCommand) {
73
73
  .map((finding) => ({ ...finding, checkerCommand }));
74
74
  }
75
75
 
76
+ function quoteTarget(relativeFile, platform = process.platform) {
77
+ const normalized = './' + relativeFile.split(path.sep).join('/');
78
+ if (platform === 'win32') return "'" + normalized.replaceAll("'", "''") + "'";
79
+ return "'" + normalized.replaceAll("'", "'\\''") + "'";
80
+ }
81
+
76
82
  function formatFeedback(projectRoot, relativeFile, findings) {
77
- const sourceArgument = "'./" + relativeFile.split(path.sep).join('/').replaceAll("'", "'\\''") + "'";
83
+ const sourceArgument = quoteTarget(relativeFile);
78
84
  const lines = findings.map((finding) => {
79
85
  const target = finding.checkerCommand === 'maint' ? '.' : sourceArgument;
80
86
  const action = finding.fixable
@@ -104,6 +110,15 @@ function sourceFindings(local, relativeFile, safeRelativeFile, deadline) {
104
110
  ];
105
111
  }
106
112
 
113
+ function hasInlineTemplate(filename) {
114
+ try {
115
+ return fs.readFileSync(filename, 'utf8').includes('@Component');
116
+ } catch {
117
+ // Each source checker can report its own coverage even if the optional template probe fails.
118
+ return false;
119
+ }
120
+ }
121
+
107
122
  function main() {
108
123
  const input = JSON.parse(readStdin());
109
124
  const filePath = input?.tool_input?.file_path;
@@ -111,9 +126,13 @@ function main() {
111
126
  const extension = path.extname(filePath).toLowerCase();
112
127
  const isSourceFile = SOURCE_EXTENSIONS.has(extension);
113
128
  if (!isSourceFile && !MARKUP_EXTENSIONS.has(extension)) return;
114
- const workspaceRoot = path.resolve(input?.cwd ?? process.cwd());
115
- const absoluteFile = path.resolve(workspaceRoot, filePath);
116
- if (!fs.existsSync(absoluteFile)) return;
129
+ const suppliedRoot = path.resolve(input?.cwd ?? process.cwd());
130
+ const suppliedFile = path.resolve(suppliedRoot, filePath);
131
+ if (path.relative(suppliedRoot, suppliedFile).split(path.sep).includes('node_modules')) return;
132
+ // The client can send the folder and the edited file through different spellings of one path.
133
+ const workspaceRoot = fs.realpathSync.native(suppliedRoot);
134
+ const absoluteFile = fs.realpathSync.native(suppliedFile);
135
+ if (path.relative(workspaceRoot, absoluteFile).split(path.sep).includes('node_modules')) return;
117
136
  const local = findLocalBinary(path.dirname(absoluteFile), workspaceRoot);
118
137
  if (!local) return;
119
138
  const relativeFile = path.relative(local.projectRoot, absoluteFile);
@@ -127,9 +146,12 @@ function main() {
127
146
  const parsedTimeout = Number(process.env.LOADWISE_HOOK_TIMEOUT_MS);
128
147
  const timeoutMs = Number.isFinite(parsedTimeout) && parsedTimeout > 0 ? parsedTimeout : DEFAULT_TIMEOUT_MS;
129
148
  const deadline = Date.now() + timeoutMs;
149
+ // Match the accessibility analyzer's inline Angular template prefilter for script extensions.
150
+ const checkAccessibility =
151
+ ACCESSIBILITY_EXTENSIONS.has(extension) || (isSourceFile && hasInlineTemplate(absoluteFile));
130
152
  const findings = [
131
153
  ...(isSourceFile ? sourceFindings(local, relativeFile, safeRelativeFile, deadline) : []),
132
- ...(ACCESSIBILITY_EXTENSIONS.has(extension)
154
+ ...(checkAccessibility
133
155
  ? findingsFor(
134
156
  runLoadwise(local.binary, ['a11y', safeRelativeFile, '--json'], local.projectRoot, deadline),
135
157
  relativeFile,
@@ -9,8 +9,11 @@ rule:
9
9
  all:
10
10
  - any:
11
11
  - pattern: new System.Text.RegularExpressions.Regex($PAT)
12
+ - pattern: new System.Text.RegularExpressions.Regex($PAT, $FLAGS)
12
13
  - all:
13
- - pattern: new Regex($PAT)
14
+ - any:
15
+ - pattern: new Regex($PAT)
16
+ - pattern: new Regex($PAT, $FLAGS)
14
17
  - inside:
15
18
  kind: compilation_unit
16
19
  stopBy: end
@@ -44,6 +47,27 @@ constraints:
44
47
  any:
45
48
  - kind: string_literal
46
49
  - kind: verbatim_string_literal
50
+ FLAGS:
51
+ kind: argument
52
+ not:
53
+ any:
54
+ - has: { kind: invocation_expression, stopBy: end }
55
+ - has: { kind: conditional_expression, stopBy: end }
56
+ - has:
57
+ stopBy: end
58
+ kind: identifier
59
+ not:
60
+ any:
61
+ - regex: '^(System|Text|RegularExpressions)$'
62
+ - all:
63
+ - regex: '^RegexOptions$'
64
+ - inside:
65
+ kind: member_access_expression
66
+ field: expression
67
+ - inside:
68
+ kind: member_access_expression
69
+ field: name
70
+ has: { field: expression, regex: '(^|\.)RegexOptions$' }
47
71
 
48
72
  ---
49
73
  id: csharp-string-concat-in-loop
@@ -86,10 +110,15 @@ rule:
86
110
  context: 'class C { void M() { $ACC = $ACC + $LIT; } }'
87
111
  selector: assignment_expression
88
112
  - has:
89
- stopBy: end
90
- any:
91
- - kind: string_literal
92
- - kind: interpolated_string_expression
113
+ field: right
114
+ has:
115
+ stopBy:
116
+ any:
117
+ - kind: bracketed_argument_list
118
+ - kind: argument_list
119
+ any:
120
+ - kind: string_literal
121
+ - kind: interpolated_string_expression
93
122
  - inside:
94
123
  kind: method_declaration
95
124
  stopBy: end
@@ -9,8 +9,11 @@ rule:
9
9
  all:
10
10
  - any:
11
11
  - pattern: java.util.regex.Pattern.compile($PAT)
12
+ - pattern: java.util.regex.Pattern.compile($PAT, $FLAGS)
12
13
  - all:
13
- - pattern: Pattern.compile($PAT)
14
+ - any:
15
+ - pattern: Pattern.compile($PAT)
16
+ - pattern: Pattern.compile($PAT, $FLAGS)
14
17
  - inside:
15
18
  kind: program
16
19
  stopBy: end
@@ -45,6 +48,26 @@ rule:
45
48
  constraints:
46
49
  PAT:
47
50
  kind: string_literal
51
+ FLAGS:
52
+ not:
53
+ any:
54
+ - has: { kind: method_invocation, stopBy: end }
55
+ - has: { kind: ternary_expression, stopBy: end }
56
+ - kind: identifier
57
+ - has:
58
+ stopBy: end
59
+ kind: identifier
60
+ not:
61
+ any:
62
+ - regex: '^(java|util|regex|Pattern)$'
63
+ - inside:
64
+ kind: field_access
65
+ field: field
66
+ has: { field: object, pattern: Pattern }
67
+ - inside:
68
+ kind: field_access
69
+ field: field
70
+ has: { field: object, pattern: java.util.regex.Pattern }
48
71
 
49
72
  ---
50
73
  id: java-string-concat-in-loop
@@ -53,11 +53,55 @@ rule:
53
53
  - pattern: requests.patch($$$ARGS)
54
54
  - pattern: requests.delete($$$ARGS)
55
55
  - pattern: requests.request($$$ARGS)
56
+ - inside:
57
+ kind: module
58
+ stopBy: end
59
+ has:
60
+ kind: import_statement
61
+ stopBy: end
62
+ all:
63
+ - not:
64
+ has:
65
+ kind: aliased_import
66
+ has: { field: name, regex: '^requests$' }
67
+ - has:
68
+ kind: dotted_name
69
+ regex: '^requests$'
56
70
  - inside:
57
71
  kind: function_definition
58
72
  regex: '^async\s'
59
73
  stopBy:
60
74
  kind: function_definition
75
+ - not:
76
+ inside:
77
+ kind: function_definition
78
+ stopBy: end
79
+ any:
80
+ - has:
81
+ field: parameters
82
+ has: { kind: identifier, regex: '^requests$', stopBy: end }
83
+ - has:
84
+ field: body
85
+ has:
86
+ kind: assignment
87
+ has:
88
+ field: left
89
+ any:
90
+ - kind: identifier
91
+ regex: '^requests$'
92
+ - any:
93
+ - kind: pattern_list
94
+ - kind: tuple_pattern
95
+ - kind: list_pattern
96
+ has: { kind: identifier, regex: '^requests$' }
97
+ stopBy:
98
+ any:
99
+ - kind: function_definition
100
+ - kind: class_definition
101
+ stopBy:
102
+ any:
103
+ - kind: function_definition
104
+ - kind: class_definition
61
105
 
62
106
  ---
63
107
  id: python-blocking-sleep-in-async
@@ -92,7 +136,13 @@ labels:
92
136
  message: This loop compiles a fixed regex for each iteration. Compile it once outside the loop and reuse the pattern.
93
137
  rule:
94
138
  all:
95
- - pattern: re.compile($PAT)
139
+ - any:
140
+ - pattern: re.compile($PAT)
141
+ - pattern: re.compile($PAT, flags=$FLAGS)
142
+ - all:
143
+ - pattern: re.compile($PAT, $FLAGS)
144
+ - not:
145
+ pattern: re.compile($PAT, $K=$V)
96
146
  - inside:
97
147
  kind: module
98
148
  stopBy: end
@@ -115,6 +165,26 @@ rule:
115
165
  constraints:
116
166
  PAT:
117
167
  kind: string
168
+ not:
169
+ has: { kind: interpolation, stopBy: end }
170
+ FLAGS:
171
+ not:
172
+ any:
173
+ - has: { kind: call, stopBy: end }
174
+ - has: { kind: conditional_expression, stopBy: end }
175
+ - all:
176
+ - kind: identifier
177
+ - not: { regex: '^re$' }
178
+ - has:
179
+ stopBy: end
180
+ kind: identifier
181
+ not:
182
+ any:
183
+ - regex: '^re$'
184
+ - inside:
185
+ kind: attribute
186
+ field: attribute
187
+ has: { field: object, kind: identifier, regex: '^re$' }
118
188
 
119
189
  ---
120
190
  id: python-n-plus-one-orm-loop
@@ -146,10 +216,12 @@ rule:
146
216
  id: python-unbounded-comprehension
147
217
  language: Python
148
218
  severity: warning
149
- message: Materializing a list comprehension inside an aggregation allocates the full list in memory. Use a generator expression instead.
219
+ message: Materializing a list comprehension inside an aggregation allocates the full list in memory. Use a generator expression (parenthesized if a second argument such as `start` follows) instead; only do so when evaluating `start` does not affect the iterated data or any other state the comprehension reads (for example `items.pop()`), because the generator defers iteration until after `start` is evaluated.
150
220
  rule:
151
221
  any:
152
222
  - pattern: sum($COMP)
223
+ - pattern: sum($COMP, $START)
224
+ - pattern: sum($COMP, start=$START)
153
225
  - pattern: any($COMP)
154
226
  - pattern: all($COMP)
155
227
  - pattern: min($COMP)
@@ -1,5 +1,6 @@
1
1
  ruleDirs:
2
2
  - rules
3
+ - ../shared-rules
3
4
  languageGlobs:
4
5
  Python: ['*.[pP][yY]']
5
6
  Go: ['*.[gG][oO]']
@@ -17,7 +17,7 @@ rule:
17
17
  - has:
18
18
  kind: parameter
19
19
  nthChild: 2
20
- has: { field: type, regex: 'EventArgs$' }
20
+ has: { field: type, regex: 'EventArgs\??$' }
21
21
  - not: { has: { kind: parameter, nthChild: 3 } }
22
22
 
23
23
  ---
@@ -40,11 +40,17 @@ rule:
40
40
  kind: variable_declarator
41
41
  all:
42
42
  - has: { field: name, pattern: $VAR }
43
- - has:
44
- kind: object_creation_expression
45
- has:
46
- field: type
47
- regex: '^(FileStream|StreamReader|StreamWriter|BinaryReader|BinaryWriter|SqlConnection|NpgsqlConnection|MySqlConnection|SqliteConnection)$'
43
+ - any:
44
+ - has:
45
+ kind: object_creation_expression
46
+ has:
47
+ field: type
48
+ regex: &disposableType '^(?:(?:global::)?System\.IO\.)?(FileStream|StreamReader|StreamWriter|BinaryReader|BinaryWriter)$|^(?:(?:global::)?(?:System|Microsoft)\.Data\.SqlClient\.)?SqlConnection$|^(?:(?:global::)?Npgsql\.)?NpgsqlConnection$|^(?:(?:global::)?(?:MySqlConnector|MySql\.Data\.MySqlClient)\.)?MySqlConnection$|^(?:(?:global::)?Microsoft\.Data\.Sqlite\.)?SqliteConnection$'
49
+ - all:
50
+ - has: { kind: implicit_object_creation_expression }
51
+ - inside:
52
+ kind: variable_declaration
53
+ has: { field: type, regex: *disposableType }
48
54
  - not:
49
55
  precedes:
50
56
  stopBy: end
@@ -4,6 +4,31 @@ language: Go
4
4
  severity: warning
5
5
  message: This assignment drops the error result with _, so a failure goes unnoticed. Check the error and return or log it.
6
6
  ignores: ['**/*_test.go']
7
+ utils:
8
+ selector-extra-signature-shadow:
9
+ inside:
10
+ stopBy: end
11
+ any:
12
+ - has:
13
+ field: receiver
14
+ has: { kind: parameter_declaration, has: { kind: identifier, pattern: $OWNER } }
15
+ - has:
16
+ field: result
17
+ has: { kind: parameter_declaration, has: { kind: identifier, pattern: $OWNER } }
18
+ selector-local-shadow:
19
+ inside:
20
+ kind: block
21
+ stopBy: end
22
+ has:
23
+ kind: statement_list
24
+ has:
25
+ any:
26
+ - all:
27
+ - kind: short_var_declaration
28
+ - has: { field: left, has: { kind: identifier, pattern: $OWNER } }
29
+ - all:
30
+ - kind: var_declaration
31
+ - has: { kind: var_spec, stopBy: end, has: { kind: identifier, pattern: $OWNER } }
7
32
  rule:
8
33
  any:
9
34
  # value, _ := call(...): reported only for an allow-list of calls known to return (T, error): selected stdlib packages,
@@ -49,6 +74,57 @@ rule:
49
74
  has:
50
75
  field: field
51
76
  regex: '^(Write|WriteString|Flush|Sync|Encode|Exec|ExecContext|Commit)$'
77
+ # A single discarded result from these standard APIs is an error. Require the matching
78
+ # import and, for Scan, a visible database/sql receiver type.
79
+ - all:
80
+ - pattern: _ = $OWNER.$METHOD($$$ARGS)
81
+ - any:
82
+ - all:
83
+ - pattern: _ = json.Unmarshal($$$ARGS)
84
+ - inside:
85
+ {
86
+ kind: source_file,
87
+ stopBy: end,
88
+ has: { kind: import_spec, regex: '^"encoding/json"$', stopBy: end },
89
+ }
90
+ - all:
91
+ - pattern: _ = os.WriteFile($$$ARGS)
92
+ - inside: { kind: source_file, stopBy: end, has: { kind: import_spec, regex: '^"os"$', stopBy: end } }
93
+ - not:
94
+ inside:
95
+ any: [{ kind: function_declaration }, { kind: method_declaration }, { kind: func_literal }]
96
+ stopBy: end
97
+ has:
98
+ field: parameters
99
+ has: { kind: parameter_declaration, has: { kind: identifier, pattern: $OWNER } }
100
+ - not: { matches: selector-local-shadow }
101
+ - not: { matches: selector-extra-signature-shadow }
102
+ - all:
103
+ - pattern: _ = $OWNER.Scan($$$ARGS)
104
+ - not: { matches: selector-local-shadow }
105
+ - not: { matches: selector-extra-signature-shadow }
106
+ - inside: { kind: source_file, stopBy: end, has: { kind: import_spec, regex: '^"database/sql"$', stopBy: end } }
107
+ - inside:
108
+ any: [{ kind: function_declaration }, { kind: method_declaration }, { kind: func_literal }]
109
+ stopBy: end
110
+ has:
111
+ field: parameters
112
+ has:
113
+ kind: parameter_declaration
114
+ all:
115
+ - has: { kind: identifier, pattern: $OWNER }
116
+ - has: { field: type, regex: '^\*sql\.(Row|Rows)$' }
117
+ - not:
118
+ inside:
119
+ any: [{ kind: function_declaration }, { kind: method_declaration }, { kind: func_literal }]
120
+ stopBy: end
121
+ has:
122
+ field: parameters
123
+ has:
124
+ kind: parameter_declaration
125
+ all:
126
+ - has: { kind: identifier, pattern: $OWNER }
127
+ - not: { has: { field: type, regex: '^\*sql\.(Row|Rows)$' } }
52
128
 
53
129
  ---
54
130
  id: go-defer-before-error-check
@@ -64,13 +140,17 @@ rule:
64
140
  - pattern: defer $RES.Body.Close()
65
141
  - follows:
66
142
  any:
67
- - pattern: $RES, err := $CALL
68
- - pattern: $RES, err = $CALL
143
+ - pattern: $RES, $ERR := $CALL($$$ARGS)
144
+ - pattern: $RES, $ERR = $CALL($$$ARGS)
69
145
  - all:
70
146
  - pattern: defer $RES.Close()
71
147
  - follows:
72
148
  any:
73
- - pattern: $RES, err := $DB.Query($$$ARGS)
74
- - pattern: $RES, err = $DB.Query($$$ARGS)
75
- - pattern: $RES, err := $DB.QueryContext($$$ARGS)
76
- - pattern: $RES, err = $DB.QueryContext($$$ARGS)
149
+ - pattern: $RES, $ERR := $DB.Query($$$ARGS)
150
+ - pattern: $RES, $ERR = $DB.Query($$$ARGS)
151
+ - pattern: $RES, $ERR := $DB.QueryContext($$$ARGS)
152
+ - pattern: $RES, $ERR = $DB.QueryContext($$$ARGS)
153
+ constraints:
154
+ ERR:
155
+ not:
156
+ regex: '^_$'
@@ -28,7 +28,28 @@ rule:
28
28
  stopBy: end
29
29
  any:
30
30
  - kind: try_statement
31
- has: { kind: finally_clause, has: { stopBy: end, pattern: $VAR } }
31
+ has:
32
+ kind: finally_clause
33
+ has:
34
+ stopBy: end
35
+ any:
36
+ - pattern: $VAR.close()
37
+ - kind: method_invocation
38
+ all:
39
+ - has: { field: name, regex: '(?i)^close' }
40
+ - has:
41
+ field: arguments
42
+ has: { pattern: $VAR }
43
+ - kind: try_with_resources_statement
44
+ has:
45
+ kind: resource_specification
46
+ has: { stopBy: end, pattern: $VAR }
47
+ - kind: return_statement
48
+ has: { stopBy: end, pattern: $VAR }
49
+ - has:
50
+ stopBy: end
51
+ kind: assignment_expression
52
+ has: { field: right, pattern: $VAR }
32
53
  - kind: try_with_resources_statement
33
54
  has:
34
55
  kind: resource_specification
@@ -1,5 +1,6 @@
1
1
  ruleDirs:
2
2
  - rules
3
+ - ../shared-rules
3
4
  languageGlobs:
4
5
  Python: ['*.[pP][yY]']
5
6
  Go: ['*.[gG][oO]']
@@ -15,28 +15,106 @@ language: Go
15
15
  severity: warning
16
16
  message: Formatting SQL with fmt.Sprintf risks SQL injection. Use parameterized queries with placeholders instead.
17
17
  rule:
18
- all:
19
- - any:
20
- - pattern:
21
- context: 'func check() { _ = $DB.Query($$$QARGS) }'
22
- selector: call_expression
23
- - pattern:
24
- context: 'func check() { _ = $DB.QueryRow($$$QARGS) }'
25
- selector: call_expression
26
- - pattern:
27
- context: 'func check() { _ = $DB.Exec($$$QARGS) }'
28
- selector: call_expression
29
- - pattern:
30
- context: 'func check() { _ = $DB.QueryContext($$$QARGS) }'
31
- selector: call_expression
32
- - pattern:
33
- context: 'func check() { _ = $DB.QueryRowContext($$$QARGS) }'
34
- selector: call_expression
35
- - pattern:
36
- context: 'func check() { _ = $DB.ExecContext($$$QARGS) }'
18
+ any:
19
+ - pattern:
20
+ context: 'func check() { _ = $DB.Query($SQL) }'
21
+ selector: call_expression
22
+ - pattern:
23
+ context: 'func check() { _ = $DB.Query($SQL, $$$QARGS) }'
24
+ selector: call_expression
25
+ - pattern:
26
+ context: 'func check() { _ = $DB.QueryRow($SQL) }'
27
+ selector: call_expression
28
+ - pattern:
29
+ context: 'func check() { _ = $DB.QueryRow($SQL, $$$QARGS) }'
30
+ selector: call_expression
31
+ - pattern:
32
+ context: 'func check() { _ = $DB.Exec($SQL) }'
33
+ selector: call_expression
34
+ - pattern:
35
+ context: 'func check() { _ = $DB.Exec($SQL, $$$QARGS) }'
36
+ selector: call_expression
37
+ - pattern:
38
+ context: 'func check() { _ = $DB.QueryContext($CTX, $SQL) }'
39
+ selector: call_expression
40
+ - pattern:
41
+ context: 'func check() { _ = $DB.QueryContext($CTX, $SQL, $$$QARGS) }'
42
+ selector: call_expression
43
+ - pattern:
44
+ context: 'func check() { _ = $DB.QueryRowContext($CTX, $SQL) }'
45
+ selector: call_expression
46
+ - pattern:
47
+ context: 'func check() { _ = $DB.QueryRowContext($CTX, $SQL, $$$QARGS) }'
48
+ selector: call_expression
49
+ - pattern:
50
+ context: 'func check() { _ = $DB.ExecContext($CTX, $SQL) }'
51
+ selector: call_expression
52
+ - pattern:
53
+ context: 'func check() { _ = $DB.ExecContext($CTX, $SQL, $$$QARGS) }'
54
+ selector: call_expression
55
+ constraints:
56
+ SQL:
57
+ any:
58
+ - pattern:
59
+ context: 'func check() { _ = fmt.Sprintf($$$FMTARGS) }'
60
+ selector: call_expression
61
+ - has:
62
+ pattern:
63
+ context: 'func check() { _ = fmt.Sprintf($$$FMTARGS) }'
37
64
  selector: call_expression
65
+ stopBy: end
66
+
67
+ ---
68
+ id: go-tls-insecure-skip-verify
69
+ language: Go
70
+ severity: warning
71
+ message: Setting InsecureSkipVerify to true on tls.Config disables TLS certificate verification. Enable verification or configure an explicit RootCAs trust store.
72
+ ignores:
73
+ - '**/*_test.go'
74
+ - '**/tests/**'
75
+ - '**/test/**'
76
+ rule:
77
+ all:
78
+ - pattern: tls.Config{$$$FIELDS}
38
79
  - has:
39
- pattern:
40
- context: 'func check() { _ = fmt.Sprintf($$$ARGS) }'
41
- selector: call_expression
80
+ kind: literal_value
81
+ has:
82
+ kind: keyed_element
83
+ regex: '^InsecureSkipVerify\s*:\s*true$'
84
+ - not:
85
+ has:
86
+ kind: literal_value
87
+ has:
88
+ kind: keyed_element
89
+ regex: '^(VerifyPeerCertificate|VerifyConnection)\s*:'
90
+ - inside:
91
+ kind: source_file
42
92
  stopBy: end
93
+ all:
94
+ - has:
95
+ stopBy: end
96
+ kind: import_spec
97
+ regex: '"crypto/tls"$'
98
+ - not:
99
+ has:
100
+ stopBy: end
101
+ all:
102
+ - kind: import_spec
103
+ regex: '^tls\s+"'
104
+ - not:
105
+ regex: '^tls\s+"crypto/tls"$'
106
+ - not:
107
+ inside:
108
+ stopBy: end
109
+ all:
110
+ - any:
111
+ - pattern: $CFG := &tls.Config{$$$FIELDS}
112
+ - pattern: $CFG := tls.Config{$$$FIELDS}
113
+ - pattern: $CFG = &tls.Config{$$$FIELDS}
114
+ - pattern: $CFG = tls.Config{$$$FIELDS}
115
+ - precedes:
116
+ stopBy: end
117
+ any:
118
+ - pattern: $CFG.VerifyPeerCertificate = $VAL
119
+ - pattern: $CFG.VerifyConnection = $VAL
120
+ - pattern: $CFG.InsecureSkipVerify = false