loadwise 0.6.2 → 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.
- package/README.md +175 -115
- package/dist/bin/loadwise.js +132 -67
- package/dist/lib/accessibility/analyze.js +5 -3
- package/dist/lib/accessibility/angular-inline.js +9 -11
- package/dist/lib/accessibility/angular-literal.js +39 -0
- package/dist/lib/accessibility/form-context.js +36 -0
- package/dist/lib/accessibility/frame-head.js +92 -0
- package/dist/lib/accessibility/frame-viewport.js +149 -0
- package/dist/lib/accessibility/frontend-detect.js +6 -5
- package/dist/lib/accessibility/jsx-elements.js +13 -3
- package/dist/lib/accessibility/markup-files.js +7 -2
- package/dist/lib/accessibility/rule-ids.js +3 -0
- package/dist/lib/accessibility/rules.js +128 -41
- package/dist/lib/accessibility/site-fixes/buttons.js +5 -1
- package/dist/lib/accessibility/template-attributes.js +5 -3
- package/dist/lib/accessibility/template-elements.js +25 -6
- package/dist/lib/accessibility/template-file.js +40 -25
- package/dist/lib/accessibility/usage.js +10 -2
- package/dist/lib/editor/accessibility-examples.js +6 -1
- package/dist/lib/editor/actions.js +46 -7
- package/dist/lib/editor/apply-fix.js +69 -4
- package/dist/lib/editor/configured-setup.js +63 -0
- package/dist/lib/editor/diagnostics.js +206 -17
- package/dist/lib/editor/dismissals.js +85 -26
- package/dist/lib/editor/editor-document.js +5 -2
- package/dist/lib/editor/editor-launcher.js +170 -0
- package/dist/lib/editor/fix-edits.js +19 -0
- package/dist/lib/editor/jetbrains-setup.js +53 -0
- package/dist/lib/editor/language-server.js +80 -24
- package/dist/lib/editor/managed-config.js +37 -0
- package/dist/lib/editor/native-setup.js +86 -0
- package/dist/lib/editor/perf-watch.js +8 -6
- package/dist/lib/editor/release-vsix.js +61 -0
- package/dist/lib/editor/reliability-examples.js +15 -0
- package/dist/lib/editor/scan-session.js +29 -8
- package/dist/lib/editor/server-commands.js +38 -9
- package/dist/lib/editor/setup-server.js +87 -0
- package/dist/lib/editor/setup-vim.js +63 -0
- package/dist/lib/editor/setup.js +131 -0
- package/dist/lib/editor/stdio-setup.js +6 -0
- package/dist/lib/editor/workspace-files.js +61 -7
- package/dist/lib/editor/workspace-paths.js +41 -1
- package/dist/lib/maintainability/analysis/analyze-source.js +1 -1
- package/dist/lib/maintainability/architecture/architecture.js +4 -4
- package/dist/lib/maintainability/cli/changed-lines.js +20 -2
- package/dist/lib/maintainability/cli/inputs.js +12 -3
- package/dist/lib/maintainability/cli.js +18 -5
- package/dist/lib/maintainability/entry-points/entry-points.js +44 -15
- package/dist/lib/maintainability/entry-points/html-entry-points.js +5 -1
- package/dist/lib/maintainability/examples.js +4 -0
- package/dist/lib/maintainability/quality/functions.js +9 -6
- package/dist/lib/maintainability/quality/limits.js +19 -0
- package/dist/lib/maintainability/quality/size-limits.js +8 -2
- package/dist/lib/maintainability/quality/stray-console.js +62 -1
- package/dist/lib/maintainability/quality/tsconfig-strict.js +2 -0
- package/dist/lib/maintainability/rule-ids.js +3 -0
- package/dist/lib/maintainability/scan-changed.js +4 -1
- package/dist/lib/maintainability/scan-worker.js +6 -2
- package/dist/lib/maintainability/scan.js +21 -8
- package/dist/lib/maintainability/site-fixes/unused-bindings.js +138 -3
- package/dist/lib/maintainability/unused/module-usage.js +43 -21
- package/dist/lib/maintainability/unused/unused-bindings.js +39 -4
- package/dist/lib/maintainability/unused/unused-modules.js +5 -10
- package/dist/lib/performance/analysis/source-inputs.js +7 -2
- package/dist/lib/performance/analysis/source-options.js +7 -6
- package/dist/lib/performance/analyze.js +16 -3
- package/dist/lib/performance/cli/changed-lines.js +8 -1
- package/dist/lib/performance/cli/cli-arguments.js +19 -8
- package/dist/lib/performance/cli/cli-output.js +4 -0
- package/dist/lib/performance/cli/cli-scan.js +21 -2
- package/dist/lib/performance/cli.js +16 -7
- package/dist/lib/performance/collections/memory-growth.js +55 -12
- package/dist/lib/performance/contracts/openapi.js +13 -4
- package/dist/lib/performance/datastores/pg-integrity.js +68 -22
- package/dist/lib/performance/datastores/pg-session-release.js +114 -0
- package/dist/lib/performance/datastores/pg-session-sql.js +144 -0
- package/dist/lib/performance/datastores/pooling.js +62 -3
- package/dist/lib/performance/datastores/redis.js +94 -18
- package/dist/lib/performance/datastores/session-store.js +2 -1
- package/dist/lib/performance/db/checks.js +19 -8
- package/dist/lib/performance/db/gateway.js +3 -1
- package/dist/lib/performance/db/plan-estimates.js +4 -4
- package/dist/lib/performance/engine/native-syntax.js +3 -0
- package/dist/lib/performance/engine/native.js +11 -7
- package/dist/lib/performance/evidence/plans.js +7 -5
- package/dist/lib/performance/evidence/traces.js +21 -1
- package/dist/lib/performance/frontend/angular-teardown.js +96 -0
- package/dist/lib/performance/frontend/effect-cleanup.js +148 -0
- package/dist/lib/performance/frontend/frontend-dom-perf.js +14 -2
- package/dist/lib/performance/frontend/frontend-helpers.js +1 -9
- package/dist/lib/performance/frontend/frontend-perf.js +149 -74
- package/dist/lib/performance/migrations/extract-code-sql.js +16 -4
- package/dist/lib/performance/migrations/extract-code.js +13 -5
- package/dist/lib/performance/migrations/extract-sql.js +82 -38
- package/dist/lib/performance/migrations/operations.js +56 -13
- package/dist/lib/performance/migrations/postgres-lock-timeout.js +52 -0
- package/dist/lib/performance/migrations/postgres-registry.js +127 -26
- package/dist/lib/performance/migrations/postgres-settings.js +78 -0
- package/dist/lib/performance/migrations/rules-postgres-add-column.js +3 -3
- package/dist/lib/performance/migrations/rules-postgres-shared.js +9 -0
- package/dist/lib/performance/migrations/rules-postgres.js +88 -39
- package/dist/lib/performance/orm/offset-pagination.js +6 -4
- package/dist/lib/performance/orm/prisma-aggregates.js +69 -18
- package/dist/lib/performance/orm/unbounded-list-chain.js +29 -0
- package/dist/lib/performance/orm/unbounded-list-queries.js +18 -13
- package/dist/lib/performance/polyglot.js +111 -14
- package/dist/lib/performance/projects.js +3 -3
- package/dist/lib/performance/query-loops/sequential-loops.js +1 -0
- package/dist/lib/performance/request/backend-mastery.js +151 -42
- package/dist/lib/performance/request/bulk-listener-registration.js +111 -0
- package/dist/lib/performance/request/fastify-receivers.js +93 -0
- package/dist/lib/performance/request/fresh-loop-socket.js +103 -0
- package/dist/lib/performance/request/mongoose-lean.js +298 -46
- package/dist/lib/performance/request/node-event-listener-leak.js +99 -5
- package/dist/lib/performance/request/phase5-ast.js +6 -7
- package/dist/lib/performance/request/phase5-rules.js +204 -23
- package/dist/lib/performance/request/request-handlers.js +120 -23
- package/dist/lib/performance/request/sql-select-star.js +150 -0
- package/dist/lib/performance/request/unbounded-promise-all.js +54 -29
- package/dist/lib/performance/request/upload-limits.js +5 -1
- package/dist/lib/performance/site-fix.js +4 -4
- package/dist/lib/performance/site-fixes/backend-mastery-fixes.js +298 -16
- package/dist/lib/performance/site-fixes/collection-existence.js +2 -1
- package/dist/lib/performance/site-fixes/collections.js +1 -2
- package/dist/lib/performance/site-fixes/frontend-fixes.js +358 -14
- package/dist/lib/performance/site-fixes/helpers.js +3 -4
- package/dist/lib/performance/site-fixes/integrity.js +2 -4
- package/dist/lib/performance/site-fixes/migration-context.js +8 -1
- package/dist/lib/performance/site-fixes/migration-lock-rules.js +66 -30
- package/dist/lib/performance/site-fixes/prisma-aggregates.js +29 -9
- package/dist/lib/performance/site-fixes/small-rewrites.js +168 -10
- package/dist/lib/performance/site-fixes/sync-calls.js +14 -12
- package/dist/lib/performance/site-fixes/upload-limits.js +13 -7
- package/dist/lib/performance/sql/mysql-tokens.js +38 -12
- package/dist/lib/reliability/boundary-access.js +114 -57
- package/dist/lib/reliability/react-bugs.js +29 -7
- package/dist/lib/reliability/resource-leak-intervals.js +258 -0
- package/dist/lib/reliability/resource-leaks.js +209 -195
- package/dist/lib/reliability/rule-ids.js +10 -1
- package/dist/lib/reliability/site-fixes/resource-leaks.js +16 -1
- package/dist/lib/reliability/swallowed-errors.js +107 -21
- package/dist/lib/reliability/test-cleanup-after-await.js +92 -18
- package/dist/lib/reliability/usage.js +16 -5
- package/dist/lib/reliability/walk.js +3 -2
- package/dist/lib/security/auth-crypto/hashing.js +24 -8
- package/dist/lib/security/auth-crypto/jwt.js +21 -6
- package/dist/lib/security/auth-crypto/secrets.js +44 -1
- package/dist/lib/security/auth-crypto/shared.js +3 -1
- package/dist/lib/security/auth-crypto/signing-algorithm.js +79 -0
- package/dist/lib/security/auth-crypto/transport-and-ciphers.js +85 -1
- package/dist/lib/security/cli.js +21 -6
- package/dist/lib/security/cookie-credentials.js +115 -0
- package/dist/lib/security/cookie-csrf.js +241 -0
- package/dist/lib/security/deps/advisory.js +50 -109
- package/dist/lib/security/deps/cli.js +1 -1
- package/dist/lib/security/deps/cvss-score.js +14 -0
- package/dist/lib/security/deps/fixed-version.js +97 -0
- package/dist/lib/security/deps/lockfiles.js +135 -74
- package/dist/lib/security/deps/osv.js +11 -3
- package/dist/lib/security/deps/scan.js +47 -20
- package/dist/lib/security/deps/yarn-lock.js +158 -0
- package/dist/lib/security/examples/injection.cjs +4 -0
- package/dist/lib/security/exposure/cookies.js +17 -2
- package/dist/lib/security/exposure/cors-origin-regex.js +2 -3
- package/dist/lib/security/exposure/frontend-security.js +21 -14
- package/dist/lib/security/exposure/jsx-url.js +18 -33
- package/dist/lib/security/exposure/logging.js +49 -10
- package/dist/lib/security/exposure/prototype-pollution.js +126 -56
- package/dist/lib/security/exposure/react-html.js +26 -0
- package/dist/lib/security/exposure/reflected-xss.js +34 -5
- package/dist/lib/security/files/compose.js +126 -1
- package/dist/lib/security/files/dockerfile.js +62 -4
- package/dist/lib/security/files/index.js +1 -1
- package/dist/lib/security/injection/command.js +46 -18
- package/dist/lib/security/injection/index.js +2 -0
- package/dist/lib/security/injection/ldap.js +86 -0
- package/dist/lib/security/injection/nosql.js +28 -4
- package/dist/lib/security/injection/redos.js +1 -1
- package/dist/lib/security/injection/rule-ids.js +1 -0
- package/dist/lib/security/injection/shared.js +5 -1
- package/dist/lib/security/injection/sql.js +28 -13
- package/dist/lib/security/lexical-declaration.js +113 -0
- package/dist/lib/security/pg-dynamic-query.js +28 -1
- package/dist/lib/security/pg-identifier-guards.js +107 -3
- package/dist/lib/security/phase5-rules.js +26 -135
- package/dist/lib/security/polyglot.js +2 -2
- package/dist/lib/security/redirect-settings.js +98 -0
- package/dist/lib/security/request-forgery/open-redirect.js +18 -5
- package/dist/lib/security/request-forgery/path-traversal.js +84 -6
- package/dist/lib/security/request-forgery/shared.js +1 -7
- package/dist/lib/security/request-forgery/ssrf.js +176 -14
- package/dist/lib/security/rule-descriptions.js +5 -1
- package/dist/lib/security/rule-ids.js +7 -0
- package/dist/lib/security/site-fixes/auth-crypto.js +5 -78
- package/dist/lib/security/site-fixes/exposure.js +21 -3
- package/dist/lib/security/site-fixes/files.js +11 -13
- package/dist/lib/security/site-fixes/frontend-security-fixes.js +2 -2
- package/dist/lib/security/site-fixes/injection.js +17 -4
- package/dist/lib/security/site-fixes/jwt.js +1 -20
- package/dist/lib/security/site-fixes/request-forgery.js +37 -29
- package/dist/lib/security/taint/binding-inputs.js +236 -0
- package/dist/lib/security/taint/filename-guard.js +45 -45
- package/dist/lib/security/taint/guards.js +14 -8
- package/dist/lib/security/taint/index.js +126 -154
- package/dist/lib/security/taint/propagate.js +43 -9
- package/dist/lib/security/taint/record-writes.js +161 -0
- package/dist/lib/security/taint/resolution-cache.js +13 -7
- package/dist/lib/security/taint/sanitizers.js +89 -5
- package/dist/lib/security/taint/trace-nodes.js +61 -0
- package/dist/lib/security/taint/validators.js +89 -9
- package/dist/lib/shared/agent/agent-init.js +28 -5
- package/dist/lib/shared/agent/agent-prompt.js +74 -0
- package/dist/lib/shared/agent/agent-session.js +6 -1
- package/dist/lib/shared/agent/agent-verify.js +58 -11
- package/dist/lib/shared/agent/git-hook.js +17 -6
- package/dist/lib/shared/agent/review-delivery.js +1 -1
- package/dist/lib/shared/agent/review-mcp.js +8 -2
- package/dist/lib/shared/analysis/ast-semantics.js +2 -2
- package/dist/lib/shared/analysis/scan-cache.js +99 -14
- package/dist/lib/shared/check.js +172 -20
- package/dist/lib/shared/cli-dispatch.js +17 -0
- package/dist/lib/shared/config.js +27 -10
- package/dist/lib/shared/explain.js +1 -1
- package/dist/lib/shared/fix/fix-convergence.js +19 -31
- package/dist/lib/shared/fix/fix-handoff.js +16 -11
- package/dist/lib/shared/fix/fix-imports.js +4 -162
- package/dist/lib/shared/fix/fix-presentation-comments.js +23 -9
- package/dist/lib/shared/fix/fix-presentation-prettier.js +1 -46
- package/dist/lib/shared/fix/fix-presentation-rows.js +45 -1
- package/dist/lib/shared/fix/fix-presentation.js +9 -6
- package/dist/lib/shared/fix/fix-safety.js +32 -1
- package/dist/lib/shared/fix/fix-scope.js +82 -0
- package/dist/lib/shared/fix/fix-terminal.js +28 -1
- package/dist/lib/shared/fix/fix-typecheck.js +8 -4
- package/dist/lib/shared/fix/import-text-edits.js +148 -0
- package/dist/lib/shared/fix/project-file-access.js +17 -26
- package/dist/lib/shared/fix/read-fix-text.js +20 -0
- package/dist/lib/shared/fix.js +241 -104
- package/dist/lib/shared/formats/finding-location.js +4 -1
- package/dist/lib/shared/formats/github.js +3 -3
- package/dist/lib/shared/formats/sarif.js +9 -3
- package/dist/lib/shared/report-fp.js +97 -0
- package/dist/lib/shared/reporting/automatic-fix-signal.js +10 -0
- package/dist/lib/shared/reporting/baseline.js +7 -5
- package/dist/lib/shared/reporting/check-text.js +50 -0
- package/dist/lib/shared/reporting/pillars.js +54 -19
- package/dist/lib/shared/reporting/source-report.js +3 -0
- package/dist/lib/shared/system/atomic-write.js +5 -2
- package/dist/lib/shared/system/glob.js +34 -8
- package/dist/lib/shared/system/sentry.js +222 -0
- package/dist/lib/shared/system/shell-argument.js +5 -1
- package/dist/lib/shared/system/terminal-safe.js +3 -2
- package/dist/lib/shared/system/terminal-style.js +131 -0
- package/dist/lib/shared/workspaces.js +15 -3
- package/docs/assets/cli-workflow.gif +0 -0
- package/integrations/sublime/plugin.py +22 -0
- package/integrations/zed/Cargo.lock +845 -0
- package/integrations/zed/Cargo.toml +11 -0
- package/integrations/zed/extension.toml +11 -0
- package/integrations/zed/src/lib.rs +25 -0
- package/package.json +15 -3
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/commands/loadwise.md +11 -6
- package/plugin/hooks/check-edited-file.mjs +27 -5
- package/polyglot/performance/rules/csharp.yml +34 -5
- package/polyglot/performance/rules/java.yml +24 -1
- package/polyglot/performance/rules/python.yml +74 -2
- package/polyglot/performance/sgconfig.yml +1 -0
- package/polyglot/reliability/rules/csharp.yml +12 -6
- package/polyglot/reliability/rules/go.yml +86 -6
- package/polyglot/reliability/rules/java.yml +22 -1
- package/polyglot/reliability/sgconfig.yml +1 -0
- package/polyglot/security/rules/go.yml +100 -22
- package/polyglot/security/rules/python.yml +74 -6
- package/polyglot/security/rules/rust.yml +65 -0
- package/polyglot/security/sgconfig.yml +1 -0
- package/schema/loadwise.config.schema.json +556 -76
- /package/polyglot/{performance/rules → shared-rules}/input.yml +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// ssrf-request-url: an outgoing HTTP request whose host a caller chooses.
|
|
2
2
|
import { ts } from '../../performance/engine/compiler.js';
|
|
3
|
+
import { constInitializer, effectiveProperty, unwrapExpression } from '../../shared/analysis/ast-semantics.js';
|
|
3
4
|
import { importedFrom } from '../bindings.js';
|
|
4
|
-
import { strip, propertyValue,
|
|
5
|
+
import { strip, propertyValue, isGlobalIdentifier, hopReason, isAllowedHost, isHostHeader } from './shared.js';
|
|
5
6
|
const ruleId = 'ssrf-request-url';
|
|
6
7
|
const message = (label) => `The request URL host comes from \`${label}\`, so a caller can make this server reach internal addresses. Parse it with \`new URL()\` and allow only known hosts, or build the URL from a fixed origin.`;
|
|
7
8
|
const hostHeaderReason = 'The host comes from the Host header; a reverse proxy that accepts only known hosts makes this unreachable.';
|
|
@@ -25,9 +26,10 @@ const clients = {
|
|
|
25
26
|
'@nestjs/axios': 'url',
|
|
26
27
|
};
|
|
27
28
|
const fetchModules = new Set(['node-fetch', 'cross-fetch', 'isomorphic-fetch', 'undici']);
|
|
29
|
+
const nodeAgentModules = new Set(['node-fetch', 'cross-fetch', 'isomorphic-fetch', 'needle']);
|
|
28
30
|
// Agents from these packages refuse private and loopback addresses.
|
|
29
31
|
const filterModules = new Set(['ssrf-req-filter', 'request-filtering-agent']);
|
|
30
|
-
const
|
|
32
|
+
const allTransports = ['http', 'https'];
|
|
31
33
|
// `const api = axios.create(...)`, so `api.get(url)` is recognised without installed types.
|
|
32
34
|
function createdClient(receiver, context) {
|
|
33
35
|
const node = strip(receiver);
|
|
@@ -85,7 +87,7 @@ function urlArguments(call, client) {
|
|
|
85
87
|
for (const name of ['url', 'baseURL', 'prefixUrl', 'origin']) {
|
|
86
88
|
const value = propertyValue(first, name);
|
|
87
89
|
if (value)
|
|
88
|
-
found.push({ expression: value, hostOnly: false });
|
|
90
|
+
found.push({ expression: value, hostOnly: false, overridable: name === 'baseURL' });
|
|
89
91
|
}
|
|
90
92
|
for (const name of ['hostname', 'host']) {
|
|
91
93
|
const value = propertyValue(first, name);
|
|
@@ -94,23 +96,183 @@ function urlArguments(call, client) {
|
|
|
94
96
|
}
|
|
95
97
|
return found;
|
|
96
98
|
}
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
function optionsObject(expression, context) {
|
|
100
|
+
let current = unwrapExpression(expression);
|
|
101
|
+
for (let depth = 0; depth < 4 && ts.isIdentifier(current); depth++) {
|
|
102
|
+
const initializer = constInitializer(current, context.checker);
|
|
103
|
+
if (!initializer)
|
|
104
|
+
return;
|
|
105
|
+
current = initializer;
|
|
106
|
+
}
|
|
107
|
+
return ts.isObjectLiteralExpression(current) ? current : undefined;
|
|
108
|
+
}
|
|
109
|
+
function effectiveOption(options, name, context) {
|
|
110
|
+
const property = effectiveProperty(options, name, { guardSpreadGetters: true });
|
|
111
|
+
if (!property || property === 'unknown')
|
|
112
|
+
return;
|
|
113
|
+
if (ts.isPropertyAssignment(property))
|
|
114
|
+
return property.initializer;
|
|
115
|
+
if (ts.isShorthandPropertyAssignment(property)) {
|
|
116
|
+
return constInitializer(property.name, context.checker) ?? property.name;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function protocolFromPrefix(text) {
|
|
120
|
+
if (/^https:\/\//i.test(text))
|
|
121
|
+
return 'https';
|
|
122
|
+
if (/^http:\/\//i.test(text))
|
|
123
|
+
return 'http';
|
|
124
|
+
}
|
|
125
|
+
function possibleTransports(expression, context, depth = 0) {
|
|
126
|
+
if (depth >= 4)
|
|
127
|
+
return new Set(allTransports);
|
|
128
|
+
const value = unwrapExpression(expression);
|
|
129
|
+
if (ts.isIdentifier(value)) {
|
|
130
|
+
const initializer = constInitializer(value, context.checker);
|
|
131
|
+
return initializer ? possibleTransports(initializer, context, depth + 1) : new Set(allTransports);
|
|
132
|
+
}
|
|
133
|
+
if (ts.isStringLiteralLike(value)) {
|
|
134
|
+
const fixed = protocolFromPrefix(value.text);
|
|
135
|
+
return fixed ? new Set([fixed]) : new Set(allTransports);
|
|
136
|
+
}
|
|
137
|
+
if (ts.isTemplateExpression(value)) {
|
|
138
|
+
const fixed = protocolFromPrefix(value.head.text);
|
|
139
|
+
return fixed ? new Set([fixed]) : new Set(allTransports);
|
|
140
|
+
}
|
|
141
|
+
if (ts.isBinaryExpression(value) && value.operatorToken.kind === ts.SyntaxKind.PlusToken) {
|
|
142
|
+
const left = possibleTransports(value.left, context, depth + 1);
|
|
143
|
+
if (left.size === 1)
|
|
144
|
+
return left;
|
|
145
|
+
}
|
|
146
|
+
if (ts.isNewExpression(value) && (value.arguments?.length === 1 || value.arguments?.length === 2)) {
|
|
147
|
+
return possibleTransports(value.arguments[0], context, depth + 1);
|
|
148
|
+
}
|
|
149
|
+
return new Set(allTransports);
|
|
150
|
+
}
|
|
151
|
+
function requiredTransports(candidates, client, context) {
|
|
152
|
+
if (client.module === 'http')
|
|
153
|
+
return new Set(['http']);
|
|
154
|
+
if (client.module === 'https')
|
|
155
|
+
return new Set(['https']);
|
|
156
|
+
const required = new Set();
|
|
157
|
+
const hasAbsoluteUrl = candidates.some((candidate) => !candidate.overridable && possibleTransports(candidate.expression, context).size === 1);
|
|
158
|
+
for (const candidate of candidates) {
|
|
159
|
+
if (candidate.overridable && hasAbsoluteUrl)
|
|
160
|
+
continue;
|
|
161
|
+
for (const transport of possibleTransports(candidate.expression, context))
|
|
162
|
+
required.add(transport);
|
|
163
|
+
}
|
|
164
|
+
return required;
|
|
165
|
+
}
|
|
166
|
+
function singleReturnExpression(body) {
|
|
167
|
+
const [statement] = body.statements;
|
|
168
|
+
if (body.statements.length !== 1 || !ts.isReturnStatement(statement))
|
|
169
|
+
return;
|
|
170
|
+
return statement.expression;
|
|
171
|
+
}
|
|
172
|
+
function filteringFactoryTransports(value, context) {
|
|
173
|
+
let root = unwrapExpression(value.expression);
|
|
174
|
+
const memberName = ts.isPropertyAccessExpression(root) ? root.name.text : undefined;
|
|
175
|
+
while (root && (ts.isCallExpression(root) || ts.isNewExpression(root) || ts.isPropertyAccessExpression(root)))
|
|
176
|
+
root = unwrapExpression(root.expression);
|
|
177
|
+
const binding = root && ts.isIdentifier(root) && importedFrom(root, context.checker);
|
|
178
|
+
if (!binding || !filterModules.has(binding.module))
|
|
179
|
+
return;
|
|
180
|
+
const exported = memberName ?? binding.exported;
|
|
181
|
+
if (binding.module === 'request-filtering-agent') {
|
|
182
|
+
if (exported === 'RequestFilteringHttpAgent')
|
|
183
|
+
return new Set(['http']);
|
|
184
|
+
if (exported === 'RequestFilteringHttpsAgent')
|
|
185
|
+
return new Set(['https']);
|
|
186
|
+
}
|
|
187
|
+
return new Set(allTransports);
|
|
188
|
+
}
|
|
189
|
+
function filteringSingletonTransports(value, context) {
|
|
190
|
+
const root = unwrapExpression(value.expression);
|
|
191
|
+
const binding = ts.isIdentifier(root) && importedFrom(root, context.checker);
|
|
192
|
+
if (!binding || !filterModules.has(binding.module))
|
|
193
|
+
return;
|
|
194
|
+
if (binding.module === 'request-filtering-agent') {
|
|
195
|
+
if (value.name.text === 'globalHttpAgent')
|
|
196
|
+
return new Set(['http']);
|
|
197
|
+
if (value.name.text === 'globalHttpsAgent')
|
|
198
|
+
return new Set(['https']);
|
|
199
|
+
}
|
|
200
|
+
return new Set(allTransports);
|
|
201
|
+
}
|
|
202
|
+
function filteringAgentTransports(expression, context, depth = 0) {
|
|
203
|
+
if (depth >= 4)
|
|
204
|
+
return;
|
|
205
|
+
const value = unwrapExpression(expression);
|
|
206
|
+
if (ts.isIdentifier(value)) {
|
|
207
|
+
const binding = importedFrom(value, context.checker);
|
|
208
|
+
if (binding && filterModules.has(binding.module))
|
|
209
|
+
return new Set(allTransports);
|
|
210
|
+
const initializer = constInitializer(value, context.checker);
|
|
211
|
+
return initializer ? filteringAgentTransports(initializer, context, depth + 1) : undefined;
|
|
212
|
+
}
|
|
213
|
+
if (ts.isArrowFunction(value) && !ts.isBlock(value.body))
|
|
214
|
+
return filteringAgentTransports(value.body, context, depth + 1);
|
|
215
|
+
if (ts.isArrowFunction(value) || ts.isFunctionExpression(value)) {
|
|
216
|
+
const returned = ts.isBlock(value.body) ? singleReturnExpression(value.body) : undefined;
|
|
217
|
+
return returned && filteringAgentTransports(returned, context, depth + 1);
|
|
218
|
+
}
|
|
219
|
+
if (ts.isPropertyAccessExpression(value))
|
|
220
|
+
return filteringSingletonTransports(value, context);
|
|
221
|
+
if (ts.isCallExpression(value) || ts.isNewExpression(value))
|
|
222
|
+
return filteringFactoryTransports(value, context);
|
|
223
|
+
}
|
|
224
|
+
function addOptionTransports(target, expr, restrictTo, context) {
|
|
225
|
+
const transports = expr ? filteringAgentTransports(expr, context) : undefined;
|
|
226
|
+
if (!transports)
|
|
227
|
+
return;
|
|
228
|
+
for (const transport of transports) {
|
|
229
|
+
if (!restrictTo || transport === restrictTo)
|
|
230
|
+
target.add(transport);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function coveredTransports(call, client, context) {
|
|
234
|
+
const covered = new Set();
|
|
235
|
+
for (const argument of call.arguments) {
|
|
236
|
+
const options = optionsObject(argument, context);
|
|
237
|
+
if (!options)
|
|
238
|
+
continue;
|
|
239
|
+
if (client.module === 'axios' || client.module === '@nestjs/axios') {
|
|
240
|
+
addOptionTransports(covered, effectiveOption(options, 'httpAgent', context), 'http', context);
|
|
241
|
+
addOptionTransports(covered, effectiveOption(options, 'httpsAgent', context), 'https', context);
|
|
242
|
+
}
|
|
243
|
+
else if (client.module === 'http') {
|
|
244
|
+
addOptionTransports(covered, effectiveOption(options, 'agent', context), 'http', context);
|
|
245
|
+
}
|
|
246
|
+
else if (client.module === 'https') {
|
|
247
|
+
addOptionTransports(covered, effectiveOption(options, 'agent', context), 'https', context);
|
|
248
|
+
}
|
|
249
|
+
else if (client.module === 'got') {
|
|
250
|
+
const agent = effectiveOption(options, 'agent', context);
|
|
251
|
+
const agentOptions = agent && optionsObject(agent, context);
|
|
252
|
+
if (agentOptions) {
|
|
253
|
+
addOptionTransports(covered, effectiveOption(agentOptions, 'http', context), 'http', context);
|
|
254
|
+
addOptionTransports(covered, effectiveOption(agentOptions, 'https', context), 'https', context);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else if (nodeAgentModules.has(client.module)) {
|
|
258
|
+
addOptionTransports(covered, effectiveOption(options, 'agent', context), undefined, context);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return covered;
|
|
262
|
+
}
|
|
263
|
+
function hasFilteringAgent(call, candidates, client, context) {
|
|
264
|
+
const required = requiredTransports(candidates, client, context);
|
|
265
|
+
if (!required.size)
|
|
266
|
+
return false;
|
|
267
|
+
const covered = coveredTransports(call, client, context);
|
|
268
|
+
return [...required].every((transport) => covered.has(transport));
|
|
107
269
|
}
|
|
108
270
|
function checkRequestUrl(call, context) {
|
|
109
271
|
const client = clientCall(call, context);
|
|
110
272
|
if (!client)
|
|
111
273
|
return;
|
|
112
274
|
const candidates = urlArguments(call, client);
|
|
113
|
-
if (!candidates.length || hasFilteringAgent(call, context))
|
|
275
|
+
if (!candidates.length || hasFilteringAgent(call, candidates, client, context))
|
|
114
276
|
return;
|
|
115
277
|
for (const { expression, hostOnly } of candidates) {
|
|
116
278
|
const control = hostOnly ? hostControl(expression, context) : context.taint.urlControl(expression);
|
|
@@ -29,6 +29,7 @@ const descriptionByRule = {
|
|
|
29
29
|
'frontend-storage-secret-token': 'A token, JWT, password or API key is stored in localStorage or sessionStorage, readable by any script on the page.',
|
|
30
30
|
'go-exec-command-shell': 'exec.Command invokes a shell, which risks command injection.',
|
|
31
31
|
'go-sql-sprintf-injection': 'SQL text formatted with fmt.Sprintf risks SQL injection.',
|
|
32
|
+
'go-tls-insecure-skip-verify': 'Setting InsecureSkipVerify: true on tls.Config disables TLS certificate verification.',
|
|
32
33
|
'graphql-batching-unbounded': 'GraphQL query batching is enabled without a batch size, query depth, or cost/complexity limit.',
|
|
33
34
|
'graphql-introspection-enabled': 'A GraphQL server explicitly enables schema introspection.',
|
|
34
35
|
'graphql-query-depth-unbounded': 'A GraphQL server accepts queries of any depth.',
|
|
@@ -44,6 +45,7 @@ const descriptionByRule = {
|
|
|
44
45
|
'jwt-verify-without-algorithms': 'JWT verification does not restrict the accepted signing algorithms.',
|
|
45
46
|
'jwt-weak-secret-literal': 'JWT signing or verification uses a short (< 32 chars) or weak literal secret susceptible to brute-force forgery.',
|
|
46
47
|
'knex-raw-dynamic-text': 'A dynamic SQL fragment reaches Knex without parameter binding.',
|
|
48
|
+
'ldap-filter-injection': 'Request data reaches an LDAP search filter without RFC 4515 filter escaping or a filter builder.',
|
|
47
49
|
'mass-assignment': 'An unfiltered request body reaches a persistence operation.',
|
|
48
50
|
'mysql-dynamic-query-text': 'Dynamic SQL text reaches a MySQL client without parameter binding.',
|
|
49
51
|
'nest-validation-without-whitelist': 'A NestJS ValidationPipe permits properties outside the validated DTO.',
|
|
@@ -59,13 +61,15 @@ const descriptionByRule = {
|
|
|
59
61
|
'prisma-scope-unverified': 'A Prisma operation lacks the row scope required by the declared policy.',
|
|
60
62
|
'prototype-pollution': 'Request data can supply keys to a write or merge that can modify an object prototype.',
|
|
61
63
|
'python-insecure-deserialization': 'pickle or marshal deserialization of untrusted data can execute arbitrary code.',
|
|
64
|
+
'python-requests-tls-verify-disabled': 'Calling Python requests with verify=False disables TLS certificate verification.',
|
|
62
65
|
'python-subprocess-shell-true': 'subprocess with shell=True or os.system passes input through a shell, risking command injection.',
|
|
63
|
-
'python-unsafe-yaml-load': 'yaml.load without SafeLoader can construct arbitrary Python objects.',
|
|
66
|
+
'python-unsafe-yaml-load': 'yaml.load or yaml.load_all without SafeLoader can construct arbitrary Python objects.',
|
|
64
67
|
'react-dangerously-set-inner-html': 'dangerouslySetInnerHTML receives HTML that is not a constant or sanitized.',
|
|
65
68
|
'reflected-xss-response': 'An HTML response reflects request data without recognized escaping.',
|
|
66
69
|
'regex-catastrophic-backtracking': 'A regular expression that can backtrack exponentially or in polynomial time runs on request input.',
|
|
67
70
|
'regex-from-input': 'Request input supplies a regular expression pattern without recognized escaping.',
|
|
68
71
|
'rust-command-shell': 'Command::new("sh") or Command::new("bash") spawns a shell and risks command injection.',
|
|
72
|
+
'rust-reqwest-danger-accept-invalid-certs': 'Calling danger_accept_invalid_certs(true) on a reqwest client disables TLS certificate verification.',
|
|
69
73
|
'rust-unsafe-raw-pointer-deref': 'A raw pointer dereference in an unsafe block bypasses Rust memory safety guarantees.',
|
|
70
74
|
'secret-compared-non-constant-time': 'A secret is compared with an operation that can vary in timing with its contents.',
|
|
71
75
|
'secret-in-log': 'A log statement can expose a credential, token, or other secret.',
|
|
@@ -69,6 +69,7 @@ const impactByRule = {
|
|
|
69
69
|
'frontend-storage-secret-token': 'medium',
|
|
70
70
|
'go-exec-command-shell': 'high',
|
|
71
71
|
'go-sql-sprintf-injection': 'high',
|
|
72
|
+
'go-tls-insecure-skip-verify': 'high',
|
|
72
73
|
'graphql-batching-unbounded': 'medium',
|
|
73
74
|
'graphql-introspection-enabled': 'medium',
|
|
74
75
|
'graphql-query-depth-unbounded': 'medium',
|
|
@@ -84,6 +85,7 @@ const impactByRule = {
|
|
|
84
85
|
'jwt-verify-without-algorithms': 'high',
|
|
85
86
|
'jwt-weak-secret-literal': 'high',
|
|
86
87
|
'knex-raw-dynamic-text': 'critical',
|
|
88
|
+
'ldap-filter-injection': 'high',
|
|
87
89
|
'mass-assignment': 'high',
|
|
88
90
|
'mysql-dynamic-query-text': 'critical',
|
|
89
91
|
'nest-validation-without-whitelist': 'medium',
|
|
@@ -99,6 +101,7 @@ const impactByRule = {
|
|
|
99
101
|
'prisma-scope-unverified': 'high',
|
|
100
102
|
'prototype-pollution': 'high',
|
|
101
103
|
'python-insecure-deserialization': 'high',
|
|
104
|
+
'python-requests-tls-verify-disabled': 'high',
|
|
102
105
|
'python-subprocess-shell-true': 'high',
|
|
103
106
|
'python-unsafe-yaml-load': 'high',
|
|
104
107
|
'react-dangerously-set-inner-html': 'high',
|
|
@@ -106,6 +109,7 @@ const impactByRule = {
|
|
|
106
109
|
'regex-catastrophic-backtracking': 'high',
|
|
107
110
|
'regex-from-input': 'medium',
|
|
108
111
|
'rust-command-shell': 'high',
|
|
112
|
+
'rust-reqwest-danger-accept-invalid-certs': 'high',
|
|
109
113
|
'rust-unsafe-raw-pointer-deref': 'medium',
|
|
110
114
|
'secret-compared-non-constant-time': 'medium',
|
|
111
115
|
'secret-in-log': 'high',
|
|
@@ -134,12 +138,15 @@ const polyglotRules = [
|
|
|
134
138
|
'csharp-process-start',
|
|
135
139
|
'go-exec-command-shell',
|
|
136
140
|
'go-sql-sprintf-injection',
|
|
141
|
+
'go-tls-insecure-skip-verify',
|
|
137
142
|
'java-runtime-exec',
|
|
138
143
|
'java-sql-string-concat',
|
|
139
144
|
'python-insecure-deserialization',
|
|
145
|
+
'python-requests-tls-verify-disabled',
|
|
140
146
|
'python-subprocess-shell-true',
|
|
141
147
|
'python-unsafe-yaml-load',
|
|
142
148
|
'rust-command-shell',
|
|
149
|
+
'rust-reqwest-danger-accept-invalid-certs',
|
|
143
150
|
'rust-unsafe-raw-pointer-deref',
|
|
144
151
|
];
|
|
145
152
|
const securityRules = Object.keys(ruleInfo);
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
import { calleeName } from '../../performance/analysis/call-syntax.js';
|
|
4
4
|
import { ts, addProperty, ancestor, calleeCall, replaceNode, requireReview, } from '../../performance/site-fixes/helpers.js';
|
|
5
5
|
import { effectiveProperty } from '../../shared/analysis/ast-semantics.js';
|
|
6
|
+
import { signingSourceHash } from '../auth-crypto/signing-algorithm.js';
|
|
6
7
|
import { nameText } from '../exposure/literals.js';
|
|
7
8
|
const suggestedBcryptCost = 12;
|
|
8
|
-
const defaultSigningAlgorithm = 'HS256';
|
|
9
9
|
const secureRandomImport = "import { randomInt } from 'node:crypto';";
|
|
10
10
|
function tlsVerificationFix({ finding, node }) {
|
|
11
11
|
if (!node || finding.contextualReason)
|
|
@@ -55,87 +55,14 @@ function bcryptCostFix({ node }) {
|
|
|
55
55
|
note: `${suggestedBcryptCost} is a common choice; measure the hashing time on your hardware and adjust.`,
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
// review.
|
|
60
|
-
function keyReference(node) {
|
|
61
|
-
const expression = ts.skipOuterExpressions(node);
|
|
62
|
-
if (ts.isIdentifier(expression))
|
|
63
|
-
return expression.text;
|
|
64
|
-
if (expression.kind === ts.SyntaxKind.ThisKeyword)
|
|
65
|
-
return 'this';
|
|
66
|
-
if (!ts.isPropertyAccessExpression(expression) || expression.questionDotToken)
|
|
67
|
-
return;
|
|
68
|
-
const root = keyReference(expression.expression);
|
|
69
|
-
return root && root + '.' + expression.name.text;
|
|
70
|
-
}
|
|
71
|
-
function signerFor(verify, sourceFile) {
|
|
72
|
-
const callee = ts.skipOuterExpressions(verify.expression);
|
|
73
|
-
if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression))
|
|
74
|
-
return callee.expression.text + '.sign';
|
|
75
|
-
if (!ts.isIdentifier(callee))
|
|
76
|
-
return;
|
|
77
|
-
for (const statement of sourceFile.statements) {
|
|
78
|
-
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))
|
|
79
|
-
continue;
|
|
80
|
-
if (statement.moduleSpecifier.text !== 'jsonwebtoken')
|
|
81
|
-
continue;
|
|
82
|
-
const names = statement.importClause?.namedBindings;
|
|
83
|
-
if (!names || !ts.isNamedImports(names))
|
|
84
|
-
continue;
|
|
85
|
-
const signer = names.elements.find((item) => (item.propertyName ?? item.name).text === 'sign');
|
|
86
|
-
if (signer)
|
|
87
|
-
return signer.name.text;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function algorithmInSignOptions(call) {
|
|
91
|
-
const argument = call.arguments[2];
|
|
92
|
-
if (!argument)
|
|
93
|
-
return defaultSigningAlgorithm;
|
|
94
|
-
const options = ts.skipOuterExpressions(argument);
|
|
95
|
-
if (ts.isArrowFunction(options) || ts.isFunctionExpression(options))
|
|
96
|
-
return defaultSigningAlgorithm;
|
|
97
|
-
if (!ts.isObjectLiteralExpression(options) || effectiveProperty(options, 'algorithms') !== undefined)
|
|
98
|
-
return;
|
|
99
|
-
let algorithm = defaultSigningAlgorithm;
|
|
100
|
-
for (const property of options.properties) {
|
|
101
|
-
if (!ts.isPropertyAssignment(property) || ts.isComputedPropertyName(property.name))
|
|
102
|
-
return;
|
|
103
|
-
if (property.name.text === 'header')
|
|
104
|
-
return;
|
|
105
|
-
if (property.name.text !== 'algorithm')
|
|
106
|
-
continue;
|
|
107
|
-
const value = ts.skipOuterExpressions(property.initializer);
|
|
108
|
-
if (!ts.isStringLiteralLike(value) || !/^(?:HS|RS|PS|ES)(?:256|384|512)$/.test(value.text))
|
|
109
|
-
return;
|
|
110
|
-
algorithm = value.text;
|
|
111
|
-
}
|
|
112
|
-
return algorithm;
|
|
113
|
-
}
|
|
114
|
-
function signingAlgorithm(sourceFile, verify) {
|
|
115
|
-
const key = keyReference(verify.arguments[1]);
|
|
116
|
-
const signer = signerFor(verify, sourceFile);
|
|
117
|
-
if (!key || !signer)
|
|
118
|
-
return;
|
|
119
|
-
const algorithms = new Set();
|
|
120
|
-
function visit(node) {
|
|
121
|
-
if (ts.isCallExpression(node) &&
|
|
122
|
-
node.arguments.length >= 2 &&
|
|
123
|
-
keyReference(node.expression) === signer &&
|
|
124
|
-
keyReference(node.arguments[1]) === key)
|
|
125
|
-
algorithms.add(algorithmInSignOptions(node));
|
|
126
|
-
ts.forEachChild(node, visit);
|
|
127
|
-
}
|
|
128
|
-
visit(sourceFile);
|
|
129
|
-
return algorithms.size === 1 ? [...algorithms][0] : undefined;
|
|
130
|
-
}
|
|
131
|
-
function jwtVerifyFix({ node, sourceFile, text }) {
|
|
58
|
+
function jwtVerifyFix({ finding, node, text, sourceFile }) {
|
|
132
59
|
const call = node && calleeCall(node);
|
|
133
|
-
if (!call || !sourceFile ||
|
|
60
|
+
if (!call || text === undefined || !sourceFile || finding.signingSourceHash !== signingSourceHash(sourceFile))
|
|
134
61
|
return;
|
|
135
62
|
if (calleeName(call) !== 'verify' || call.arguments.length < 2)
|
|
136
63
|
return;
|
|
137
|
-
const algorithm = signingAlgorithm
|
|
138
|
-
if (
|
|
64
|
+
const algorithm = finding.signingAlgorithm;
|
|
65
|
+
if (typeof algorithm !== 'string' || !/^(?:HS|RS|PS|ES)(?:256|384|512)$/.test(algorithm))
|
|
139
66
|
return;
|
|
140
67
|
const property = `algorithms: ['${algorithm}']`;
|
|
141
68
|
const options = call.arguments[2] && ts.skipOuterExpressions(call.arguments[2]);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// lib/performance/site-fix.cjs.
|
|
3
3
|
import { ts, ancestor, calleeCall, addProperty, addOptionsArgument, replaceNode, requireReview, } from '../../performance/site-fixes/helpers.js';
|
|
4
4
|
import { buildFix as corsOriginRegexFix } from '../exposure/cors-origin-regex.js';
|
|
5
|
+
import { isScriptReadableCookieName } from '../exposure/cookies.js';
|
|
5
6
|
import { unwrap, findProperty, isFullyLiteral, isFalse, isTrue } from '../exposure/literals.js';
|
|
6
7
|
const cookieMethods = new Set(['cookie', 'setCookie']);
|
|
7
8
|
const nonProductionCheck = "process.env.NODE_ENV !== 'production'";
|
|
@@ -16,6 +17,8 @@ function cookieFix({ node, text }) {
|
|
|
16
17
|
const callee = call && unwrap(call.expression);
|
|
17
18
|
if (!call || !callee || !ts.isPropertyAccessExpression(callee) || !cookieMethods.has(callee.name.text))
|
|
18
19
|
return;
|
|
20
|
+
if (call.arguments[0] && isScriptReadableCookieName(call.arguments[0]))
|
|
21
|
+
return;
|
|
19
22
|
const options = call.arguments[2] && unwrap(call.arguments[2]);
|
|
20
23
|
if (!options && call.arguments.length === 2)
|
|
21
24
|
return { edits: [addOptionsArgument(call, 'httpOnly: true', text)] };
|
|
@@ -86,10 +89,25 @@ function secretInLogFix({ node }) {
|
|
|
86
89
|
if (!call || call.arguments.length < 1)
|
|
87
90
|
return;
|
|
88
91
|
const arg = call.arguments.find((candidate) => candidate.pos <= node.pos && node.end <= candidate.end);
|
|
89
|
-
if (!arg
|
|
90
|
-
return;
|
|
92
|
+
if (!arg)
|
|
93
|
+
return;
|
|
94
|
+
const marker = "'[REDACTED]'";
|
|
95
|
+
let edit;
|
|
96
|
+
if (ts.isIdentifier(arg) && node === arg)
|
|
97
|
+
edit = replaceNode(arg, marker);
|
|
98
|
+
else {
|
|
99
|
+
if (!ts.isObjectLiteralExpression(arg))
|
|
100
|
+
return;
|
|
101
|
+
const property = arg.properties.find((item) => item.pos <= node.pos && node.end <= item.end);
|
|
102
|
+
if (property && ts.isShorthandPropertyAssignment(property) && !property.objectAssignmentInitializer)
|
|
103
|
+
edit = replaceNode(property, `${property.name.text}: ${marker}`);
|
|
104
|
+
else if (property && ts.isPropertyAssignment(property) && ts.isIdentifier(property.initializer))
|
|
105
|
+
edit = replaceNode(property.initializer, marker);
|
|
106
|
+
else
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
91
109
|
return {
|
|
92
|
-
edits: [
|
|
110
|
+
edits: [edit],
|
|
93
111
|
note: "Replaces the logged secret argument with `'[REDACTED]'`.",
|
|
94
112
|
};
|
|
95
113
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { previousNumericUser } from '../files/dockerfile.js';
|
|
1
2
|
import { requireReview } from '../../performance/site-fixes/helpers.js';
|
|
2
3
|
function dockerfileRunsAsRootFix({ finding, text }) {
|
|
3
4
|
if (text === undefined || finding.line === undefined)
|
|
@@ -7,19 +8,16 @@ function dockerfileRunsAsRootFix({ finding, text }) {
|
|
|
7
8
|
if (lineIndex < 0 || lineIndex >= lines.length)
|
|
8
9
|
return;
|
|
9
10
|
const targetLine = lines[lineIndex];
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const cmdIndex = lines.findLastIndex((line) => /^\s*(?:CMD|ENTRYPOINT)\b/i.test(line));
|
|
18
|
-
const insertAt = cmdIndex >= 0 ? lines.slice(0, cmdIndex).join('\n').length + (cmdIndex > 0 ? 1 : 0) : text.length;
|
|
19
|
-
const prefix = insertAt === text.length && text.length > 0 && !text.endsWith('\n') ? '\n' : '';
|
|
11
|
+
const explicitRoot = /^(\s*USER[ \t]+)((?:root|0)(?::[a-z0-9_.-]+)?)[ \t]*\r?$/i.exec(targetLine);
|
|
12
|
+
if (!explicitRoot)
|
|
13
|
+
return;
|
|
14
|
+
const user = previousNumericUser(text, finding.line);
|
|
15
|
+
if (!user)
|
|
16
|
+
return;
|
|
17
|
+
const start = lines.slice(0, lineIndex).join('\n').length + (lineIndex > 0 ? 1 : 0) + explicitRoot[1].length;
|
|
20
18
|
return {
|
|
21
|
-
edits: [{ start
|
|
22
|
-
note: '
|
|
19
|
+
edits: [{ start, end: start + explicitRoot[2].length, text: user }],
|
|
20
|
+
note: 'Restores the numeric USER selected earlier in the final stage.',
|
|
23
21
|
};
|
|
24
22
|
}
|
|
25
23
|
function dockerfileAddRemoteUrlFix({ finding, text }) {
|
|
@@ -39,7 +37,7 @@ function dockerfileAddRemoteUrlFix({ finding, text }) {
|
|
|
39
37
|
};
|
|
40
38
|
}
|
|
41
39
|
const builders = {
|
|
42
|
-
'dockerfile-runs-as-root': requireReview('
|
|
40
|
+
'dockerfile-runs-as-root': requireReview('Confirm the earlier UID is appropriate for runtime and can access the required files.', dockerfileRunsAsRootFix),
|
|
43
41
|
'dockerfile-add-remote-url': requireReview('Ensure `curl` is installed in the image and verify a SHA-256 checksum for the downloaded file.', dockerfileAddRemoteUrlFix),
|
|
44
42
|
};
|
|
45
43
|
export default builders;
|
|
@@ -45,8 +45,8 @@ function postMessageOriginFix({ node }) {
|
|
|
45
45
|
note: 'Restricted the `postMessage` target origin from `*` to the current origin. A page served from a `file:` URL has the origin `null`, which `postMessage` rejects.',
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
function dangerouslySetInnerHtmlFix({ node, sourceFile,
|
|
49
|
-
if (!node || !sourceFile ||
|
|
48
|
+
function dangerouslySetInnerHtmlFix({ node, sourceFile, finding }) {
|
|
49
|
+
if (!node || !sourceFile || finding.hasDomPurify !== true)
|
|
50
50
|
return;
|
|
51
51
|
const attr = ancestor(node, ts.isJsxAttribute);
|
|
52
52
|
if (!attr || attr.name.getText(sourceFile) !== 'dangerouslySetInnerHTML')
|
|
@@ -28,11 +28,24 @@ function wrapInEquality({ node, sourceFile }) {
|
|
|
28
28
|
function regexFromInputFix({ node, sourceFile }) {
|
|
29
29
|
if (!node || !sourceFile)
|
|
30
30
|
return;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
// The scanner reports the pattern, which may itself contain a call or sit inside another constructor.
|
|
32
|
+
let patternArg = node;
|
|
33
|
+
while (patternArg.parent && patternArg.parent.getStart(sourceFile) === node.getStart(sourceFile)) {
|
|
34
|
+
patternArg = patternArg.parent;
|
|
35
|
+
}
|
|
36
|
+
const owner = patternArg.parent;
|
|
37
|
+
if (!(ts.isNewExpression(owner) || ts.isCallExpression(owner)) || owner.arguments?.[0] !== patternArg)
|
|
38
|
+
return;
|
|
39
|
+
const callee = ts.skipOuterExpressions(owner.expression);
|
|
40
|
+
const method = ts.isPropertyAccessExpression(callee)
|
|
41
|
+
? callee.name.text
|
|
42
|
+
: ts.isElementAccessExpression(callee) && ts.isStringLiteralLike(callee.argumentExpression)
|
|
43
|
+
? callee.argumentExpression.text
|
|
44
|
+
: undefined;
|
|
45
|
+
const supported = (ts.isIdentifier(callee) && callee.text === 'RegExp') ||
|
|
46
|
+
(ts.isCallExpression(owner) && method !== undefined && ['match', 'matchAll', 'search'].includes(method));
|
|
47
|
+
if (!supported || ts.isSpreadElement(patternArg))
|
|
34
48
|
return;
|
|
35
|
-
const patternArg = callExpr.arguments[0];
|
|
36
49
|
if (ts.isStringLiteralLike(patternArg) || ts.isRegularExpressionLiteral(patternArg))
|
|
37
50
|
return;
|
|
38
51
|
const exprText = patternArg.getText(sourceFile);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Rule id -> build({ finding, node, sourceFile, text, load }) => { edits, note } | undefined; see
|
|
2
2
|
// lib/performance/site-fix.cjs.
|
|
3
3
|
import { calleeName } from '../../performance/analysis/call-syntax.js';
|
|
4
|
-
import { ts, ancestor, calleeCall, addProperty, addOptionsArgument
|
|
4
|
+
import { ts, ancestor, calleeCall, addProperty, addOptionsArgument } from '../../performance/site-fixes/helpers.js';
|
|
5
5
|
import { removeListItem } from './list-edits.js';
|
|
6
6
|
const expiryPlaceholder = "expiresIn: '15m'";
|
|
7
7
|
const expiryNote = 'The 15 minute lifetime is a placeholder: set it from how long this token may stay valid, and check that clients refresh or re-authenticate when it ends. Tokens already issued keep their old lifetime. Only an object-literal payload is edited: jsonwebtoken rejects `expiresIn` for a string payload.';
|
|
@@ -63,27 +63,8 @@ function noneFix({ node }) {
|
|
|
63
63
|
const edit = removeListItem(list.elements, literal);
|
|
64
64
|
return edit && { edits: [edit], note: noneNote };
|
|
65
65
|
}
|
|
66
|
-
function jwtDecodeForAuthFix({ node, sourceFile }) {
|
|
67
|
-
if (!node || !sourceFile)
|
|
68
|
-
return;
|
|
69
|
-
const call = calleeCall(node);
|
|
70
|
-
if (!call || !call.arguments.length)
|
|
71
|
-
return;
|
|
72
|
-
const callee = ts.skipOuterExpressions(call.expression);
|
|
73
|
-
if (!ts.isPropertyAccessExpression(callee) || callee.name.text !== 'decode')
|
|
74
|
-
return;
|
|
75
|
-
const tokenArg = call.arguments[0].getText(sourceFile);
|
|
76
|
-
const receiver = callee.expression.getText(sourceFile);
|
|
77
|
-
return {
|
|
78
|
-
edits: [
|
|
79
|
-
replaceNode(call, `${receiver}.verify(${tokenArg}, process.env.JWT_SECRET ?? '', { algorithms: ['HS256'] })`),
|
|
80
|
-
],
|
|
81
|
-
note: 'Replaces unverified `decode` with `verify` using `process.env.JWT_SECRET` and pinned `algorithms`.',
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
66
|
const builders = {
|
|
85
67
|
'jwt-none-algorithm': noneFix,
|
|
86
68
|
'jwt-sign-without-expiry': expiryFix,
|
|
87
|
-
'jwt-decode-for-auth': requireReview('Confirm the signing key env var and `algorithms` list match your token issuer.', jwtDecodeForAuthFix),
|
|
88
69
|
};
|
|
89
70
|
export default builders;
|