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
@@ -1,5 +1,6 @@
1
1
  import { ts } from '../performance/engine/compiler.js';
2
2
  import { analyzeFragment } from '../performance/datastores/pg-fragments.js';
3
+ import { importedFrom } from './bindings.js';
3
4
  // A wildcard, negated class, whitespace, broad escape (\S, \x, \u, \p), quote or semicolon could
4
5
  // let SQL syntax through.
5
6
  const openAlphabet = /[.'"`;\s]|\[\^|\\[SWDsbxupP]/;
@@ -146,10 +147,113 @@ function isValidatedIdentifier(identifier, call, checker) {
146
147
  }
147
148
  return false;
148
149
  }
149
- // True when every runtime part of the SQL text is an identifier validated before the query runs.
150
- function allRuntimePartsValidated(query, call, checker) {
150
+ function resolveAliasedSymbol(symbol, checker) {
151
+ return symbol && symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
152
+ }
153
+ function isPgSourceDeclaration(node) {
154
+ const file = node.getSourceFile().fileName.replaceAll('\\', '/');
155
+ return /(?:^|\/)node_modules\/(?:@types\/)?pg(?:\/|$)/.test(file);
156
+ }
157
+ function isPgReceiver(expression, checker) {
158
+ const receiver = ts.skipOuterExpressions(expression);
159
+ if (!ts.isIdentifier(receiver))
160
+ return false;
161
+ const binding = importedFrom(receiver, checker);
162
+ if (binding?.module === 'pg')
163
+ return !binding.exported || binding.exported === 'default';
164
+ // A local re-export (`export { default } from 'pg'`) still resolves to the pg package declarations.
165
+ const symbol = checker.getSymbolAtLocation(receiver);
166
+ if (!symbol || !(symbol.flags & ts.SymbolFlags.Alias))
167
+ return false;
168
+ return Boolean(resolveAliasedSymbol(symbol, checker)?.declarations?.some(isPgSourceDeclaration));
169
+ }
170
+ function isPgEscapeIdentifierCall(node, checker, depth = 2) {
171
+ const value = ts.skipOuterExpressions(node);
172
+ if (ts.isIdentifier(value)) {
173
+ if (depth <= 0)
174
+ return false;
175
+ const declaration = resolveAliasedSymbol(checker.getSymbolAtLocation(value), checker)?.valueDeclaration;
176
+ return Boolean(declaration &&
177
+ ts.isVariableDeclaration(declaration) &&
178
+ Boolean(declaration.parent.flags & ts.NodeFlags.Const) &&
179
+ declaration.initializer &&
180
+ isPgEscapeIdentifierCall(declaration.initializer, checker, depth - 1));
181
+ }
182
+ if (!ts.isCallExpression(value) || value.arguments.length !== 1)
183
+ return false;
184
+ const callee = ts.skipOuterExpressions(value.expression);
185
+ if (ts.isPropertyAccessExpression(callee)) {
186
+ if (callee.name.text !== 'escapeIdentifier')
187
+ return false;
188
+ return isPgReceiver(callee.expression, checker);
189
+ }
190
+ if (!ts.isIdentifier(callee))
191
+ return false;
192
+ const target = resolveAliasedSymbol(checker.getSymbolAtLocation(callee), checker);
193
+ if (target?.name === 'escapeIdentifier' && target.declarations?.some(isPgSourceDeclaration))
194
+ return true;
195
+ if (target?.valueDeclaration &&
196
+ ts.isVariableDeclaration(target.valueDeclaration) &&
197
+ Boolean(target.valueDeclaration.parent.flags & ts.NodeFlags.Const) &&
198
+ target.valueDeclaration.initializer) {
199
+ const init = ts.skipOuterExpressions(target.valueDeclaration.initializer);
200
+ if (ts.isPropertyAccessExpression(init) &&
201
+ init.name.text === 'escapeIdentifier' &&
202
+ isPgReceiver(init.expression, checker) &&
203
+ resolveAliasedSymbol(checker.getSymbolAtLocation(init.name), checker)?.declarations?.some(isPgSourceDeclaration)) {
204
+ return true;
205
+ }
206
+ }
207
+ const binding = importedFrom(callee, checker);
208
+ return binding?.module === 'pg' && binding.exported === 'escapeIdentifier';
209
+ }
210
+ // True when the literal SQL text before `target` leaves a single-quoted string open, where identifier
211
+ // escaping does not protect the value.
212
+ function isInsideSingleQuotes(query, target, checker) {
213
+ let open = false;
214
+ let found = false;
215
+ const countQuotes = (text) => {
216
+ if (found)
217
+ return;
218
+ for (const char of text)
219
+ if (char === "'")
220
+ open = !open;
221
+ };
222
+ const visit = (node) => {
223
+ if (found)
224
+ return;
225
+ const value = ts.skipOuterExpressions(node);
226
+ if (value === target)
227
+ found = true;
228
+ else if (ts.isTemplateExpression(value)) {
229
+ countQuotes(value.head.text);
230
+ for (const span of value.templateSpans) {
231
+ visit(span.expression);
232
+ countQuotes(span.literal.text);
233
+ }
234
+ }
235
+ else if (ts.isBinaryExpression(value) && value.operatorToken.kind === ts.SyntaxKind.PlusToken) {
236
+ visit(value.left);
237
+ visit(value.right);
238
+ }
239
+ else {
240
+ // A fixed const prefix resolves to text whose quotes still count.
241
+ const text = analyzeFragment(value, checker);
242
+ if (typeof text === 'string')
243
+ countQuotes(text);
244
+ }
245
+ };
246
+ visit(query);
247
+ return open;
248
+ }
249
+ // True when every runtime part of the SQL text is an identifier validated before the query runs,
250
+ // escaped with node-postgres's `escapeIdentifier`, or satisfies an optional caller-provided exemption
251
+ // (such as a bound placeholder list).
252
+ function allRuntimePartsValidated(query, call, checker, isExtraSafe) {
151
253
  const unknown = operandsOf(query).filter((operand) => analyzeFragment(operand, checker) === undefined);
152
254
  return (unknown.length > 0 &&
153
- unknown.every((operand) => ts.isIdentifier(operand) && isValidatedIdentifier(operand, call, checker)));
255
+ unknown.every((operand) => isExtraSafe?.(operand) ||
256
+ (isPgEscapeIdentifierCall(operand, checker) && !isInsideSingleQuotes(query, operand, checker)) ||
257
+ (ts.isIdentifier(operand) && isValidatedIdentifier(operand, call, checker))));
154
258
  }
