loadwise 0.9.0 → 0.10.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 +88 -19
- package/agent/hooks/check-edited-file.mjs +146 -28
- package/dist/bin/github-action.js +3 -74
- package/dist/bin/loadwise.js +12 -12
- package/dist/lib/accessibility/aria-tables.js +10 -6
- package/dist/lib/accessibility/document-reference-rules.js +13 -3
- package/dist/lib/accessibility/jsx-elements.js +34 -16
- package/dist/lib/accessibility/native-interactive.js +51 -13
- package/dist/lib/accessibility/rules.js +4 -2
- package/dist/lib/accessibility/site-fixes/aria-typo.js +65 -0
- package/dist/lib/accessibility/site-fixes/html-language.js +45 -9
- package/dist/lib/accessibility/template-elements.js +5 -3
- package/dist/lib/editor/actions.js +15 -9
- package/dist/lib/editor/diagnostics.js +110 -107
- package/dist/lib/editor/finding-comparison.js +4 -25
- package/dist/lib/editor/hover-markdown.js +104 -0
- package/dist/lib/editor/inline-fix.js +50 -0
- package/dist/lib/editor/inline-recommendation.js +27 -0
- package/dist/lib/editor/language-server.js +94 -18
- package/dist/lib/editor/scan-session.js +2 -1
- package/dist/lib/editor/standalone-performance-examples.js +48 -0
- package/dist/lib/maintainability/analysis/analyze-source.js +2 -0
- package/dist/lib/maintainability/architecture/architecture.js +50 -2
- package/dist/lib/maintainability/cli/inputs.js +12 -5
- package/dist/lib/maintainability/cli/site-fix.js +3 -0
- package/dist/lib/maintainability/cli.js +6 -3
- package/dist/lib/maintainability/examples.js +48 -0
- package/dist/lib/maintainability/quality/modern-node-callbacks.js +188 -0
- package/dist/lib/maintainability/quality/modern-syntax.js +301 -0
- package/dist/lib/maintainability/quality/tsconfig-strict.js +307 -15
- package/dist/lib/maintainability/rule-ids.js +18 -0
- package/dist/lib/maintainability/scan-changed.js +33 -2
- package/dist/lib/maintainability/scan.js +10 -1
- package/dist/lib/maintainability/site-fixes/unused-bindings.js +15 -6
- package/dist/lib/maintainability/unused/module-usage-signatures.js +116 -0
- package/dist/lib/maintainability/unused/module-usage.js +67 -106
- package/dist/lib/maintainability/unused/unused-bindings.js +143 -8
- package/dist/lib/maintainability/unused/unused-dependencies.js +218 -0
- package/dist/lib/maintainability/unused/unused-modules.js +4 -0
- package/dist/lib/performance/analysis/missing-packages.js +3 -0
- package/dist/lib/performance/analysis/source-text.js +2 -2
- package/dist/lib/performance/analyze.js +4 -1
- package/dist/lib/performance/async/floating-promises.js +25 -4
- package/dist/lib/performance/cli/cli-output.js +9 -3
- package/dist/lib/performance/cli/cli-policy.js +25 -2
- package/dist/lib/performance/cli/cli-scan.js +25 -24
- package/dist/lib/performance/cli/scan-outcome.js +19 -1
- package/dist/lib/performance/cli/shared-security-inputs.js +27 -0
- package/dist/lib/performance/cli/watch.js +27 -8
- package/dist/lib/performance/collections/collection-lookups.js +27 -10
- package/dist/lib/performance/collections/collection-reduce.js +32 -2
- package/dist/lib/performance/collections/collections.js +28 -0
- package/dist/lib/performance/collections/repeated.js +25 -1
- package/dist/lib/performance/contracts/cli.js +22 -11
- package/dist/lib/performance/contracts/git-files.js +46 -1
- package/dist/lib/performance/datastores/pooling.js +1 -17
- package/dist/lib/performance/datastores/postgres.js +41 -33
- package/dist/lib/performance/engine/native.js +5 -1
- package/dist/lib/performance/frontend/angular-template-calls.js +187 -0
- package/dist/lib/performance/frontend/frontend-dom-perf.js +68 -8
- package/dist/lib/performance/frontend/frontend-perf.js +115 -171
- package/dist/lib/performance/frontend/frontend-render-perf.js +7 -3
- package/dist/lib/performance/frontend/jsx-element-perf.js +171 -0
- package/dist/lib/performance/frontend/next-fetch-waterfall.js +346 -29
- package/dist/lib/performance/frontend/rxjs-subscriptions.js +155 -0
- package/dist/lib/performance/frontend/seo/client-fetched-content.js +196 -0
- package/dist/lib/performance/frontend/seo/navigation-without-link.js +116 -0
- package/dist/lib/performance/frontend/seo/next-routes.js +114 -0
- package/dist/lib/performance/frontend/seo/route-metadata.js +158 -0
- package/dist/lib/performance/frontend/seo/seo-rules.js +9 -0
- package/dist/lib/performance/frontend/seo/sitewide-noindex.js +103 -0
- package/dist/lib/performance/frontend/template-tracking.js +86 -2
- package/dist/lib/performance/frontend/vue-options-hooks.js +108 -0
- package/dist/lib/performance/orm/prisma.js +1 -25
- package/dist/lib/performance/projects.js +3 -2
- package/dist/lib/performance/query-loops/service-loops.js +38 -8
- package/dist/lib/performance/request/json-stringify-output.js +82 -4
- package/dist/lib/performance/request/promise-schedulers.js +180 -0
- package/dist/lib/performance/request/request-handlers.js +43 -4
- package/dist/lib/performance/request/unbounded-promise-all.js +13 -52
- package/dist/lib/performance/rule-ids.js +26 -2
- package/dist/lib/performance/site-fix.js +1 -0
- package/dist/lib/reliability/react-bugs.js +9 -0
- package/dist/lib/reliability/react-state-aliases.js +94 -4
- package/dist/lib/reliability/react-state.js +24 -5
- package/dist/lib/security/auth-crypto/secrets.js +121 -16
- package/dist/lib/security/cli.js +1 -1
- package/dist/lib/security/credential-entropy.js +12 -0
- package/dist/lib/security/deps/lockfiles.js +3 -1
- package/dist/lib/security/examples/files.js +110 -0
- package/dist/lib/security/examples/request-forgery.js +1 -1
- package/dist/lib/security/exposure/frontend-security.js +11 -2
- package/dist/lib/security/exposure/prototype-pollution.js +73 -4
- package/dist/lib/security/files/azure-pipelines.js +69 -0
- package/dist/lib/security/files/bitbucket-pipelines.js +32 -0
- package/dist/lib/security/files/ci-platforms.js +16 -0
- package/dist/lib/security/files/ci-shared.js +260 -0
- package/dist/lib/security/files/circleci.js +81 -0
- package/dist/lib/security/files/dockerfile.js +188 -3
- package/dist/lib/security/files/github-actions.js +490 -0
- package/dist/lib/security/files/gitlab-ci.js +90 -0
- package/dist/lib/security/files/hcl.js +264 -0
- package/dist/lib/security/files/hosting-config.js +159 -0
- package/dist/lib/security/files/http-headers.js +65 -0
- package/dist/lib/security/files/index.js +62 -7
- package/dist/lib/security/files/jenkinsfile.js +482 -0
- package/dist/lib/security/files/json-nodes.js +67 -0
- package/dist/lib/security/files/nginx.js +501 -0
- package/dist/lib/security/files/package-scripts.js +175 -0
- package/dist/lib/security/files/rule-ids.js +29 -0
- package/dist/lib/security/files/secret-values.js +31 -5
- package/dist/lib/security/files/secrets.js +44 -13
- package/dist/lib/security/files/terraform.js +345 -0
- package/dist/lib/security/injection/nosql.js +2 -1
- package/dist/lib/security/injection/sql.js +2 -2
- package/dist/lib/security/lexical-declaration.js +28 -0
- package/dist/lib/security/pg-identifier-guards.js +90 -1
- package/dist/lib/security/request-forgery/member-chain.js +41 -0
- package/dist/lib/security/request-forgery/open-redirect.js +45 -8
- package/dist/lib/security/request-forgery/shared.js +18 -3
- package/dist/lib/security/rule-descriptions.js +29 -0
- package/dist/lib/security/rule-ids.js +29 -0
- package/dist/lib/security/taint/original-string-validation.js +229 -0
- package/dist/lib/security/taint/validators.js +1 -1
- package/dist/lib/shared/agent/review-delivery.js +3 -1
- package/dist/lib/shared/analysis/ast-semantics.js +17 -1
- package/dist/lib/shared/analysis/hot-path-graph.js +55 -19
- package/dist/lib/shared/analysis/next-env-config.js +232 -0
- package/dist/lib/shared/analysis/scan-cache-git.js +114 -0
- package/dist/lib/shared/analysis/scan-cache-loadwise-packages.js +54 -0
- package/dist/lib/shared/analysis/scan-cache-project-inputs.js +221 -0
- package/dist/lib/shared/analysis/scan-cache-sources.js +235 -0
- package/dist/lib/shared/analysis/scan-cache-storage.js +24 -0
- package/dist/lib/shared/analysis/scan-cache.js +158 -174
- package/dist/lib/shared/check-watch.js +3 -3
- package/dist/lib/shared/check.js +25 -4
- package/dist/lib/shared/config.js +1 -1
- package/dist/lib/shared/conventional-projects.js +40 -0
- package/dist/lib/shared/fix/fix-command.js +2 -0
- package/dist/lib/shared/fix/fix-usage.js +47 -0
- package/dist/lib/shared/fix/project-file-access.js +43 -20
- package/dist/lib/shared/fix.js +4 -35
- package/dist/lib/shared/formats/security-cwe.js +29 -0
- package/dist/lib/shared/project-root.js +1 -1
- package/dist/lib/shared/reporting/action-comparison.js +78 -0
- package/dist/lib/shared/reporting/automatic-fix-signal.js +7 -2
- package/dist/lib/shared/reporting/check-text.js +7 -5
- package/dist/lib/shared/reporting/pillars.js +28 -8
- package/dist/lib/shared/reporting/source-report.js +4 -4
- package/dist/lib/shared/system/git.js +31 -16
- package/dist/lib/shared/system/glob.js +146 -19
- package/dist/lib/shared/system/terminal-style.js +2 -2
- package/dist/lib/shared/workspaces.js +6 -1
- package/package.json +4 -1
- package/schema/loadwise.config.schema.json +86 -0
|
@@ -85,6 +85,93 @@ function isProvenString(node, checker) {
|
|
|
85
85
|
const members = type.isUnion() ? (type.types ?? []) : [type];
|
|
86
86
|
return members.length > 0 && members.every((member) => member.flags & ts.TypeFlags.StringLike);
|
|
87
87
|
}
|
|
88
|
+
function isLookupFallback(node) {
|
|
89
|
+
const value = ts.skipOuterExpressions(node);
|
|
90
|
+
if (!ts.isBinaryExpression(value) || !ts.isStringLiteralLike(ts.skipOuterExpressions(value.right)))
|
|
91
|
+
return false;
|
|
92
|
+
const operator = value.operatorToken.kind;
|
|
93
|
+
return operator === ts.SyntaxKind.QuestionQuestionToken || operator === ts.SyntaxKind.BarBarToken;
|
|
94
|
+
}
|
|
95
|
+
const readOnlyTableCache = new WeakMap();
|
|
96
|
+
// Every reference reads a member of the table; an assignment, `delete` or escape could add a key.
|
|
97
|
+
function isReadOnlyTable(table, declaration, checker) {
|
|
98
|
+
const cached = readOnlyTableCache.get(declaration);
|
|
99
|
+
if (cached !== undefined)
|
|
100
|
+
return cached;
|
|
101
|
+
const readOnly = !isExported(declaration) && !tableEscapes(table, declaration, checker);
|
|
102
|
+
readOnlyTableCache.set(declaration, readOnly);
|
|
103
|
+
return readOnly;
|
|
104
|
+
}
|
|
105
|
+
function isExported(declaration) {
|
|
106
|
+
const statement = declaration.parent.parent;
|
|
107
|
+
return (ts.isVariableStatement(statement) &&
|
|
108
|
+
!!statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword));
|
|
109
|
+
}
|
|
110
|
+
function tableEscapes(table, declaration, checker) {
|
|
111
|
+
const symbol = checker.getSymbolAtLocation(table);
|
|
112
|
+
return !!(function escapes(node) {
|
|
113
|
+
// `export { T }` and `{ T }` resolve to an alias or property symbol, so they are matched by name.
|
|
114
|
+
if (ts.isIdentifier(node) &&
|
|
115
|
+
node.text === table.text &&
|
|
116
|
+
(ts.isExportSpecifier(node.parent) || ts.isShorthandPropertyAssignment(node.parent)))
|
|
117
|
+
return true;
|
|
118
|
+
if (ts.isIdentifier(node) && node !== declaration.name && checker.getSymbolAtLocation(node) === symbol) {
|
|
119
|
+
const access = node.parent;
|
|
120
|
+
if (!(ts.isElementAccessExpression(access) || ts.isPropertyAccessExpression(access)) ||
|
|
121
|
+
access.expression !== node)
|
|
122
|
+
return true;
|
|
123
|
+
// Covers `T[k] = v`, `(T[k]) = v`, `T[k]! = v`, `[T[k]] = [v]`, `for (T[k] of xs)` and `T[k]++`.
|
|
124
|
+
if (ts.isAssignmentTarget(access))
|
|
125
|
+
return true;
|
|
126
|
+
let use = access.parent;
|
|
127
|
+
while (ts.isParenthesizedExpression(use) || ts.isNonNullExpression(use))
|
|
128
|
+
use = use.parent;
|
|
129
|
+
if (ts.isDeleteExpression(use))
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
return ts.forEachChild(node, escapes);
|
|
133
|
+
})(declaration.getSourceFile());
|
|
134
|
+
}
|
|
135
|
+
// `SORT_COLUMNS[sort] ?? 'created_at'`, directly or through a const: a lookup in a file-local const
|
|
136
|
+
// object whose values are all string literals and that is never written. Any key yields one of
|
|
137
|
+
// those strings, `undefined`, or an inherited built-in such as `constructor` whose text no request
|
|
138
|
+
// chooses.
|
|
139
|
+
function isFixedMapLookup(node, checker) {
|
|
140
|
+
let value = constantValue(node, checker);
|
|
141
|
+
if (value && isLookupFallback(value) && ts.isBinaryExpression(value))
|
|
142
|
+
value = ts.skipOuterExpressions(value.left);
|
|
143
|
+
if (!value || !ts.isElementAccessExpression(value))
|
|
144
|
+
return false;
|
|
145
|
+
const table = ts.skipOuterExpressions(value.expression);
|
|
146
|
+
if (!ts.isIdentifier(table))
|
|
147
|
+
return false;
|
|
148
|
+
const declaration = checker.getSymbolAtLocation(table)?.valueDeclaration;
|
|
149
|
+
if (!declaration || !ts.isVariableDeclaration(declaration) || !(declaration.parent.flags & ts.NodeFlags.Const))
|
|
150
|
+
return false;
|
|
151
|
+
const object = declaration.initializer && ts.skipOuterExpressions(declaration.initializer);
|
|
152
|
+
return (!!object &&
|
|
153
|
+
ts.isObjectLiteralExpression(object) &&
|
|
154
|
+
object.properties.length > 0 &&
|
|
155
|
+
object.properties.every((property) => ts.isPropertyAssignment(property) && ts.isStringLiteralLike(ts.skipOuterExpressions(property.initializer))) &&
|
|
156
|
+
isReadOnlyTable(table, declaration, checker));
|
|
157
|
+
}
|
|
158
|
+
// A parameter declared as a string literal or a union of them: `table: 'orders' | 'users'`. Only a
|
|
159
|
+
// declared parameter type counts: an inferred literal type, such as an `as const` field, says
|
|
160
|
+
// nothing once the object escapes. A decorated parameter, such as NestJS `@Query('sort')`, is filled
|
|
161
|
+
// from the request without checking its type, and a reassigned one may no longer hold the union.
|
|
162
|
+
function isStringLiteralUnionParameter(node, checker) {
|
|
163
|
+
const value = ts.skipOuterExpressions(node);
|
|
164
|
+
const declaration = ts.isIdentifier(value) ? checker.getSymbolAtLocation(value)?.valueDeclaration : undefined;
|
|
165
|
+
if (!declaration || !ts.isParameter(declaration) || !declaration.type)
|
|
166
|
+
return false;
|
|
167
|
+
if (ts.getDecorators(declaration)?.length)
|
|
168
|
+
return false;
|
|
169
|
+
if (ts.isIdentifier(value) && isReassigned(declaration.parent, declaration, value.text, checker))
|
|
170
|
+
return false;
|
|
171
|
+
const type = checker.getTypeAtLocation(value);
|
|
172
|
+
const members = type.isUnion() ? (type.types ?? []) : [type];
|
|
173
|
+
return members.length > 0 && members.every((member) => member.flags & ts.TypeFlags.StringLiteral);
|
|
174
|
+
}
|
|
88
175
|
// `String(value)` of a value already proven to be a string is that value.
|
|
89
176
|
function stringConversionOperand(node, checker) {
|
|
90
177
|
const call = ts.skipOuterExpressions(node);
|
|
@@ -306,6 +393,8 @@ function allRuntimePartsValidated(query, call, checker, isExtraSafe) {
|
|
|
306
393
|
return (unknown.length > 0 &&
|
|
307
394
|
unknown.every((operand) => isExtraSafe?.(operand) ||
|
|
308
395
|
(isPgEscapeIdentifierCall(operand, checker) && !isInsideSingleQuotes(query, operand, checker)) ||
|
|
396
|
+
isFixedMapLookup(operand, checker) ||
|
|
397
|
+
isStringLiteralUnionParameter(operand, checker) ||
|
|
309
398
|
(ts.isIdentifier(operand) && isValidatedIdentifier(operand, call, checker))));
|
|
310
399
|
}
|
|
311
|
-
export { allRuntimePartsValidated, isValidatedIdentifier, isValidation, isClosedAnchoredRegex, isLiteralList, operandsOf, staticAccessPath, stringConversionOperand, };
|
|
400
|
+
export { allRuntimePartsValidated, isFixedMapLookup, isValidatedIdentifier, isValidation, isClosedAnchoredRegex, isLiteralList, operandsOf, staticAccessPath, stringConversionOperand, };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Property chains such as `req.query.next`, used to match a redirect guard to the request property it checks.
|
|
2
|
+
import { ts } from '../../performance/engine/compiler.js';
|
|
3
|
+
import { stripExpression as strip } from '../bindings.js';
|
|
4
|
+
// `req.query.next` or `req.query['next']`: its root and the property names read from it.
|
|
5
|
+
function memberChain(node) {
|
|
6
|
+
let value = strip(node);
|
|
7
|
+
const names = [];
|
|
8
|
+
while (value && (ts.isPropertyAccessExpression(value) || ts.isElementAccessExpression(value))) {
|
|
9
|
+
if (ts.isPropertyAccessExpression(value))
|
|
10
|
+
names.unshift(value.name.text);
|
|
11
|
+
else if (ts.isStringLiteralLike(value.argumentExpression))
|
|
12
|
+
names.unshift(value.argumentExpression.text);
|
|
13
|
+
else
|
|
14
|
+
return;
|
|
15
|
+
value = strip(value.expression);
|
|
16
|
+
}
|
|
17
|
+
return value && names.length ? { root: value, path: names } : undefined;
|
|
18
|
+
}
|
|
19
|
+
// `req.query['a.b']` and `req.query.a.b` read different properties, so names are compared one by one.
|
|
20
|
+
function samePath(path, expected) {
|
|
21
|
+
return path.length === expected.length && path.every((name, index) => name === expected[index]);
|
|
22
|
+
}
|
|
23
|
+
// `Object.assign(req.query, ...)` or `normalize(req)`: a call that receives the root, or an object on
|
|
24
|
+
// the way to the target, can overwrite the target without a visible assignment.
|
|
25
|
+
function passesChainOwner(scope, chain, isRoot) {
|
|
26
|
+
const ownsTarget = (argument) => {
|
|
27
|
+
if (isRoot(argument))
|
|
28
|
+
return true;
|
|
29
|
+
const owner = memberChain(argument);
|
|
30
|
+
return (!!owner &&
|
|
31
|
+
owner.path.length < chain.path.length &&
|
|
32
|
+
samePath(owner.path, chain.path.slice(0, owner.path.length)) &&
|
|
33
|
+
isRoot(owner.root));
|
|
34
|
+
};
|
|
35
|
+
return !!(function visit(node) {
|
|
36
|
+
if ((ts.isCallExpression(node) || ts.isNewExpression(node)) && node.arguments?.some(ownsTarget))
|
|
37
|
+
return true;
|
|
38
|
+
return ts.forEachChild(node, visit);
|
|
39
|
+
})(scope);
|
|
40
|
+
}
|
|
41
|
+
export { memberChain, samePath, passesChainOwner };
|
|
@@ -365,7 +365,22 @@ function configuredPredicate(sink, target, context) {
|
|
|
365
365
|
return trustedBindingAt(condition.expression, 'redirect-target-predicate', context) === binding;
|
|
366
366
|
}));
|
|
367
367
|
}
|
|
368
|
-
|
|
368
|
+
// The branches of `ok ? next : '/'`, written in the redirect call or in the const it reads. A const
|
|
369
|
+
// already followed on this path is not followed again, so declarations that read each other end.
|
|
370
|
+
function conditionalBranches(target, checker, visited) {
|
|
371
|
+
let value = strip(target);
|
|
372
|
+
if (ts.isIdentifier(value)) {
|
|
373
|
+
const declaration = constantDeclaration(value, checker);
|
|
374
|
+
if (declaration && visited.has(declaration))
|
|
375
|
+
return;
|
|
376
|
+
if (declaration)
|
|
377
|
+
visited.add(declaration);
|
|
378
|
+
if (declaration?.initializer)
|
|
379
|
+
value = strip(declaration.initializer);
|
|
380
|
+
}
|
|
381
|
+
return ts.isConditionalExpression(value) ? [value.whenTrue, value.whenFalse] : undefined;
|
|
382
|
+
}
|
|
383
|
+
function wholeTargetTrace(site, target, context) {
|
|
369
384
|
if (startsWithFixedPath(target, context) || isFixedPathHelperCall(target, context))
|
|
370
385
|
return;
|
|
371
386
|
const control = context.taint.urlControl(target);
|
|
@@ -375,15 +390,37 @@ function reportTarget(node, target, context) {
|
|
|
375
390
|
// The victim's browser sends its own Host header, so a host taken from it cannot point elsewhere.
|
|
376
391
|
if (isHostHeader(trace))
|
|
377
392
|
return;
|
|
378
|
-
if (isRelativeRedirect(
|
|
379
|
-
isProjectValidated(
|
|
380
|
-
hasParsedOriginGuard(
|
|
381
|
-
isParsedHostAllowlisted(
|
|
382
|
-
isAllowedHost(
|
|
393
|
+
if (isRelativeRedirect(site, target, context) ||
|
|
394
|
+
isProjectValidated(site, target, validatedKinds, context) ||
|
|
395
|
+
hasParsedOriginGuard(site, target, context.checker, ['raw']) ||
|
|
396
|
+
isParsedHostAllowlisted(site, target, context.checker) ||
|
|
397
|
+
isAllowedHost(site, parsedUrlTarget(target), context, false, usesInlineHostCollection) ||
|
|
398
|
+
queryOnlyRedirect(site, target, context) === 'fixed')
|
|
383
399
|
return;
|
|
384
|
-
|
|
385
|
-
|
|
400
|
+
return trace;
|
|
401
|
+
}
|
|
402
|
+
// The taint trace of a target a link can still point off-site, judged at `site`. A target that a
|
|
403
|
+
// check before `site` does not clear is split into its conditional branches, each judged at its own
|
|
404
|
+
// position, so the condition guarding a branch counts as a check.
|
|
405
|
+
function unguardedTrace(site, target, context, visited = new Set()) {
|
|
406
|
+
const trace = wholeTargetTrace(site, target, context);
|
|
407
|
+
if (!trace)
|
|
386
408
|
return;
|
|
409
|
+
const branches = conditionalBranches(target, context.checker, visited);
|
|
410
|
+
if (!branches)
|
|
411
|
+
return trace;
|
|
412
|
+
for (const branch of branches) {
|
|
413
|
+
const branchTrace = unguardedTrace(branch, branch, context, new Set(visited));
|
|
414
|
+
if (branchTrace)
|
|
415
|
+
return branchTrace;
|
|
416
|
+
}
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
function reportTarget(node, target, context) {
|
|
420
|
+
const trace = unguardedTrace(node, target, context);
|
|
421
|
+
if (!trace)
|
|
422
|
+
return;
|
|
423
|
+
const queryProof = queryOnlyRedirect(node, target, context);
|
|
387
424
|
const reason = queryProof === 'configured'
|
|
388
425
|
? configuredOriginReason
|
|
389
426
|
: hasParsedOriginGuard(node, target, context.checker, ['based'])
|
|
@@ -7,6 +7,7 @@ import { isLiteralList } from '../pg-identifier-guards.js';
|
|
|
7
7
|
import { isGuardedByCondition, isReassigned } from '../taint/guards.js';
|
|
8
8
|
import { argumentValidations } from '../taint/summaries.js';
|
|
9
9
|
import { isUrlConstructor } from '../taint/url-parts.js';
|
|
10
|
+
import { memberChain, passesChainOwner, samePath } from './member-chain.js';
|
|
10
11
|
const secondHopReason = 'Reached through two calls; confirm the intermediate functions do not validate the value.';
|
|
11
12
|
// Parameter names that hold an HTTP response (Express, Fastify, Koa, Hono) in practice.
|
|
12
13
|
const responseNames = new Set(['res', 'response', 'reply', 'ctx', 'context', 'c']);
|
|
@@ -481,12 +482,26 @@ function isAllowedOriginPrefix(sink, expression, checker) {
|
|
|
481
482
|
// Reject characters the URL parser treats as alternate separators or removes before interpreting
|
|
482
483
|
// the path.
|
|
483
484
|
const redirectSeparators = /[\\\t\r\n]/;
|
|
485
|
+
// A guard reads the redirect target when it names the same const or parameter, or the same property
|
|
486
|
+
// chain on a root that nothing reassigns, writes a property of or hands to a call before the redirect.
|
|
487
|
+
function targetMatcher(sink, expression, checker) {
|
|
488
|
+
const target = stableIdentifier(expression, sink, checker);
|
|
489
|
+
if (target)
|
|
490
|
+
return (node) => sameValue(node, target, checker);
|
|
491
|
+
const chain = memberChain(expression);
|
|
492
|
+
const root = chain && stableIdentifier(chain.root, sink, checker, true);
|
|
493
|
+
if (!chain || !root || passesChainOwner(scopeOf(sink), chain, (node) => sameValue(node, root, checker)))
|
|
494
|
+
return;
|
|
495
|
+
return (node) => {
|
|
496
|
+
const candidate = memberChain(node);
|
|
497
|
+
return !!candidate && samePath(candidate.path, chain.path) && sameValue(candidate.root, root, checker);
|
|
498
|
+
};
|
|
499
|
+
}
|
|
484
500
|
function isRelativeRedirect(sink, expression, context) {
|
|
485
501
|
const { checker } = context;
|
|
486
|
-
const
|
|
487
|
-
if (!
|
|
502
|
+
const matches = targetMatcher(sink, expression, checker);
|
|
503
|
+
if (!matches)
|
|
488
504
|
return false;
|
|
489
|
-
const matches = (node) => sameValue(node, target, checker);
|
|
490
505
|
if (isGuardedByCondition(sink, (condition, truth) => checkedAgainstLiteral(condition, truth, matches, checker))) {
|
|
491
506
|
return true;
|
|
492
507
|
}
|
|
@@ -2,12 +2,20 @@
|
|
|
2
2
|
const descriptionByRule = {
|
|
3
3
|
'angular-bypass-security-trust': "DomSanitizer.bypassSecurityTrust* is called on a dynamic value, which turns off Angular's built-in sanitization.",
|
|
4
4
|
'auth-route-without-rate-limit': 'A login, signup or password-reset route has no rate limiter.',
|
|
5
|
+
'azure-pipelines-script-injection': 'An Azure Pipelines script pastes a commit message or branch name into its text with a $(...) macro.',
|
|
5
6
|
'bcrypt-low-cost': 'A bcrypt password hash uses a work factor below the recommended minimum.',
|
|
7
|
+
'bitbucket-pipelines-script-injection': 'A Bitbucket Pipelines script passes the branch name to eval or inline code, which parses it as commands.',
|
|
8
|
+
'bitbucket-pipelines-unpinned-image': 'A Bitbucket Pipelines build image has no version tag or uses :latest.',
|
|
9
|
+
'circleci-script-injection': 'A CircleCI run command pastes a branch name or commit text into its text, or passes it to eval or inline code.',
|
|
10
|
+
'circleci-unpinned-image': 'A CircleCI Docker executor image has no version tag or uses :latest.',
|
|
11
|
+
'circleci-unpinned-orb': 'A CircleCI orb is used at the moving @volatile or a dev: version.',
|
|
6
12
|
'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.',
|
|
7
13
|
'code-injection': 'Request-controlled input becomes source code evaluated by the application.',
|
|
8
14
|
'command-injection': 'Request-controlled input reaches a shell command string.',
|
|
9
15
|
'committed-secret': 'A tracked file contains a value that appears to be a credential.',
|
|
10
16
|
'compose-hardcoded-secret': 'A Docker Compose service supplies a secret as a literal environment value.',
|
|
17
|
+
'config-cors-credentials-any-origin': 'A web server or hosting config sends Access-Control-Allow-Credentials: true with a wildcard or echoed request origin.',
|
|
18
|
+
'config-unsafe-security-header': "A web server or hosting config sets a security header to a value that disables it, such as X-Frame-Options: ALLOWALL or CSP 'unsafe-eval'.",
|
|
11
19
|
'cookie-missing-security-flags': 'A sensitive cookie is set without the expected security attributes.',
|
|
12
20
|
'cors-credentials-any-origin': 'A credentialed CORS response allows arbitrary origins.',
|
|
13
21
|
'cors-origin-regex-unanchored': 'A CORS origin regex also accepts look-alike hosts.',
|
|
@@ -18,6 +26,7 @@ const descriptionByRule = {
|
|
|
18
26
|
'dependency-known-vulnerability': 'A resolved dependency version is listed in a published vulnerability advisory.',
|
|
19
27
|
'discarded-signature-verification-result': 'A standalone call discards the result of Node.js synchronous signature verification.',
|
|
20
28
|
'dockerfile-add-remote-url': 'A Dockerfile ADD instruction retrieves a resource from a remote URL.',
|
|
29
|
+
'dockerfile-npm-install': 'A Dockerfile runs `npm install` after copying the lockfile, so the image can resolve versions the lockfile does not pin.',
|
|
21
30
|
'dockerfile-runs-as-root': 'The final image selects root or inherits an unverified base-image user.',
|
|
22
31
|
'dockerfile-secret-in-build': 'A Dockerfile exposes a secret through a build argument or environment variable.',
|
|
23
32
|
'dockerfile-unpinned-base-image': 'A Dockerfile uses a base image reference that can change between builds.',
|
|
@@ -29,6 +38,12 @@ const descriptionByRule = {
|
|
|
29
38
|
'express-cookie-auth-missing-csrf': 'Cookie-based session or auth is paired with state-changing routes without CSRF protection or `sameSite: "strict"`.',
|
|
30
39
|
'express-missing-helmet': 'The Express or NestJS server starts without helmet security headers middleware (contextual: a proxy may set them).',
|
|
31
40
|
'frontend-storage-secret-token': 'A token, JWT, password or API key is stored in localStorage or sessionStorage, readable by any script on the page.',
|
|
41
|
+
'github-actions-pull-request-target-checkout': 'A pull_request_target or workflow_run workflow checks out the pull request code with the base repository secrets.',
|
|
42
|
+
'github-actions-script-injection': 'A workflow script expands attacker-controlled event text such as an issue title or branch name.',
|
|
43
|
+
'github-actions-unpinned-action': 'A workflow runs a third-party action from a tag or branch instead of a commit SHA.',
|
|
44
|
+
'gitlab-ci-script-injection': 'A GitLab CI script passes commit, merge request or branch text to eval or inline code, which parses it as commands.',
|
|
45
|
+
'gitlab-ci-unpinned-image': 'A GitLab CI job image has no version tag or uses :latest.',
|
|
46
|
+
'gitlab-ci-unpinned-include': 'A GitLab CI include loads another project, a remote URL or a component from a moving branch or version.',
|
|
32
47
|
'go-exec-command-shell': 'exec.Command invokes a shell, which risks command injection.',
|
|
33
48
|
'go-sql-sprintf-injection': 'SQL text formatted with fmt.Sprintf risks SQL injection.',
|
|
34
49
|
'go-tls-insecure-skip-verify': 'Setting InsecureSkipVerify: true on tls.Config disables TLS certificate verification.',
|
|
@@ -36,6 +51,7 @@ const descriptionByRule = {
|
|
|
36
51
|
'graphql-introspection-enabled': 'A GraphQL server explicitly enables schema introspection.',
|
|
37
52
|
'graphql-query-depth-unbounded': 'A GraphQL server accepts queries of any depth.',
|
|
38
53
|
'hardcoded-secret': 'The source supplies a literal credential or cryptographic secret.',
|
|
54
|
+
'hosting-redirect-external-wildcard': 'A vercel.json, netlify.toml or _redirects redirect takes its destination host from the request path (open redirect).',
|
|
39
55
|
'insecure-cipher': 'A cryptographic operation selects an insecure cipher or mode.',
|
|
40
56
|
'insecure-deserialization': 'Request data is deserialized by a library that can rebuild and run functions from it.',
|
|
41
57
|
'insecure-random-for-secret': 'A sensitive token or secret uses a non-cryptographic random source.',
|
|
@@ -43,6 +59,8 @@ const descriptionByRule = {
|
|
|
43
59
|
'java-objectinputstream-request-deserialization': 'Java ObjectInputStream.readObject consumes a servlet request body.',
|
|
44
60
|
'java-runtime-exec': 'Runtime.getRuntime().exec runs an OS command and risks command injection with untrusted arguments.',
|
|
45
61
|
'java-sql-string-concat': 'A SQL query built by string concatenation risks SQL injection.',
|
|
62
|
+
'jenkinsfile-credential-interpolation': 'A Jenkinsfile shell step interpolates a bound credential with a Groovy double-quoted string.',
|
|
63
|
+
'jenkinsfile-script-injection': 'A Jenkinsfile shell step interpolates a branch name, pull request field or build parameter into its script.',
|
|
46
64
|
'js-yaml-unsafe-schema': 'A resolved js-yaml loader enables JavaScript-specific YAML constructors.',
|
|
47
65
|
'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).',
|
|
48
66
|
'jwt-decode-for-auth': 'Authentication uses decoded JWT claims without verifying the token signature.',
|
|
@@ -58,8 +76,11 @@ const descriptionByRule = {
|
|
|
58
76
|
'mysql-dynamic-query-text': 'Dynamic SQL text reaches a MySQL client without parameter binding.',
|
|
59
77
|
'nest-validation-without-whitelist': 'A NestJS ValidationPipe permits properties outside the validated DTO.',
|
|
60
78
|
'next-image-any-remote-host': "A Next.js images.remotePatterns entry sets hostname '**', so the image optimizer fetches and serves any host (open proxy).",
|
|
79
|
+
'nginx-proxy-pass-request-host': 'An Nginx proxy_pass takes its upstream host from a client-sent value such as $http_host or a query argument.',
|
|
61
80
|
'nosql-operator-injection': 'Request data can introduce query operators into a NoSQL filter.',
|
|
62
81
|
'open-redirect': 'An HTTP redirect destination is controlled by request data.',
|
|
82
|
+
'package-script-remote-code': 'A package.json install lifecycle script downloads code and runs it, for example `curl ... | sh`.',
|
|
83
|
+
'package-script-tls-verification-disabled': 'A package.json script turns off TLS certificate verification, for example NODE_TLS_REJECT_UNAUTHORIZED=0 or strict-ssl false.',
|
|
63
84
|
'password-hash-in-response': 'A response returns a user record that still holds its password hash.',
|
|
64
85
|
'path-traversal': 'Request data controls a filesystem path without a recognized containment check.',
|
|
65
86
|
'pg-dynamic-query-text': 'Dynamic SQL text reaches the PostgreSQL client without parameter binding.',
|
|
@@ -93,6 +114,11 @@ const descriptionByRule = {
|
|
|
93
114
|
'template-autoescape-disabled': 'A template engine is configured to render values without HTML escaping.',
|
|
94
115
|
'template-injection': 'Request data is interpreted as template source rather than a template value.',
|
|
95
116
|
'template-raw-html-binding': 'A Vue or Svelte template inserts a dynamic value as raw HTML.',
|
|
117
|
+
'terraform-admin-port-open-to-world': 'A Terraform firewall rule opens an SSH, RDP or database port to every internet address.',
|
|
118
|
+
'terraform-database-publicly-accessible': 'A Terraform database is reachable from the public internet.',
|
|
119
|
+
'terraform-hardcoded-credential': 'A Terraform provider, resource or module sets a credential to a literal value.',
|
|
120
|
+
'terraform-storage-bucket-public': 'A Terraform storage bucket or container grants anonymous public access.',
|
|
121
|
+
'terraform-storage-encryption-disabled': 'A Terraform resource explicitly turns off encryption at rest.',
|
|
96
122
|
'tls-verification-disabled': 'A TLS client skips certificate or server hostname verification.',
|
|
97
123
|
'trust-boundary-violation': 'Request data is stored in application-wide state that later requests trust.',
|
|
98
124
|
'typeorm-dynamic-query-text': 'A dynamic SQL fragment reaches TypeORM without parameter binding.',
|
|
@@ -101,6 +127,9 @@ const descriptionByRule = {
|
|
|
101
127
|
'vue-v-html-unsanitized': 'A Vue render function binds unsanitized dynamic HTML to innerHTML.',
|
|
102
128
|
'weak-hash': 'A request credential is hashed with MD5 or SHA-1.',
|
|
103
129
|
'weak-password-hash': 'A password is hashed with an algorithm unsuitable for password storage.',
|
|
130
|
+
'web-server-directory-listing': 'An Nginx or Apache config turns on directory listing (autoindex on or Options Indexes).',
|
|
131
|
+
'web-server-legacy-tls': 'An Nginx or Apache config enables SSLv3, TLSv1 or TLSv1.1.',
|
|
132
|
+
'web-server-version-exposed': 'An Nginx or Apache config explicitly adds the server version to response headers.',
|
|
104
133
|
'webhook-body-without-verification': 'A Stripe webhook writes request-body data before visible signature verification.',
|
|
105
134
|
'xml-external-entities': 'An XML parser allows processing of external entities.',
|
|
106
135
|
'xpath-injection': 'Request data is concatenated into an XPath expression.',
|
|
@@ -43,12 +43,20 @@ for (const [group, rules] of Object.entries(groups)) {
|
|
|
43
43
|
const impactByRule = {
|
|
44
44
|
'angular-bypass-security-trust': 'high',
|
|
45
45
|
'auth-route-without-rate-limit': 'medium',
|
|
46
|
+
'azure-pipelines-script-injection': 'high',
|
|
46
47
|
'bcrypt-low-cost': 'medium',
|
|
48
|
+
'bitbucket-pipelines-script-injection': 'high',
|
|
49
|
+
'bitbucket-pipelines-unpinned-image': 'low',
|
|
50
|
+
'circleci-script-injection': 'high',
|
|
51
|
+
'circleci-unpinned-image': 'low',
|
|
52
|
+
'circleci-unpinned-orb': 'medium',
|
|
47
53
|
'client-env-secret-exposed': 'critical',
|
|
48
54
|
'code-injection': 'critical',
|
|
49
55
|
'command-injection': 'critical',
|
|
50
56
|
'committed-secret': 'critical',
|
|
51
57
|
'compose-hardcoded-secret': 'high',
|
|
58
|
+
'config-cors-credentials-any-origin': 'medium',
|
|
59
|
+
'config-unsafe-security-header': 'low',
|
|
52
60
|
'cookie-missing-security-flags': 'high',
|
|
53
61
|
'cors-credentials-any-origin': 'high',
|
|
54
62
|
'cors-origin-regex-unanchored': 'medium',
|
|
@@ -59,6 +67,7 @@ const impactByRule = {
|
|
|
59
67
|
'dependency-known-vulnerability': 'medium',
|
|
60
68
|
'discarded-signature-verification-result': 'high',
|
|
61
69
|
'dockerfile-add-remote-url': 'medium',
|
|
70
|
+
'dockerfile-npm-install': 'low',
|
|
62
71
|
'dockerfile-runs-as-root': 'medium',
|
|
63
72
|
'dockerfile-secret-in-build': 'high',
|
|
64
73
|
'dockerfile-unpinned-base-image': 'low',
|
|
@@ -70,6 +79,12 @@ const impactByRule = {
|
|
|
70
79
|
'express-cookie-auth-missing-csrf': 'high',
|
|
71
80
|
'express-missing-helmet': 'low',
|
|
72
81
|
'frontend-storage-secret-token': 'medium',
|
|
82
|
+
'github-actions-pull-request-target-checkout': 'high',
|
|
83
|
+
'github-actions-script-injection': 'high',
|
|
84
|
+
'github-actions-unpinned-action': 'medium',
|
|
85
|
+
'gitlab-ci-script-injection': 'high',
|
|
86
|
+
'gitlab-ci-unpinned-image': 'low',
|
|
87
|
+
'gitlab-ci-unpinned-include': 'medium',
|
|
73
88
|
'go-exec-command-shell': 'high',
|
|
74
89
|
'go-sql-sprintf-injection': 'high',
|
|
75
90
|
'go-tls-insecure-skip-verify': 'high',
|
|
@@ -77,6 +92,7 @@ const impactByRule = {
|
|
|
77
92
|
'graphql-introspection-enabled': 'medium',
|
|
78
93
|
'graphql-query-depth-unbounded': 'medium',
|
|
79
94
|
'hardcoded-secret': 'critical',
|
|
95
|
+
'hosting-redirect-external-wildcard': 'medium',
|
|
80
96
|
'insecure-cipher': 'medium',
|
|
81
97
|
'insecure-deserialization': 'critical',
|
|
82
98
|
'insecure-random-for-secret': 'high',
|
|
@@ -84,6 +100,8 @@ const impactByRule = {
|
|
|
84
100
|
'java-objectinputstream-request-deserialization': 'high',
|
|
85
101
|
'java-runtime-exec': 'medium',
|
|
86
102
|
'java-sql-string-concat': 'high',
|
|
103
|
+
'jenkinsfile-credential-interpolation': 'medium',
|
|
104
|
+
'jenkinsfile-script-injection': 'high',
|
|
87
105
|
'js-yaml-unsafe-schema': 'high',
|
|
88
106
|
'jsx-javascript-url': 'high',
|
|
89
107
|
'jwt-decode-for-auth': 'high',
|
|
@@ -99,8 +117,11 @@ const impactByRule = {
|
|
|
99
117
|
'mysql-dynamic-query-text': 'critical',
|
|
100
118
|
'nest-validation-without-whitelist': 'medium',
|
|
101
119
|
'next-image-any-remote-host': 'medium',
|
|
120
|
+
'nginx-proxy-pass-request-host': 'high',
|
|
102
121
|
'nosql-operator-injection': 'high',
|
|
103
122
|
'open-redirect': 'medium',
|
|
123
|
+
'package-script-remote-code': 'high',
|
|
124
|
+
'package-script-tls-verification-disabled': 'medium',
|
|
104
125
|
'password-hash-in-response': 'high',
|
|
105
126
|
'path-traversal': 'high',
|
|
106
127
|
'pg-dynamic-query-text': 'medium',
|
|
@@ -134,6 +155,11 @@ const impactByRule = {
|
|
|
134
155
|
'template-autoescape-disabled': 'medium',
|
|
135
156
|
'template-injection': 'critical',
|
|
136
157
|
'template-raw-html-binding': 'medium',
|
|
158
|
+
'terraform-admin-port-open-to-world': 'high',
|
|
159
|
+
'terraform-database-publicly-accessible': 'high',
|
|
160
|
+
'terraform-hardcoded-credential': 'high',
|
|
161
|
+
'terraform-storage-bucket-public': 'high',
|
|
162
|
+
'terraform-storage-encryption-disabled': 'medium',
|
|
137
163
|
'tls-verification-disabled': 'high',
|
|
138
164
|
'trust-boundary-violation': 'medium',
|
|
139
165
|
'typeorm-dynamic-query-text': 'critical',
|
|
@@ -142,6 +168,9 @@ const impactByRule = {
|
|
|
142
168
|
'vue-v-html-unsanitized': 'high',
|
|
143
169
|
'weak-hash': 'medium',
|
|
144
170
|
'weak-password-hash': 'high',
|
|
171
|
+
'web-server-directory-listing': 'medium',
|
|
172
|
+
'web-server-legacy-tls': 'medium',
|
|
173
|
+
'web-server-version-exposed': 'low',
|
|
145
174
|
'webhook-body-without-verification': 'high',
|
|
146
175
|
'xml-external-entities': 'medium',
|
|
147
176
|
'xpath-injection': 'high',
|