loadwise 0.5.1 → 0.6.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.
- package/README.md +542 -627
- package/bin/loadwise.js +4 -0
- package/lib/accessibility/frontend-detect.js +2 -1
- package/lib/accessibility/rule-ids.js +12 -9
- package/{editor/accessibility-examples.cjs → lib/editor/accessibility-examples.js} +20 -21
- package/lib/editor/actions.js +117 -0
- package/{editor/apply-fix.cjs → lib/editor/apply-fix.js} +1 -6
- package/{editor/control-flow-comparison.cjs → lib/editor/control-flow-comparison.js} +1 -3
- package/lib/editor/diagnostics.js +365 -0
- package/lib/editor/dismissals.js +111 -0
- package/lib/editor/editor-document.js +99 -0
- package/{editor/finding-comparison.cjs → lib/editor/finding-comparison.js} +4 -7
- package/lib/editor/fix-edits.js +200 -0
- package/lib/editor/language-server.js +437 -0
- package/{editor/maintainability-examples.cjs → lib/editor/maintainability-examples.js} +1 -3
- package/{editor/perf-site-comparison.cjs → lib/editor/perf-site-comparison.js} +1 -3
- package/lib/editor/perf-watch.js +78 -0
- package/{editor/performance-examples.cjs → lib/editor/performance-examples.js} +129 -128
- package/{editor/reliability-examples.cjs → lib/editor/reliability-examples.js} +100 -41
- package/lib/editor/scan-session.js +334 -0
- package/{editor/security-examples.cjs → lib/editor/security-examples.js} +28 -32
- package/lib/editor/server-commands.js +232 -0
- package/{editor/source-example.cjs → lib/editor/source-example.js} +3 -5
- package/{editor/standalone-performance-examples.cjs → lib/editor/standalone-performance-examples.js} +349 -333
- package/lib/editor/types/dismissal.js +1 -0
- package/lib/editor/types/fix-example.js +1 -0
- package/lib/editor/types/source-document.js +1 -0
- package/lib/editor/workspace-files.js +78 -0
- package/lib/editor/workspace-paths.js +22 -0
- package/lib/maintainability/analyze-source.js +2 -0
- package/lib/maintainability/apply-fix.js +1 -1
- package/lib/maintainability/cli.js +1 -1
- package/lib/maintainability/examples.js +58 -41
- package/lib/maintainability/rule-ids.js +29 -14
- package/lib/maintainability/scan-changed.js +3 -0
- package/lib/maintainability/scan.js +13 -9
- package/lib/maintainability/tsconfig-strict.js +69 -0
- package/lib/maintainability/type-safety-hygiene.js +204 -0
- package/lib/performance/analyze.js +2 -0
- package/lib/performance/cli-arguments.js +0 -2
- package/lib/performance/cli-policy.js +17 -9
- package/lib/performance/cli-scan.js +10 -8
- package/lib/performance/cli.js +4 -23
- package/lib/performance/editor-signal.js +1 -1
- package/lib/performance/finding-text.js +3 -3
- package/lib/performance/fix-cli.js +1 -1
- package/lib/performance/frontend-perf.js +7 -0
- package/lib/performance/frontend-render-perf.js +200 -0
- package/lib/performance/llm-max-tokens.js +56 -0
- package/lib/performance/native.js +46 -26
- package/lib/performance/polyglot.js +22 -1
- package/lib/performance/pooling.js +38 -23
- package/lib/performance/projects.js +42 -21
- package/lib/performance/rule-ids.js +236 -222
- package/lib/performance/site-fixes/database.js +3 -1
- package/lib/performance/site-fixes/integrity.js +15 -1
- package/lib/performance/source-inputs.js +18 -6
- package/lib/performance/unscanned-javascript.js +66 -19
- package/lib/reliability/analyze.js +12 -0
- package/lib/reliability/child-process.js +106 -0
- package/lib/reliability/error-values.js +177 -0
- package/lib/reliability/pool-timeout.js +79 -0
- package/lib/reliability/react-bugs.js +602 -0
- package/lib/reliability/resource-leaks.js +3 -6
- package/lib/reliability/rule-ids.js +169 -127
- package/lib/reliability/switch-exhaustive.js +284 -0
- package/lib/reliability/uncaught-exception.js +223 -0
- package/lib/security/auth-crypto/rule-ids.js +3 -2
- package/lib/security/cli.js +6 -5
- package/lib/security/deps/rule-ids.js +1 -0
- package/lib/security/examples/auth-crypto.cjs +5 -4
- package/lib/security/examples/deps.cjs +1 -0
- package/lib/security/examples/exposure.cjs +55 -42
- package/lib/security/examples/files.cjs +1 -0
- package/lib/security/examples/injection.cjs +1 -0
- package/lib/security/examples/moved.cjs +5 -4
- package/lib/security/examples/request-forgery.cjs +1 -0
- package/lib/security/exposure/client-env.js +113 -0
- package/lib/security/exposure/frontend-security.js +12 -10
- package/lib/security/exposure/index.js +14 -3
- package/lib/security/exposure/jsx-url.js +267 -0
- package/lib/security/exposure/next-image-config.js +34 -0
- package/lib/security/exposure/package-manifest.js +45 -0
- package/lib/security/exposure/react-version.js +45 -0
- package/lib/security/exposure/rule-ids.js +16 -12
- package/lib/security/files/index.js +1 -1
- package/lib/security/files/rule-ids.js +1 -0
- package/lib/security/injection/code.js +24 -10
- package/lib/security/injection/command.js +81 -28
- package/lib/security/injection/nosql.js +109 -22
- package/lib/security/injection/redos.js +152 -308
- package/lib/security/injection/regex-pattern.js +290 -0
- package/lib/security/injection/regex.js +30 -11
- package/lib/security/injection/rule-ids.js +2 -1
- package/lib/security/injection/shared.js +19 -1
- package/lib/security/injection/sql.js +83 -2
- package/lib/security/request-forgery/rule-ids.js +1 -0
- package/lib/security/rule-descriptions.js +36 -32
- package/lib/security/rule-ids.js +74 -67
- package/lib/security/taint/filename-guard.js +3 -1
- package/lib/security/taint/guards.js +84 -10
- package/lib/security/taint/index.js +124 -13
- package/lib/security/taint/propagate.js +10 -7
- package/lib/security/taint/sanitizers.js +7 -3
- package/lib/security/taint/sources.js +6 -3
- package/lib/security/taint/summaries.js +13 -1
- package/lib/security/taint/url-parts.js +14 -5
- package/lib/shared/agent-session.js +2 -2
- package/lib/shared/check.js +9 -6
- package/lib/shared/explain.js +5 -5
- package/lib/shared/fix-convergence.js +1 -1
- package/lib/shared/formats/finding-location.js +6 -2
- package/lib/shared/formats/sarif.js +3 -3
- package/lib/shared/heap-limit.js +6 -0
- package/lib/shared/pillars.js +7 -7
- package/lib/shared/rule-docs.js +12 -0
- package/lib/shared/scan-cache.js +0 -1
- package/lib/shared/workspaces.js +31 -9
- package/package.json +9 -16
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/schema/loadwise.config.schema.json +44 -0
- package/editor/README.md +0 -47
- package/examples/redis-keys.otlp.json +0 -22
- package/lib/maintainability/notify-editor.js +0 -1
- package/lib/performance/editor-report.js +0 -191
- package/lib/performance/editor-setup.js +0 -189
- package/lib/performance/editor-watch-supervisor.js +0 -104
- package/lib/performance/editor-watch.js +0 -193
- package/lib/performance/notify-editor.js +0 -1
- package/lib/performance/recursive-watch.js +0 -181
- /package/lib/{performance/types/editor-report.js → editor/types/comparison.js} +0 -0
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
// Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
|
|
1
2
|
const descriptionByRule = {
|
|
3
|
+
'angular-bypass-security-trust': "DomSanitizer.bypassSecurityTrust* is called on a dynamic value, which turns off Angular's built-in sanitization.",
|
|
4
|
+
'auth-route-without-rate-limit': 'A login, signup or password-reset route has no rate limiter.',
|
|
2
5
|
'bcrypt-low-cost': 'A bcrypt password hash uses a work factor below the recommended minimum.',
|
|
6
|
+
'client-env-secret-exposed': 'A secret-named env variable is read under a browser prefix (NEXT_PUBLIC_, VITE_, REACT_APP_...), so the build ships it to every visitor.',
|
|
3
7
|
'code-injection': 'Request-controlled input becomes source code evaluated by the application.',
|
|
4
8
|
'command-injection': 'Request-controlled input reaches a shell command string.',
|
|
5
9
|
'committed-secret': 'A tracked file contains a value that appears to be a credential.',
|
|
@@ -7,78 +11,78 @@ const descriptionByRule = {
|
|
|
7
11
|
'cookie-missing-security-flags': 'A sensitive cookie is set without the expected security attributes.',
|
|
8
12
|
'cors-credentials-any-origin': 'A credentialed CORS response allows arbitrary origins.',
|
|
9
13
|
'cors-origin-regex-unanchored': 'A CORS origin regex also accepts look-alike hosts.',
|
|
14
|
+
'csharp-ef-from-sql-raw': 'FromSqlRaw or ExecuteSqlRaw receives a concatenated or interpolated string, risking SQL injection.',
|
|
15
|
+
'csharp-process-start': 'Process.Start launches an external process and risks command injection with untrusted arguments.',
|
|
16
|
+
'database-error-in-response': 'An HTTP response includes a raw database error message.',
|
|
10
17
|
'dependency-known-vulnerability': 'A resolved dependency version is listed in a published vulnerability advisory.',
|
|
11
18
|
'dockerfile-add-remote-url': 'A Dockerfile ADD instruction retrieves a resource from a remote URL.',
|
|
12
19
|
'dockerfile-runs-as-root': 'The final image selects root or inherits an unverified base-image user.',
|
|
13
20
|
'dockerfile-secret-in-build': 'A Dockerfile exposes a secret through a build argument or environment variable.',
|
|
14
21
|
'dockerfile-unpinned-base-image': 'A Dockerfile uses a base image reference that can change between builds.',
|
|
22
|
+
'dom-xss-sink': 'Untrusted or dynamic HTML reaches innerHTML, outerHTML, insertAdjacentHTML, document.write or createContextualFragment (DOM XSS).',
|
|
15
23
|
'drizzle-scope-unverified': 'A Drizzle operation lacks the row scope required by the declared policy.',
|
|
16
24
|
'drizzle-sql-raw-dynamic': 'A dynamic SQL fragment reaches Drizzle without parameter binding.',
|
|
17
25
|
'error-stack-in-response': 'An HTTP response includes an internal error stack.',
|
|
26
|
+
'express-cookie-auth-missing-csrf': 'Cookie-based session or auth is paired with state-changing routes without CSRF protection or `sameSite: "strict"`.',
|
|
27
|
+
'express-missing-helmet': 'The Express or NestJS server starts without helmet security headers middleware (contextual: a proxy may set them).',
|
|
28
|
+
'frontend-storage-secret-token': 'A token, JWT, password or API key is stored in localStorage or sessionStorage, readable by any script on the page.',
|
|
29
|
+
'go-exec-command-shell': 'exec.Command invokes a shell, which risks command injection.',
|
|
30
|
+
'go-sql-sprintf-injection': 'SQL text formatted with fmt.Sprintf risks SQL injection.',
|
|
31
|
+
'graphql-batching-unbounded': 'GraphQL query batching is enabled without a batch size, query depth, or cost/complexity limit.',
|
|
18
32
|
'graphql-introspection-enabled': 'A GraphQL server explicitly enables schema introspection.',
|
|
33
|
+
'graphql-query-depth-unbounded': 'A GraphQL server accepts queries of any depth.',
|
|
19
34
|
'hardcoded-secret': 'The source supplies a literal credential or cryptographic secret.',
|
|
20
35
|
'insecure-cipher': 'A cryptographic operation selects an insecure cipher or mode.',
|
|
21
36
|
'insecure-random-for-secret': 'A sensitive token or secret uses a non-cryptographic random source.',
|
|
37
|
+
'java-runtime-exec': 'Runtime.getRuntime().exec runs an OS command and risks command injection with untrusted arguments.',
|
|
38
|
+
'java-sql-string-concat': 'A SQL query built by string concatenation risks SQL injection.',
|
|
39
|
+
'jsx-javascript-url': 'In React 18 and older or Preact, a URL search parameter or location hash starts a JSX href, action or iframe src (javascript: XSS).',
|
|
22
40
|
'jwt-decode-for-auth': 'Authentication uses decoded JWT claims without verifying the token signature.',
|
|
23
41
|
'jwt-none-algorithm': 'JWT signing or verification allows an unsigned token.',
|
|
24
42
|
'jwt-sign-without-expiry': 'A signed JWT has no explicit expiration.',
|
|
25
43
|
'jwt-verify-without-algorithms': 'JWT verification does not restrict the accepted signing algorithms.',
|
|
44
|
+
'jwt-weak-secret-literal': 'JWT signing or verification uses a short (< 32 chars) or weak literal secret susceptible to brute-force forgery.',
|
|
26
45
|
'knex-raw-dynamic-text': 'A dynamic SQL fragment reaches Knex without parameter binding.',
|
|
27
46
|
'mass-assignment': 'An unfiltered request body reaches a persistence operation.',
|
|
28
47
|
'mysql-dynamic-query-text': 'Dynamic SQL text reaches a MySQL client without parameter binding.',
|
|
29
48
|
'nest-validation-without-whitelist': 'A NestJS ValidationPipe permits properties outside the validated DTO.',
|
|
49
|
+
'next-image-any-remote-host': "A Next.js images.remotePatterns entry sets hostname '**', so the image optimizer fetches and serves any host (open proxy).",
|
|
30
50
|
'nosql-operator-injection': 'Request data can introduce query operators into a NoSQL filter.',
|
|
31
51
|
'open-redirect': 'An HTTP redirect destination is controlled by request data.',
|
|
52
|
+
'password-hash-in-response': 'A response returns a user record that still holds its password hash.',
|
|
32
53
|
'path-traversal': 'Request data controls a filesystem path without a recognized containment check.',
|
|
33
54
|
'pg-dynamic-query-text': 'Dynamic SQL text reaches the PostgreSQL client without parameter binding.',
|
|
55
|
+
'plaintext-password-storage': 'A password is stored or written without being hashed.',
|
|
56
|
+
'postmessage-missing-origin-check': "postMessage targets '*', or a window message listener reads event.data without checking origin or source.",
|
|
34
57
|
'prisma-raw-unsafe-dynamic': 'Dynamic SQL text reaches an unsafe Prisma raw-query method.',
|
|
35
58
|
'prisma-scope-unverified': 'A Prisma operation lacks the row scope required by the declared policy.',
|
|
36
59
|
'prototype-pollution': 'Request data can supply keys to a write or merge that can modify an object prototype.',
|
|
60
|
+
'python-insecure-deserialization': 'pickle or marshal deserialization of untrusted data can execute arbitrary code.',
|
|
61
|
+
'python-subprocess-shell-true': 'subprocess with shell=True or os.system passes input through a shell, risking command injection.',
|
|
62
|
+
'python-unsafe-yaml-load': 'yaml.load without SafeLoader can construct arbitrary Python objects.',
|
|
63
|
+
'react-dangerously-set-inner-html': 'dangerouslySetInnerHTML receives HTML that is not a constant or sanitized.',
|
|
37
64
|
'reflected-xss-response': 'An HTML response reflects request data without recognized escaping.',
|
|
38
|
-
'regex-from-input': 'Request input supplies a regular expression pattern without recognized escaping.',
|
|
39
65
|
'regex-catastrophic-backtracking': 'A regular expression that can backtrack exponentially or in polynomial time runs on request input.',
|
|
66
|
+
'regex-from-input': 'Request input supplies a regular expression pattern without recognized escaping.',
|
|
67
|
+
'rust-command-shell': 'Command::new("sh") or Command::new("bash") spawns a shell and risks command injection.',
|
|
68
|
+
'rust-unsafe-raw-pointer-deref': 'A raw pointer dereference in an unsafe block bypasses Rust memory safety guarantees.',
|
|
40
69
|
'secret-compared-non-constant-time': 'A secret is compared with an operation that can vary in timing with its contents.',
|
|
41
70
|
'secret-in-log': 'A log statement can expose a credential, token, or other secret.',
|
|
71
|
+
'secret-in-url-query': 'A password, token or API key is passed in a URL query string.',
|
|
42
72
|
'sequelize-dynamic-query-text': 'Dynamic SQL text reaches Sequelize without parameter binding.',
|
|
73
|
+
'server-action-missing-auth': 'An exported Next.js Server Action performs work without verifying authentication or session state.',
|
|
74
|
+
'ssrf-redirect-bypass': 'An outbound HTTP request with a dynamic URL does not disable redirects, allowing SSRF allowlist bypasses.',
|
|
43
75
|
'ssrf-request-url': 'Request data controls the destination of a server-side network request.',
|
|
76
|
+
'storage-object-public-acl': 'A storage upload makes the object publicly readable.',
|
|
44
77
|
'template-autoescape-disabled': 'A template engine is configured to render values without HTML escaping.',
|
|
45
78
|
'template-injection': 'Request data is interpreted as template source rather than a template value.',
|
|
46
79
|
'tls-verification-disabled': 'A TLS client skips certificate or server hostname verification.',
|
|
47
80
|
'typeorm-dynamic-query-text': 'A dynamic SQL fragment reaches TypeORM without parameter binding.',
|
|
48
81
|
'upload-client-filename': 'A file upload is stored under the original name supplied by the client.',
|
|
82
|
+
'vm-sandbox-escape': 'Node `vm` or `vm2` executes dynamic code or an untrusted context, risking sandbox escape and host RCE.',
|
|
83
|
+
'vue-v-html-unsanitized': 'A Vue render function binds unsanitized dynamic HTML to innerHTML.',
|
|
49
84
|
'weak-password-hash': 'A password is hashed with an algorithm unsuitable for password storage.',
|
|
50
|
-
'plaintext-password-storage': 'A password is stored or written without being hashed.',
|
|
51
85
|
'xml-external-entities': 'An XML parser allows processing of external entities.',
|
|
52
|
-
'password-hash-in-response': 'A response returns a user record that still holds its password hash.',
|
|
53
|
-
'storage-object-public-acl': 'A storage upload makes the object publicly readable.',
|
|
54
|
-
'secret-in-url-query': 'A password, token or API key is passed in a URL query string.',
|
|
55
|
-
'auth-route-without-rate-limit': 'A login, signup or password-reset route has no rate limiter.',
|
|
56
|
-
'graphql-query-depth-unbounded': 'A GraphQL server accepts queries of any depth.',
|
|
57
|
-
'database-error-in-response': 'An HTTP response includes a raw database error message.',
|
|
58
|
-
'dom-xss-sink': 'Untrusted or dynamic HTML reaches innerHTML, outerHTML, insertAdjacentHTML, document.write or createContextualFragment (DOM XSS).',
|
|
59
|
-
'react-dangerously-set-inner-html': 'dangerouslySetInnerHTML receives HTML that is not a constant or sanitized.',
|
|
60
|
-
'angular-bypass-security-trust': "DomSanitizer.bypassSecurityTrust* is called on a dynamic value, which turns off Angular's built-in sanitization.",
|
|
61
|
-
'vue-v-html-unsanitized': 'A Vue render function binds unsanitized dynamic HTML to innerHTML.',
|
|
62
|
-
'frontend-storage-secret-token': 'A token, JWT, password or API key is stored in localStorage or sessionStorage, readable by any script on the page.',
|
|
63
|
-
'postmessage-missing-origin-check': "postMessage targets '*', or a window message listener reads event.data without checking origin or source.",
|
|
64
|
-
'express-missing-helmet': 'The Express or NestJS server starts without helmet security headers middleware (contextual: a proxy may set them).',
|
|
65
86
|
'zip-slip-extraction': 'An archive entry controls an extraction path without a recognized containment check.',
|
|
66
|
-
'server-action-missing-auth': 'An exported Next.js Server Action performs work without verifying authentication or session state.',
|
|
67
|
-
'ssrf-redirect-bypass': 'An outbound HTTP request with a dynamic URL does not disable redirects, allowing SSRF allowlist bypasses.',
|
|
68
|
-
'vm-sandbox-escape': 'Node `vm` or `vm2` executes dynamic code or an untrusted context, risking sandbox escape and host RCE.',
|
|
69
|
-
'jwt-weak-secret-literal': 'JWT signing or verification uses a short (< 32 chars) or weak literal secret susceptible to brute-force forgery.',
|
|
70
|
-
'graphql-batching-unbounded': 'GraphQL query batching is enabled without a batch size, query depth, or cost/complexity limit.',
|
|
71
|
-
'express-cookie-auth-missing-csrf': 'Cookie-based session or auth is paired with state-changing routes without CSRF protection or `sameSite: "strict"`.',
|
|
72
|
-
'csharp-process-start': 'Process.Start launches an external process and risks command injection with untrusted arguments.',
|
|
73
|
-
'csharp-ef-from-sql-raw': 'FromSqlRaw or ExecuteSqlRaw receives a concatenated or interpolated string, risking SQL injection.',
|
|
74
|
-
'go-exec-command-shell': 'exec.Command invokes a shell, which risks command injection.',
|
|
75
|
-
'go-sql-sprintf-injection': 'SQL text formatted with fmt.Sprintf risks SQL injection.',
|
|
76
|
-
'java-runtime-exec': 'Runtime.getRuntime().exec runs an OS command and risks command injection with untrusted arguments.',
|
|
77
|
-
'java-sql-string-concat': 'A SQL query built by string concatenation risks SQL injection.',
|
|
78
|
-
'python-insecure-deserialization': 'pickle or marshal deserialization of untrusted data can execute arbitrary code.',
|
|
79
|
-
'python-unsafe-yaml-load': 'yaml.load without SafeLoader can construct arbitrary Python objects.',
|
|
80
|
-
'python-subprocess-shell-true': 'subprocess with shell=True or os.system passes input through a shell, risking command injection.',
|
|
81
|
-
'rust-command-shell': 'Command::new("sh") or Command::new("bash") spawns a shell and risks command injection.',
|
|
82
|
-
'rust-unsafe-raw-pointer-deref': 'A raw pointer dereference in an unsafe block bypasses Rust memory safety guarantees.',
|
|
83
87
|
};
|
|
84
88
|
export { descriptionByRule };
|
package/lib/security/rule-ids.js
CHANGED
|
@@ -6,18 +6,20 @@ import authCryptoRules from './auth-crypto/rule-ids.js';
|
|
|
6
6
|
import exposureRules from './exposure/rule-ids.js';
|
|
7
7
|
import depsRules from './deps/rule-ids.js';
|
|
8
8
|
import filesRules from './files/rule-ids.js';
|
|
9
|
+
// Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
|
|
9
10
|
const movedRuleInfo = {
|
|
11
|
+
'drizzle-scope-unverified': { group: 'moved', needs: 'types' },
|
|
10
12
|
'pg-dynamic-query-text': { group: 'moved', needs: 'types' },
|
|
11
13
|
'prisma-scope-unverified': { group: 'moved', needs: 'types' },
|
|
12
|
-
'drizzle-scope-unverified': { group: 'moved', needs: 'types' },
|
|
13
14
|
};
|
|
15
|
+
// Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
|
|
14
16
|
const phase5Rules = {
|
|
17
|
+
'express-cookie-auth-missing-csrf': { needs: 'syntax' },
|
|
18
|
+
'graphql-batching-unbounded': { needs: 'syntax' },
|
|
19
|
+
'jwt-weak-secret-literal': { needs: 'syntax' },
|
|
15
20
|
'server-action-missing-auth': { needs: 'syntax' },
|
|
16
21
|
'ssrf-redirect-bypass': { needs: 'syntax' },
|
|
17
22
|
'vm-sandbox-escape': { needs: 'syntax' },
|
|
18
|
-
'jwt-weak-secret-literal': { needs: 'syntax' },
|
|
19
|
-
'graphql-batching-unbounded': { needs: 'syntax' },
|
|
20
|
-
'express-cookie-auth-missing-csrf': { needs: 'syntax' },
|
|
21
23
|
};
|
|
22
24
|
const groups = {
|
|
23
25
|
injection: injectionRules,
|
|
@@ -36,101 +38,106 @@ for (const [group, rules] of Object.entries(groups)) {
|
|
|
36
38
|
ruleInfo[ruleId] = { group, ...info };
|
|
37
39
|
}
|
|
38
40
|
}
|
|
41
|
+
// Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
|
|
39
42
|
const impactByRule = {
|
|
40
|
-
'
|
|
41
|
-
'
|
|
42
|
-
'
|
|
43
|
+
'angular-bypass-security-trust': 'high',
|
|
44
|
+
'auth-route-without-rate-limit': 'medium',
|
|
45
|
+
'bcrypt-low-cost': 'medium',
|
|
46
|
+
'client-env-secret-exposed': 'critical',
|
|
43
47
|
'code-injection': 'critical',
|
|
44
48
|
'command-injection': 'critical',
|
|
45
|
-
'
|
|
46
|
-
'
|
|
47
|
-
'mysql-dynamic-query-text': 'critical',
|
|
48
|
-
'nosql-operator-injection': 'high',
|
|
49
|
-
'prisma-raw-unsafe-dynamic': 'critical',
|
|
50
|
-
'regex-from-input': 'medium',
|
|
51
|
-
'regex-catastrophic-backtracking': 'high',
|
|
52
|
-
'sequelize-dynamic-query-text': 'critical',
|
|
53
|
-
'template-injection': 'critical',
|
|
54
|
-
'typeorm-dynamic-query-text': 'critical',
|
|
55
|
-
'open-redirect': 'medium',
|
|
56
|
-
'path-traversal': 'high',
|
|
57
|
-
'ssrf-request-url': 'high',
|
|
58
|
-
'upload-client-filename': 'medium',
|
|
59
|
-
'zip-slip-extraction': 'high',
|
|
60
|
-
'bcrypt-low-cost': 'medium',
|
|
61
|
-
'hardcoded-secret': 'critical',
|
|
62
|
-
'insecure-cipher': 'medium',
|
|
63
|
-
'insecure-random-for-secret': 'high',
|
|
64
|
-
'jwt-decode-for-auth': 'high',
|
|
65
|
-
'jwt-none-algorithm': 'critical',
|
|
66
|
-
'jwt-sign-without-expiry': 'medium',
|
|
67
|
-
'jwt-verify-without-algorithms': 'high',
|
|
68
|
-
'secret-compared-non-constant-time': 'medium',
|
|
69
|
-
'tls-verification-disabled': 'high',
|
|
70
|
-
'weak-password-hash': 'high',
|
|
71
|
-
'plaintext-password-storage': 'critical',
|
|
49
|
+
'committed-secret': 'critical',
|
|
50
|
+
'compose-hardcoded-secret': 'high',
|
|
72
51
|
'cookie-missing-security-flags': 'high',
|
|
73
52
|
'cors-credentials-any-origin': 'high',
|
|
74
53
|
'cors-origin-regex-unanchored': 'medium',
|
|
75
|
-
'
|
|
76
|
-
'
|
|
77
|
-
'mass-assignment': 'high',
|
|
78
|
-
'nest-validation-without-whitelist': 'medium',
|
|
79
|
-
'prototype-pollution': 'high',
|
|
80
|
-
'reflected-xss-response': 'low',
|
|
81
|
-
'secret-in-log': 'high',
|
|
82
|
-
'template-autoescape-disabled': 'medium',
|
|
83
|
-
'xml-external-entities': 'medium',
|
|
84
|
-
'password-hash-in-response': 'high',
|
|
85
|
-
'storage-object-public-acl': 'high',
|
|
86
|
-
'secret-in-url-query': 'medium',
|
|
87
|
-
'auth-route-without-rate-limit': 'medium',
|
|
88
|
-
'graphql-query-depth-unbounded': 'medium',
|
|
54
|
+
'csharp-ef-from-sql-raw': 'high',
|
|
55
|
+
'csharp-process-start': 'medium',
|
|
89
56
|
'database-error-in-response': 'medium',
|
|
90
|
-
'dom-xss-sink': 'high',
|
|
91
|
-
'react-dangerously-set-inner-html': 'high',
|
|
92
|
-
'angular-bypass-security-trust': 'high',
|
|
93
|
-
'vue-v-html-unsanitized': 'high',
|
|
94
|
-
'frontend-storage-secret-token': 'medium',
|
|
95
|
-
'postmessage-missing-origin-check': 'medium',
|
|
96
|
-
'express-missing-helmet': 'low',
|
|
97
57
|
'dependency-known-vulnerability': 'medium',
|
|
98
|
-
'committed-secret': 'critical',
|
|
99
|
-
'compose-hardcoded-secret': 'high',
|
|
100
58
|
'dockerfile-add-remote-url': 'medium',
|
|
101
59
|
'dockerfile-runs-as-root': 'medium',
|
|
102
60
|
'dockerfile-secret-in-build': 'high',
|
|
103
61
|
'dockerfile-unpinned-base-image': 'low',
|
|
104
|
-
'
|
|
105
|
-
'
|
|
106
|
-
'
|
|
107
|
-
'
|
|
108
|
-
'graphql-batching-unbounded': 'medium',
|
|
62
|
+
'dom-xss-sink': 'high',
|
|
63
|
+
'drizzle-scope-unverified': 'high',
|
|
64
|
+
'drizzle-sql-raw-dynamic': 'critical',
|
|
65
|
+
'error-stack-in-response': 'medium',
|
|
109
66
|
'express-cookie-auth-missing-csrf': 'high',
|
|
110
|
-
'
|
|
111
|
-
'
|
|
67
|
+
'express-missing-helmet': 'low',
|
|
68
|
+
'frontend-storage-secret-token': 'medium',
|
|
112
69
|
'go-exec-command-shell': 'high',
|
|
113
70
|
'go-sql-sprintf-injection': 'high',
|
|
71
|
+
'graphql-batching-unbounded': 'medium',
|
|
72
|
+
'graphql-introspection-enabled': 'medium',
|
|
73
|
+
'graphql-query-depth-unbounded': 'medium',
|
|
74
|
+
'hardcoded-secret': 'critical',
|
|
75
|
+
'insecure-cipher': 'medium',
|
|
76
|
+
'insecure-random-for-secret': 'high',
|
|
114
77
|
'java-runtime-exec': 'medium',
|
|
115
78
|
'java-sql-string-concat': 'high',
|
|
79
|
+
'jsx-javascript-url': 'high',
|
|
80
|
+
'jwt-decode-for-auth': 'high',
|
|
81
|
+
'jwt-none-algorithm': 'critical',
|
|
82
|
+
'jwt-sign-without-expiry': 'medium',
|
|
83
|
+
'jwt-verify-without-algorithms': 'high',
|
|
84
|
+
'jwt-weak-secret-literal': 'high',
|
|
85
|
+
'knex-raw-dynamic-text': 'critical',
|
|
86
|
+
'mass-assignment': 'high',
|
|
87
|
+
'mysql-dynamic-query-text': 'critical',
|
|
88
|
+
'nest-validation-without-whitelist': 'medium',
|
|
89
|
+
'next-image-any-remote-host': 'medium',
|
|
90
|
+
'nosql-operator-injection': 'high',
|
|
91
|
+
'open-redirect': 'medium',
|
|
92
|
+
'password-hash-in-response': 'high',
|
|
93
|
+
'path-traversal': 'high',
|
|
94
|
+
'pg-dynamic-query-text': 'medium',
|
|
95
|
+
'plaintext-password-storage': 'critical',
|
|
96
|
+
'postmessage-missing-origin-check': 'medium',
|
|
97
|
+
'prisma-raw-unsafe-dynamic': 'critical',
|
|
98
|
+
'prisma-scope-unverified': 'high',
|
|
99
|
+
'prototype-pollution': 'high',
|
|
116
100
|
'python-insecure-deserialization': 'high',
|
|
117
|
-
'python-unsafe-yaml-load': 'high',
|
|
118
101
|
'python-subprocess-shell-true': 'high',
|
|
102
|
+
'python-unsafe-yaml-load': 'high',
|
|
103
|
+
'react-dangerously-set-inner-html': 'high',
|
|
104
|
+
'reflected-xss-response': 'low',
|
|
105
|
+
'regex-catastrophic-backtracking': 'high',
|
|
106
|
+
'regex-from-input': 'medium',
|
|
119
107
|
'rust-command-shell': 'high',
|
|
120
108
|
'rust-unsafe-raw-pointer-deref': 'medium',
|
|
109
|
+
'secret-compared-non-constant-time': 'medium',
|
|
110
|
+
'secret-in-log': 'high',
|
|
111
|
+
'secret-in-url-query': 'medium',
|
|
112
|
+
'sequelize-dynamic-query-text': 'critical',
|
|
113
|
+
'server-action-missing-auth': 'high',
|
|
114
|
+
'ssrf-redirect-bypass': 'high',
|
|
115
|
+
'ssrf-request-url': 'high',
|
|
116
|
+
'storage-object-public-acl': 'high',
|
|
117
|
+
'template-autoescape-disabled': 'medium',
|
|
118
|
+
'template-injection': 'critical',
|
|
119
|
+
'tls-verification-disabled': 'high',
|
|
120
|
+
'typeorm-dynamic-query-text': 'critical',
|
|
121
|
+
'upload-client-filename': 'medium',
|
|
122
|
+
'vm-sandbox-escape': 'critical',
|
|
123
|
+
'vue-v-html-unsanitized': 'high',
|
|
124
|
+
'weak-password-hash': 'high',
|
|
125
|
+
'xml-external-entities': 'medium',
|
|
126
|
+
'zip-slip-extraction': 'high',
|
|
121
127
|
};
|
|
122
128
|
// Rules the ast-grep polyglot scan reports from polyglot/security. They are syntactic patterns, so
|
|
123
129
|
// they are not in ruleInfo, which lists only the TypeScript source rules that --ignore accepts.
|
|
130
|
+
// Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
|
|
124
131
|
const polyglotRules = [
|
|
125
|
-
'csharp-process-start',
|
|
126
132
|
'csharp-ef-from-sql-raw',
|
|
133
|
+
'csharp-process-start',
|
|
127
134
|
'go-exec-command-shell',
|
|
128
135
|
'go-sql-sprintf-injection',
|
|
129
136
|
'java-runtime-exec',
|
|
130
137
|
'java-sql-string-concat',
|
|
131
138
|
'python-insecure-deserialization',
|
|
132
|
-
'python-unsafe-yaml-load',
|
|
133
139
|
'python-subprocess-shell-true',
|
|
140
|
+
'python-unsafe-yaml-load',
|
|
134
141
|
'rust-command-shell',
|
|
135
142
|
'rust-unsafe-raw-pointer-deref',
|
|
136
143
|
];
|
|
@@ -62,7 +62,9 @@ function filenameValidation(condition, isSubject, checker) {
|
|
|
62
62
|
const pattern = constantOf(receiver, checker);
|
|
63
63
|
return (!!pattern?.initializer && isFilenamePattern(ts.skipOuterExpressions(pattern.initializer)) && onlyRegexCalls(pattern));
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
// A negated class (`[^a-z/]`) matches everything except its members, so a separator inside it is
|
|
66
|
+
// evidence of nothing.
|
|
67
|
+
const separatorRegexPattern = /^\/(?:\[(?!\^)[^\]]*[/\\][^\]]*\]|\\\.\.)\/[gi]*$/;
|
|
66
68
|
const foundIndexComparisons = new Set(['!== -1', '!= -1', '>= 0', '> -1']);
|
|
67
69
|
const missingIndexComparisons = new Set(['=== -1', '== -1', '< 0']);
|
|
68
70
|
function isSeparatorStringCall(expression, methodName, expectedMethod, args, isSubject) {
|
|
@@ -56,14 +56,27 @@ function pinningComparison(condition, isSubject) {
|
|
|
56
56
|
return kind;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
// A name no project code declares: it is the runtime built-in, or has no declaration without types.
|
|
60
|
+
// A local `const Number = ...` or `parseInt` function can return anything, so it earns no credit.
|
|
61
|
+
function isBuiltinReference(identifier, checker) {
|
|
62
|
+
const declarations = checker.getSymbolAtLocation(identifier)?.declarations;
|
|
63
|
+
return !declarations || declarations.every((declaration) => declaration.getSourceFile().isDeclarationFile);
|
|
64
|
+
}
|
|
65
|
+
function isNumberCheck(condition, isSubject, checker) {
|
|
60
66
|
if (!ts.isCallExpression(condition) || condition.arguments.length !== 1 || !isSubject(condition.arguments[0]))
|
|
61
67
|
return false;
|
|
62
68
|
const callee = stripParentheses(condition.expression);
|
|
63
69
|
return (ts.isPropertyAccessExpression(callee) &&
|
|
64
70
|
ts.isIdentifier(callee.expression) &&
|
|
65
71
|
callee.expression.text === 'Number' &&
|
|
66
|
-
numberChecks.has(callee.name.text)
|
|
72
|
+
numberChecks.has(callee.name.text) &&
|
|
73
|
+
isBuiltinReference(callee.expression, checker));
|
|
74
|
+
}
|
|
75
|
+
// `ALLOWED.includes(value)`: the call checks the guarded binding itself, not another one that
|
|
76
|
+
// shares its name.
|
|
77
|
+
function checksSubject(condition, isSubject) {
|
|
78
|
+
const call = ts.skipOuterExpressions(condition);
|
|
79
|
+
return ts.isCallExpression(call) && call.arguments.length === 1 && isSubject(call.arguments[0]);
|
|
67
80
|
}
|
|
68
81
|
// When `condition` is true, the value is safe.
|
|
69
82
|
function confirms(node, guard) {
|
|
@@ -84,7 +97,8 @@ function confirms(node, guard) {
|
|
|
84
97
|
if (filename !== undefined)
|
|
85
98
|
return filename;
|
|
86
99
|
}
|
|
87
|
-
return isNumberCheck(condition, guard.isSubject
|
|
100
|
+
return (isNumberCheck(condition, guard.isSubject, guard.checker) ||
|
|
101
|
+
(checksSubject(condition, guard.isSubject) && isValidation(condition, guard.name, guard.checker)));
|
|
88
102
|
}
|
|
89
103
|
// When `condition` is false, the value is safe.
|
|
90
104
|
function rejects(node, guard) {
|
|
@@ -188,10 +202,18 @@ function isReassigned(scope, symbol, checker, properties = false) {
|
|
|
188
202
|
return ts.forEachChild(node, visit);
|
|
189
203
|
})(scope);
|
|
190
204
|
}
|
|
205
|
+
// Writes that can store the right-hand value in the variable.
|
|
206
|
+
const valueAssignmentOperators = new Set([
|
|
207
|
+
ts.SyntaxKind.EqualsToken,
|
|
208
|
+
ts.SyntaxKind.PlusEqualsToken,
|
|
209
|
+
ts.SyntaxKind.BarBarEqualsToken,
|
|
210
|
+
ts.SyntaxKind.QuestionQuestionEqualsToken,
|
|
211
|
+
ts.SyntaxKind.AmpersandAmpersandEqualsToken,
|
|
212
|
+
]);
|
|
191
213
|
const assignmentIndexes = new WeakMap();
|
|
192
|
-
// The
|
|
193
|
-
// are indexed once per checker, so resolving each `let` of a long function or
|
|
194
|
-
// the whole scope again.
|
|
214
|
+
// The `=`, `+=`, `||=`, `??=` and `&&=` writes to `declaration` inside `scope`, in source order. The
|
|
215
|
+
// writes of a scope are indexed once per checker, so resolving each `let` of a long function or
|
|
216
|
+
// module does not walk the whole scope again.
|
|
195
217
|
function assignmentsTo(declaration, scope, checker) {
|
|
196
218
|
let byScope = assignmentIndexes.get(checker);
|
|
197
219
|
if (!byScope)
|
|
@@ -202,8 +224,7 @@ function assignmentsTo(declaration, scope, checker) {
|
|
|
202
224
|
const writes = byDeclaration;
|
|
203
225
|
(function visit(node) {
|
|
204
226
|
if (ts.isBinaryExpression(node) &&
|
|
205
|
-
(node.operatorToken.kind
|
|
206
|
-
node.operatorToken.kind === ts.SyntaxKind.PlusEqualsToken) &&
|
|
227
|
+
valueAssignmentOperators.has(node.operatorToken.kind) &&
|
|
207
228
|
ts.isIdentifier(node.left)) {
|
|
208
229
|
const written = checker.getSymbolAtLocation(node.left)?.valueDeclaration;
|
|
209
230
|
if (written && !writes.has(written))
|
|
@@ -217,6 +238,51 @@ function assignmentsTo(declaration, scope, checker) {
|
|
|
217
238
|
}
|
|
218
239
|
return byDeclaration.get(declaration) ?? [];
|
|
219
240
|
}
|
|
241
|
+
const fieldWriteIndexes = new WeakMap();
|
|
242
|
+
function writtenFieldName(target) {
|
|
243
|
+
if (ts.isPropertyAccessExpression(target))
|
|
244
|
+
return target.name.text;
|
|
245
|
+
if (!ts.isElementAccessExpression(target))
|
|
246
|
+
return;
|
|
247
|
+
const key = ts.skipOuterExpressions(target.argumentExpression);
|
|
248
|
+
return ts.isStringLiteralLike(key) || ts.isNumericLiteral(key) ? key.text : undefined;
|
|
249
|
+
}
|
|
250
|
+
// The `object.field = value` and `object['field'] = value` writes (also `+=`, `||=`, `??=`, `&&=`)
|
|
251
|
+
// to fields of `declaration` inside `scope`, in source order. `const` pins only the binding, so a
|
|
252
|
+
// literal initializer is not the whole value once a field is written. Indexed once per scope, as
|
|
253
|
+
// `assignmentsTo` is.
|
|
254
|
+
function fieldWritesTo(declaration, scope, checker) {
|
|
255
|
+
let byScope = fieldWriteIndexes.get(checker);
|
|
256
|
+
if (!byScope)
|
|
257
|
+
fieldWriteIndexes.set(checker, (byScope = new WeakMap()));
|
|
258
|
+
let byDeclaration = byScope.get(scope);
|
|
259
|
+
if (!byDeclaration) {
|
|
260
|
+
byDeclaration = new Map();
|
|
261
|
+
const writes = byDeclaration;
|
|
262
|
+
(function visit(node) {
|
|
263
|
+
if (ts.isBinaryExpression(node) &&
|
|
264
|
+
valueAssignmentOperators.has(node.operatorToken.kind) &&
|
|
265
|
+
(ts.isPropertyAccessExpression(node.left) || ts.isElementAccessExpression(node.left))) {
|
|
266
|
+
const object = ts.skipOuterExpressions(node.left.expression);
|
|
267
|
+
const written = ts.isIdentifier(object) ? checker.getSymbolAtLocation(object)?.valueDeclaration : undefined;
|
|
268
|
+
if (written && !writes.has(written))
|
|
269
|
+
writes.set(written, []);
|
|
270
|
+
if (written)
|
|
271
|
+
writes.get(written)?.push({ name: writtenFieldName(node.left), assignment: node });
|
|
272
|
+
}
|
|
273
|
+
ts.forEachChild(node, visit);
|
|
274
|
+
})(scope);
|
|
275
|
+
byScope.set(scope, byDeclaration);
|
|
276
|
+
}
|
|
277
|
+
return byDeclaration.get(declaration) ?? [];
|
|
278
|
+
}
|
|
279
|
+
// A plain `=` statement in the declaration's own block runs whenever the declaration does. A write
|
|
280
|
+
// inside an `if`, a loop or a callback, or a `||=`, may not run, so the field keeps its earlier value.
|
|
281
|
+
function alwaysOverwrites(assignment, declaration) {
|
|
282
|
+
return (assignment.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
283
|
+
ts.isExpressionStatement(assignment.parent) &&
|
|
284
|
+
assignment.parent.parent === declaration.parent.parent.parent);
|
|
285
|
+
}
|
|
220
286
|
// A parameter, a `const`, or a name destructured from either.
|
|
221
287
|
function isStableDeclaration(declaration) {
|
|
222
288
|
let current = declaration;
|
|
@@ -226,6 +292,14 @@ function isStableDeclaration(declaration) {
|
|
|
226
292
|
return true;
|
|
227
293
|
return ts.isVariableDeclaration(current) && !!(current.parent.flags & ts.NodeFlags.Const);
|
|
228
294
|
}
|
|
295
|
+
// Where a rewrite of the binding can happen: a parameter is writable from every closure of the
|
|
296
|
+
// function that declares it, not only from the function that holds the use.
|
|
297
|
+
function rewriteScope(declaration, useBody) {
|
|
298
|
+
let current = declaration;
|
|
299
|
+
while (ts.isBindingElement(current))
|
|
300
|
+
current = current.parent.parent;
|
|
301
|
+
return ts.isParameter(current) ? current.parent : useBody;
|
|
302
|
+
}
|
|
229
303
|
// The use of `identifier` runs only after a guard pinned its value, and the value is not rewritten
|
|
230
304
|
// in the function.
|
|
231
305
|
function isGuardedUse(identifier, use, checker, filename) {
|
|
@@ -243,7 +317,7 @@ function isGuardedUse(identifier, use, checker, filename) {
|
|
|
243
317
|
for (let child = use, parent = use.parent; parent && child !== fn; child = parent, parent = parent.parent) {
|
|
244
318
|
if ((ts.isCaseClause(parent) && literalCase(parent, guard)) ||
|
|
245
319
|
guardedBy(child, parent, (node) => confirms(node, guard), (node) => rejects(node, guard)))
|
|
246
|
-
return !isReassigned(body, symbol, checker);
|
|
320
|
+
return !isReassigned(rewriteScope(declaration, body), symbol, checker);
|
|
247
321
|
}
|
|
248
322
|
return false;
|
|
249
323
|
}
|
|
@@ -271,4 +345,4 @@ function isGuardedByCondition(use, evidence) {
|
|
|
271
345
|
}
|
|
272
346
|
return false;
|
|
273
347
|
}
|
|
274
|
-
export { isGuardedUse, isGuardedByCondition, isReassigned, assignmentsTo };
|
|
348
|
+
export { isBuiltinReference, isGuardedUse, isGuardedByCondition, isReassigned, assignmentsTo, fieldWritesTo, alwaysOverwrites, };
|