155
259
  export { allRuntimePartsValidated, isValidatedIdentifier, isValidation, isClosedAnchoredRegex, isLiteralList, operandsOf, };
@@ -4,32 +4,22 @@ import { ts } from '../performance/engine/compiler.js';
4
4
  import { typeFromPackage } from '../performance/analysis/package-types.js';
5
5
  import { reviewedReason, reviewMarkers } from '../performance/analysis/review-context.js';
6
6
  import { libraryCall } from './bindings.js';
7
+ import { checkExpressCookieAuthCsrf } from './cookie-csrf.js';
8
+ import { checkSsrfRedirectCall } from './redirect-settings.js';
7
9
  import { createFileContext } from './file-context.js';
8
10
  import { createTaint } from './taint/index.js';
9
11
  import { hotPathOf } from '../shared/analysis/hot-path-graph.js';
10
12
  import { resolveImportedBinding, resolveRequiredModule, staticMemberName, unwrapExpression, } from '../shared/analysis/ast-semantics.js';
11
13
  import { constantDeclaration } from './request-forgery/shared.js';
14
+ import { findLexicalDeclaration } from './lexical-declaration.js';
12
15
  import { hasVmMemberReplacement } from './vm-module-members.js';
13
16
  const AUTH_CALL_PATTERN = /^(?:getSession|getServerSession|auth|currentUser|requireAuth|verifySession|getAuth|requireSession|requireUser|authenticate|authorize|validateSession|verifyAuth|ensureAuth|checkAuth|withAuth)$/i;
14
17
  const AUTH_HOC_PATTERN = /^(?:withAuth|authAction|authenticatedAction|protectedAction)$/i;
15
- const SSRF_METHODS = new Set(['get', 'post', 'put', 'patch', 'delete', 'head', 'request']);
16
- const URL_GUARD_PATTERN = /(?:allow|whitelist|validateUrl|isAllowed|isValidUrl|isSafeUrl|assertSafe|checkUrl|allowedHost|ALLOWED_HOST)/i;
17
18
  const VM_UNSAFE_METHODS = new Set(['runInNewContext', 'runInThisContext', 'runInContext']);
18
19
  const VM2_CLASSES = new Set(['NodeVM', 'VM']);
19
20
  const JWT_WEAK_TOKENS = ['secret', 'password', 'changeme', '123456', 'default', 'testkey', 'qwerty'];
20
21
  const GRAPHQL_FACTORIES = new Set(['createYoga', 'graphqlHTTP']);
21
22
  const GRAPHQL_LIMIT_PATTERN = /(?:depthLimit|complexity|costAnalysis|queryComplexity|maxBatchSize|batchLimit)/i;
22
- const COOKIE_AUTH_MODULES = new Set([
23
- 'cookie-parser',
24
- 'express-session',
25
- 'cookie-session',
26
- '@fastify/session',
27
- '@fastify/cookie',
28
- ]);
29
- const COOKIE_AUTH_CALLEES = new Set(['cookieParser', 'cookieSession', 'session']);
30
- const STATE_CHANGING_METHODS = new Set(['post', 'put', 'patch', 'delete']);
31
- const COOKIE_OR_SESSION_PATTERN = /(?:cookie|session)/i;
32
- const CSRF_PATTERN = /(?:csurf|csrf-csrf|doubleCsrf|lusca|@fastify\/csrf-protection|fastify-csrf|csrfProtection|csrfSynchronisedProtection|verifyCsrf|validateCsrf|x-csrf-token)/i;
33
23
  function unwrapExpr(expr) {
34
24
  let current = expr;
35
25
  while (current && (ts.isParenthesizedExpression(current) || ts.isAsExpression(current))) {
@@ -80,19 +70,10 @@ function resolveConstString(expr, sourceFile, depth = 0) {
80
70
  const unwrapped = unwrapExpr(expr);
81
71
  if (!unwrapped || !ts.isIdentifier(unwrapped) || depth > 3)
82
72
  return undefined;
83
- let resolved;
84
- (function findDecl(node) {
85
- if (resolved !== undefined)
86
- return;
87
- if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === unwrapped.text) {
88
- if (node.parent.flags & ts.NodeFlags.Const && node.initializer) {
89
- resolved = resolveConstString(node.initializer, sourceFile, depth + 1);
90
- }
91
- return;
92
- }
93
- ts.forEachChild(node, findDecl);
94
- })(sourceFile);
95
- return resolved;
73
+ const binding = findLexicalDeclaration(unwrapped);
74
+ if (!binding || binding.kind !== 'const')
75
+ return undefined;
76
+ return resolveConstString(binding.initializer, sourceFile, depth + 1);
96
77
  }
97
78
  function getProperty(obj, name) {
98
79
  for (const prop of obj.properties) {
@@ -198,69 +179,6 @@ function checkServerActions(sourceFile, context) {
198
179
  ts.forEachChild(node, visit);
199
180
  })(sourceFile);
200
181
  }
201
- function hasUrlValidationInScope(node) {
202
- let current = node.parent;
203
- while (current && !ts.isSourceFile(current)) {
204
- if (ts.isFunctionDeclaration(current) || ts.isFunctionExpression(current) || ts.isArrowFunction(current)) {
205
- break;
206
- }
207
- current = current.parent;
208
- }
209
- const scope = current ?? node.getSourceFile();
210
- return URL_GUARD_PATTERN.test(scope.getText());
211
- }
212
- function hasRedirectGuard(optionsExpr) {
213
- const unwrapped = unwrapExpr(optionsExpr);
214
- if (!unwrapped || !ts.isObjectLiteralExpression(unwrapped))
215
- return false;
216
- const redirectVal = getStringLiteral(getProperty(unwrapped, 'redirect'));
217
- if (redirectVal === 'manual' || redirectVal === 'error')
218
- return true;
219
- const maxRedirects = unwrapExpr(getProperty(unwrapped, 'maxRedirects'));
220
- if (maxRedirects && ts.isNumericLiteral(maxRedirects) && Number(maxRedirects.text) === 0)
221
- return true;
222
- const followRedirect = getProperty(unwrapped, 'followRedirect');
223
- if (isBooleanLiteral(followRedirect, false))
224
- return true;
225
- return false;
226
- }
227
- function checkSsrfRedirectCall(call, context) {
228
- const calleeName = getCalleeName(call);
229
- const objName = getCalleeObjectName(call);
230
- if (!calleeName)
231
- return;
232
- let urlArg;
233
- let optionsArg;
234
- if (calleeName === 'fetch' && !objName) {
235
- urlArg = call.arguments[0];
236
- optionsArg = call.arguments[1];
237
- }
238
- else if ((calleeName === 'axios' && !objName) ||
239
- (objName === 'axios' && SSRF_METHODS.has(calleeName)) ||
240
- (calleeName === 'got' && !objName) ||
241
- (objName === 'got' && SSRF_METHODS.has(calleeName)) ||
242
- ((objName === 'http' || objName === 'https') && (calleeName === 'request' || calleeName === 'get'))) {
243
- const first = unwrapExpr(call.arguments[0]);
244
- if (first && ts.isObjectLiteralExpression(first)) {
245
- urlArg = getProperty(first, 'url') ?? getProperty(first, 'href');
246
- optionsArg = first;
247
- }
248
- else {
249
- urlArg = call.arguments[0];
250
- optionsArg = call.arguments[1];
251
- }
252
- }
253
- else {
254
- return;
255
- }
256
- if (!urlArg || isStaticStringLike(urlArg))
257
- return;
258
- if (hasRedirectGuard(optionsArg) || hasUrlValidationInScope(call))
259
- return;
260
- if (!context.taint.trace(urlArg, 'url'))
261
- return;
262
- context.report(call, 'ssrf-redirect-bypass', 'HTTP request with a dynamic URL does not disable HTTP redirects (`redirect: "manual"` / `"error"` or `maxRedirects: 0`), allowing SSRF allowlist bypasses via 3xx redirects.');
263
- }
264
182
  function resolveVmBinding(node, context) {
265
183
  const callee = unwrapExpression(node.expression);
266
184
  if (!ts.isPropertyAccessExpression(callee) && !ts.isElementAccessExpression(callee)) {
@@ -327,13 +245,29 @@ function extractEncodedSecret(expr, sourceFile) {
327
245
  }
328
246
  return resolveConstString(unwrapped, sourceFile);
329
247
  }
248
+ const JWT_MODULES = new Set(['jsonwebtoken', 'jose', '@nestjs/jwt', 'hono/jwt']);
249
+ const JWT_CALLEE_NAMES = new Set(['jwtVerify', 'sign', 'signAsync', 'verify', 'verifyAsync', 'register', 'forRoot']);
250
+ function canOverrideSecret(prop) {
251
+ return ts.isSpreadAssignment(prop) || (prop.name !== undefined && ts.isComputedPropertyName(prop.name));
252
+ }
330
253
  function checkJwtWeakSecret(call, context) {
331
254
  const calleeName = getCalleeName(call);
332
- const objName = getCalleeObjectName(call);
333
- if (!calleeName)
255
+ if (!calleeName || !JWT_CALLEE_NAMES.has(calleeName))
334
256
  return;
257
+ const lib = context.libraryCall(call);
258
+ if (!lib?.module || !JWT_MODULES.has(lib.module))
259
+ return;
260
+ const objName = getCalleeObjectName(call);
335
261
  let secretExpr;
336
- if (calleeName === 'jwtVerify' || (calleeName === 'sign' && call.arguments.length === 1)) {
262
+ if (lib.module === '@nestjs/jwt' && objName !== 'JwtModule') {
263
+ // JwtService takes the payload/token first and the key only via options.secret.
264
+ const options = unwrapExpr(call.arguments[1]);
265
+ // A spread or computed key can overwrite `secret`, so the literal is not the effective key.
266
+ if (options && ts.isObjectLiteralExpression(options) && !options.properties.some(canOverrideSecret)) {
267
+ secretExpr = getProperty(options, 'secret');
268
+ }
269
+ }
270
+ else if (calleeName === 'jwtVerify' || (calleeName === 'sign' && call.arguments.length === 1)) {
337
271
  secretExpr = call.arguments[1] ?? call.arguments[0];
338
272
  }
339
273
  else if ((calleeName === 'sign' || calleeName === 'verify') && (objName === 'jwt' || !objName)) {
@@ -403,49 +337,6 @@ function checkGraphqlBatching(node, context) {
403
337
  return;
404
338
  context.report(node, 'graphql-batching-unbounded', 'GraphQL batching is enabled without a batch size, query depth, or cost/complexity limit, allowing batching DoS and brute-force attacks.');
405
339
  }
406
- function checkExpressCookieAuthCsrf(sourceFile, context) {
407
- const text = sourceFile.text;
408
- if (!COOKIE_OR_SESSION_PATTERN.test(text) || CSRF_PATTERN.test(text))
409
- return;
410
- let cookieAuthNode;
411
- let hasStateChangingRoute = false;
412
- let hasStrictSameSite = false;
413
- (function visit(node) {
414
- if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
415
- if (COOKIE_AUTH_MODULES.has(node.moduleSpecifier.text) && !cookieAuthNode) {
416
- cookieAuthNode = node;
417
- }
418
- }
419
- if (ts.isPropertyAssignment(node)) {
420
- const key = ts.isIdentifier(node.name)
421
- ? node.name.text
422
- : ts.isStringLiteral(node.name)
423
- ? node.name.text
424
- : undefined;
425
- if (key === 'sameSite') {
426
- const val = getStringLiteral(node.initializer);
427
- if (val && val.toLowerCase() === 'strict')
428
- hasStrictSameSite = true;
429
- }
430
- }
431
- if (ts.isCallExpression(node)) {
432
- const callee = getCalleeName(node);
433
- const obj = getCalleeObjectName(node);
434
- if (callee && COOKIE_AUTH_CALLEES.has(callee))
435
- cookieAuthNode = node;
436
- if ((obj === 'res' || obj === 'reply') && (callee === 'cookie' || callee === 'setCookie')) {
437
- cookieAuthNode = cookieAuthNode ?? node;
438
- }
439
- if (callee && STATE_CHANGING_METHODS.has(callee) && obj) {
440
- hasStateChangingRoute = true;
441
- }
442
- }
443
- ts.forEachChild(node, visit);
444
- })(sourceFile);
445
- if (!cookieAuthNode || !hasStateChangingRoute || hasStrictSameSite)
446
- return;
447
- context.report(cookieAuthNode, 'express-cookie-auth-missing-csrf', 'Cookie-based auth/session is used with state-changing routes without CSRF protection (`csurf`, `csrf-csrf`, `lusca`, `@fastify/csrf-protection`) or `sameSite: "strict"`.');
448
- }
449
340
  export const checks = {
450
341
  SourceFile: [
451
342
  (node, context) => {
@@ -2,7 +2,7 @@ import { scanPolyglot } from '../performance/polyglot.js';
2
2
  import { packagePath } from '../shared/package-root.js';
3
3
  const securityConfig = packagePath('polyglot/security/sgconfig.yml');
4
4
  /** Run ast-grep polyglot security checks on the given files or directories. */
5
- async function checkSecurityPolyglot(paths) {
6
- return scanPolyglot(securityConfig, paths);
5
+ async function checkSecurityPolyglot(paths, isIgnored) {
6
+ return scanPolyglot(securityConfig, paths, isIgnored);
7
7
  }
8
8
  export { checkSecurityPolyglot };
@@ -0,0 +1,98 @@
1
+ import { ts } from '../performance/engine/compiler.js';
2
+ import { effectiveProperty, isUnshadowedGlobal, symbolOf, unwrapExpression } from '../shared/analysis/ast-semantics.js';
3
+ import { importedFrom } from './bindings.js';
4
+ const methods = new Set(['get', 'head', 'options', 'delete', 'post', 'put', 'patch', 'request']);
5
+ const axiosBodyMethods = new Set(['post', 'put', 'patch', 'postForm', 'putForm', 'patchForm']);
6
+ function option(object, name) {
7
+ const property = effectiveProperty(object, name, { guardSpreadGetters: true });
8
+ if (!property || property === 'unknown')
9
+ return;
10
+ if (ts.isShorthandPropertyAssignment(property))
11
+ return property.name;
12
+ if (ts.isPropertyAssignment(property))
13
+ return unwrapExpression(property.initializer);
14
+ }
15
+ // Only a literal (possibly behind an immutable scalar binding) proves that redirects are disabled.
16
+ function scalar(expression, context) {
17
+ let value = expression && unwrapExpression(expression);
18
+ const seen = new Set();
19
+ while (value && ts.isIdentifier(value)) {
20
+ if (seen.has(value))
21
+ return;
22
+ seen.add(value);
23
+ const declaration = symbolOf(value, context.checker)?.valueDeclaration;
24
+ if (!declaration || !ts.isVariableDeclaration(declaration) || !(declaration.parent.flags & ts.NodeFlags.Const))
25
+ return;
26
+ value = declaration.initializer && unwrapExpression(declaration.initializer);
27
+ }
28
+ return value;
29
+ }
30
+ // Got skips an undefined override and keeps the earlier configuration's value.
31
+ function isKnownUndefined(expression, context) {
32
+ const value = unwrapExpression(expression);
33
+ return ts.isVoidExpression(value) || isUnshadowedGlobal(value, 'undefined', context.checker);
34
+ }
35
+ function clientCall(call, context) {
36
+ const callee = unwrapExpression(call.expression);
37
+ if (isUnshadowedGlobal(callee, 'fetch', context.checker))
38
+ return { client: 'fetch', method: 'fetch' };
39
+ const receiver = ts.isPropertyAccessExpression(callee) ? callee.expression : callee;
40
+ const binding = importedFrom(receiver, context.checker);
41
+ if (!binding?.module)
42
+ return;
43
+ const member = ts.isPropertyAccessExpression(callee);
44
+ const namespace = binding.exported === '*' ||
45
+ binding.exported === 'default' ||
46
+ (binding.module === 'got' && binding.exported === 'got');
47
+ if (member && !namespace)
48
+ return;
49
+ const method = member ? callee.name.text : binding.exported;
50
+ if (!method)
51
+ return;
52
+ if ((binding.module === 'undici' && method === 'fetch') || (binding.module === 'node-fetch' && method === 'default'))
53
+ return { client: 'fetch', method: 'fetch' };
54
+ if (binding.module !== 'axios' && binding.module !== 'got')
55
+ return;
56
+ if (method !== 'default' &&
57
+ method !== '*' &&
58
+ !(binding.module === 'got' && method === 'got') &&
59
+ !methods.has(method) &&
60
+ !(binding.module === 'axios' && axiosBodyMethods.has(method)))
61
+ return;
62
+ return { client: binding.module, method };
63
+ }
64
+ export function checkSsrfRedirectCall(call, context) {
65
+ const target = clientCall(call, context);
66
+ if (!target || !call.arguments[0])
67
+ return;
68
+ const first = unwrapExpression(call.arguments[0]);
69
+ const configFirst = (target.client === 'axios' || target.client === 'got') && ts.isObjectLiteralExpression(first);
70
+ const url = configFirst ? option(first, 'url') : first;
71
+ if (!url || ts.isStringLiteralLike(url))
72
+ return;
73
+ const index = target.client === 'axios' && axiosBodyMethods.has(target.method) ? 2 : 1;
74
+ const secondArgument = call.arguments[configFirst && target.client === 'got' ? 1 : index];
75
+ // Got merges the second options object after the first, so it takes precedence.
76
+ const configs = [secondArgument && unwrapExpression(secondArgument), configFirst ? first : undefined];
77
+ const setting = (key) => {
78
+ for (const config of configs) {
79
+ const value = config && ts.isObjectLiteralExpression(config) ? option(config, key) : undefined;
80
+ if (!value || isKnownUndefined(value, context))
81
+ continue;
82
+ return scalar(value, context);
83
+ }
84
+ };
85
+ const key = target.client === 'axios' ? 'maxRedirects' : target.client === 'got' ? 'followRedirect' : 'redirect';
86
+ const value = setting(key);
87
+ const gotBudget = target.client === 'got' ? setting('maxRedirects') : undefined;
88
+ if ((value &&
89
+ ((target.client === 'axios' && ts.isNumericLiteral(value) && Number(value.text) === 0) ||
90
+ (target.client === 'got' && value.kind === ts.SyntaxKind.FalseKeyword) ||
91
+ (target.client === 'fetch' && ts.isStringLiteralLike(value) && ['manual', 'error'].includes(value.text)))) ||
92
+ (gotBudget && ts.isNumericLiteral(gotBudget) && Number(gotBudget.text) === 0))
93
+ return;
94
+ const trace = context.taint.trace(url, 'url');
95
+ if (!trace)
96
+ return;
97
+ context.report(call, 'ssrf-redirect-bypass', 'This request uses a request-derived URL without a visible policy disabling automatic redirects. Check each redirect destination or disable automatic redirects for this client.', undefined, { taint: trace });
98
+ }
@@ -112,7 +112,7 @@ function nestRedirectTarget(statement, context) {
112
112
  // A path that starts with one `/` and a literal character that is not `/` or `\` cannot leave the
113
113
  // site. A relative path such as `original?` also stays on the site: a scheme would need a `:`
114
114
  // before the first separator.
115
- const fixedPathStart = /^(?:\/[^/\\]|[\w.~-]+[/?#])/;
115
+ const fixedPathStart = /^(?:\/[^/\\\t\r\n]|[^:/\\?#\s][^:/\\?#]*[/?#])/;
116
116
  const leadingSlashStrip = /^\^\[(?:\\?\/\\\\|\\\\\\?\/)\]\+/;
117
117
  const dependencyPath = /[\\/]node_modules[\\/]/;
118
118
  function stripsLeadingSlashes(node) {
@@ -142,10 +142,10 @@ function startsWithFixedPath(node, context) {
142
142
  const isBareSlash = ts.isStringLiteralLike(left) && left.text === '/';
143
143
  return startsWithFixedPath(left, context) || (isBareSlash && stripsLeadingSlashes(value.right));
144
144
  }
145
- // `${MOBILE_REDIRECT}?...`: the template opens with a constant string, so the site is fixed in
146
- // code.
145
+ // A literal base and the fixed text before the next substitution must reach a path, query or
146
+ // fragment before the destination is fixed.
147
147
  function startsWithFixedConstant(template, context) {
148
- if (!context || template.head.text !== '')
148
+ if (template.head.text !== '')
149
149
  return false;
150
150
  const first = strip(template.templateSpans[0].expression);
151
151
  if (!ts.isIdentifier(first))
@@ -157,7 +157,20 @@ function startsWithFixedConstant(template, context) {
157
157
  ? declaration.initializer
158
158
  : undefined;
159
159
  const literal = initializer && strip(initializer);
160
- return Boolean(literal && ts.isStringLiteralLike(literal) && /^[^/\\]/.test(literal.text));
160
+ if (!literal || !ts.isStringLiteralLike(literal))
161
+ return false;
162
+ const prefix = literal.text + template.templateSpans[0].literal.text;
163
+ if (fixedPathStart.test(prefix))
164
+ return true;
165
+ if (/^[a-z][a-z\d+.-]*:\/[^/\\\s]/i.test(prefix) && URL.canParse(prefix) && new URL(prefix).host === '')
166
+ return true;
167
+ const authority = /^[a-z][a-z\d+.-]*:\/\/(.*)$/is.exec(prefix);
168
+ if (!authority || !URL.canParse(prefix))
169
+ return false;
170
+ // In a custom deep link the first slash past an empty authority already starts its path.
171
+ if (authority[1].startsWith('/') && new URL(prefix).host === '')
172
+ return true;
173
+ return /[/?#]/.test(authority[1].replace(/^\/+/, ''));
161
174
  }
162
175
  function returnedExpressions(declaration) {
163
176
  const body = 'body' in declaration ? declaration.body : undefined;
@@ -1,7 +1,8 @@
1
1
  // path-traversal: a file-system path built from request data.
2
2
  import { ts } from '../../performance/engine/compiler.js';
3
3
  import { classifyExecutionContext } from '../../shared/analysis/execution-context.js';
4
- import { strip, hasProperty, isResponseReceiver, hopReason, isContainedPath, isProjectValidated } from './shared.js';
4
+ import { constInitializer, effectiveProperty, staticNullish, unwrapExpression, } from '../../shared/analysis/ast-semantics.js';
5
+ import { strip, isResponseReceiver, hopReason, isContainedPath, isProjectValidated } from './shared.js';
5
6
  const ruleId = 'path-traversal';
6
7
  const message = (label) => `This file path includes \`${label}\`. Check that its resolved location stays inside the intended directory, or validate the entire filename against the application's allowed format before opening it.`;
7
8
  const uploadNameReason = 'The path uses an uploaded file name; multer (busboy) strips directories from it, so confirm the upload parser does.';
@@ -51,8 +52,84 @@ const allPathFunctions = new Set([...onePathFunctions, ...twoPathFunctions]);
51
52
  function baseName(name) {
52
53
  return name?.endsWith('Sync') ? name.slice(0, -4) : name;
53
54
  }
55
+ function optionsObject(argument, context) {
56
+ let current = unwrapExpression(argument);
57
+ for (let depth = 0; depth < 4 && ts.isIdentifier(current); depth++) {
58
+ const initializer = constInitializer(current, context.checker);
59
+ if (!initializer)
60
+ return;
61
+ current = initializer;
62
+ }
63
+ return ts.isObjectLiteralExpression(current) ? current : undefined;
64
+ }
65
+ function isStaticPathSource(node, context, depth = 0) {
66
+ if (depth >= 4)
67
+ return false;
68
+ const value = unwrapExpression(node);
69
+ if (ts.isStringLiteralLike(value))
70
+ return depth > 0 || value.text.trim().length > 0;
71
+ if (ts.isTemplateExpression(value))
72
+ return value.templateSpans.every((span) => isStaticPathSource(span.expression, context, depth + 1));
73
+ if (ts.isIdentifier(value)) {
74
+ if (value.text === '__dirname' || value.text === '__filename')
75
+ return true;
76
+ const initializer = constInitializer(value, context.checker);
77
+ return initializer !== undefined && isStaticPathSource(initializer, context, depth + 1);
78
+ }
79
+ if (ts.isPropertyAccessExpression(value) &&
80
+ value.name.text === 'dirname' &&
81
+ ts.isMetaProperty(unwrapExpression(value.expression))) {
82
+ return true;
83
+ }
84
+ if (ts.isCallExpression(value)) {
85
+ const callee = unwrapExpression(value.expression);
86
+ if (ts.isPropertyAccessExpression(callee) &&
87
+ ts.isIdentifier(callee.expression) &&
88
+ callee.expression.text === 'process' &&
89
+ callee.name.text === 'cwd' &&
90
+ value.arguments.length === 0) {
91
+ return true;
92
+ }
93
+ const library = context.libraryCall(value);
94
+ const isResolve = library?.method === 'resolve' || library?.exported === 'resolve';
95
+ const isJoin = library?.method === 'join' || library?.exported === 'join';
96
+ // `path.resolve()` and `path.join()` with no arguments are the working directory, like `process.cwd()`.
97
+ if (library?.module === 'path' && (isJoin || isResolve)) {
98
+ return value.arguments.every((argument) => isStaticPathSource(argument, context, depth + 1));
99
+ }
100
+ }
101
+ return false;
102
+ }
103
+ function responseRootEvaluation(call, context) {
104
+ let rootValue;
105
+ for (const argument of call.arguments.slice(1)) {
106
+ const options = optionsObject(argument, context);
107
+ if (!options)
108
+ continue;
109
+ const property = effectiveProperty(options, 'root', { guardSpreadGetters: true });
110
+ if (property === undefined || property === 'unknown')
111
+ return { confined: false };
112
+ const value = ts.isPropertyAssignment(property)
113
+ ? property.initializer
114
+ : ts.isShorthandPropertyAssignment(property)
115
+ ? property.name
116
+ : undefined;
117
+ if (!value)
118
+ return { confined: false };
119
+ rootValue = value;
120
+ }
121
+ if (!rootValue)
122
+ return { confined: false };
123
+ const unwrapped = unwrapExpression(rootValue);
124
+ const resolved = ts.isIdentifier(unwrapped) ? (constInitializer(unwrapped, context.checker) ?? unwrapped) : unwrapped;
125
+ if (staticNullish(resolved, context.checker))
126
+ return { confined: false };
127
+ if (context.taint.trace(rootValue, 'path'))
128
+ return { confined: false, rootValue };
129
+ return isStaticPathSource(rootValue, context) ? { confined: true } : { confined: false, rootValue };
130
+ }
54
131
  // The path arguments of an fs call, or of `res.sendFile` / `res.download` / `res.render` without a
55
- // `root` option.
132
+ // trusted static `root` option.
56
133
  function pathArguments(call, context) {
57
134
  if (!call.arguments.length)
58
135
  return [];
@@ -63,10 +140,11 @@ function pathArguments(call, context) {
63
140
  return call.arguments.slice(0, 1);
64
141
  if (method !== 'sendFile' && method !== 'download')
65
142
  return [];
66
- // `send` rejects `..` above `root`, so a root option makes the name safe.
67
- return call.arguments.slice(1).some((argument) => hasProperty(argument, 'root'))
68
- ? []
69
- : call.arguments.slice(0, 1);
143
+ // `send` rejects `..` above `root`, so a trusted static root option makes the name safe.
144
+ const root = responseRootEvaluation(call, context);
145
+ if (root.confined)
146
+ return [];
147
+ return root.rootValue ? [call.arguments[0], root.rootValue] : call.arguments.slice(0, 1);
70
148
  }
71
149
  if (ts.isPropertyAccessExpression(callee)) {
72
150
  const base = baseName(callee.name.text);
@@ -29,12 +29,6 @@ function propertyValue(argument, name) {
29
29
  return property.name;
30
30
  }
31
31
  }
32
- function hasProperty(argument, name) {
33
- const literal = strip(argument);
34
- return Boolean(literal &&
35
- ts.isObjectLiteralExpression(literal) &&
36
- literal.properties.some((property) => !ts.isSpreadAssignment(property) && nameText(property.name) === name));
37
- }
38
32
  function calleeName(call) {
39
33
  const callee = strip(call.expression);
40
34
  if (ts.isIdentifier(callee))
@@ -356,4 +350,4 @@ function isRelativeRedirect(sink, expression, context) {
356
350
  isGuardedByCondition(sink, (condition, truth) => !truth && prefix(condition, '//')) &&
357
351
  isGuardedByCondition(sink, (condition, truth) => !truth && unsafeSeparator(condition)));
358
352
  }
359
- export { strip, scopeOf, nameText, propertyValue, hasProperty, calleeName, isResponseReceiver, isGlobalIdentifier, hopReason, isHostHeader, constantDeclaration, stableIdentifier, sameValue, checkedAgainstLiteral, urlReferenceEscapes, isContainedPath, isAllowedHost, isRelativeRedirect, isProjectValidated, };
353
+ export { strip, scopeOf, nameText, propertyValue, calleeName, isResponseReceiver, isGlobalIdentifier, hopReason, isHostHeader, constantDeclaration, stableIdentifier, sameValue, checkedAgainstLiteral, urlReferenceEscapes, isContainedPath, isAllowedHost, isRelativeRedirect, isProjectValidated, };