xploitscan-shared-rules 1.35.2 → 1.36.1
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 +7 -7
- package/dist/index.cjs +148 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -12
- package/dist/index.d.ts +25 -12
- package/dist/index.js +146 -82
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2425,7 +2425,7 @@ var evalUsage = {
|
|
|
2425
2425
|
title: "Use of eval() or Function Constructor",
|
|
2426
2426
|
severity: "high",
|
|
2427
2427
|
category: "Injection",
|
|
2428
|
-
description: "eval() and new Function() execute arbitrary code, creating severe injection risks.
|
|
2428
|
+
description: "eval() and new Function() execute arbitrary code, creating severe injection risks.",
|
|
2429
2429
|
check(content, filePath) {
|
|
2430
2430
|
if (filePath.includes("node_modules") || filePath.includes(".min.")) return [];
|
|
2431
2431
|
if (filePath.match(/(?:webpack|rollup|vite|jest|babel|tsup|esbuild)\.config/i)) return [];
|
|
@@ -3089,7 +3089,7 @@ var missingHTTPS = {
|
|
|
3089
3089
|
title: "Missing HTTPS Enforcement",
|
|
3090
3090
|
severity: "high",
|
|
3091
3091
|
category: "Configuration",
|
|
3092
|
-
description: "
|
|
3092
|
+
description: "Hardcoded http:// URLs (other than localhost and private-network addresses) send data unencrypted, exposing it to man-in-the-middle attacks.",
|
|
3093
3093
|
check(content, filePath) {
|
|
3094
3094
|
if (filePath.endsWith(".example") || filePath.includes("test") || filePath.includes("README")) return [];
|
|
3095
3095
|
if (filePath.match(/\.(md|txt)$/)) return [];
|
|
@@ -3674,7 +3674,7 @@ var weakPasswordRequirements = {
|
|
|
3674
3674
|
p,
|
|
3675
3675
|
weakPasswordRequirements,
|
|
3676
3676
|
filePath,
|
|
3677
|
-
() => "Minimum password length is too low. Require at least 8 characters
|
|
3677
|
+
() => "Minimum password length is too low. Require at least 8 characters, and at least 15 when the password is the only authentication factor (NIST SP 800-63B)."
|
|
3678
3678
|
));
|
|
3679
3679
|
}
|
|
3680
3680
|
if (matches.length > 0) return matches;
|
|
@@ -4623,7 +4623,7 @@ var corsServerless = {
|
|
|
4623
4623
|
title: "CORS Wildcard in Serverless Config",
|
|
4624
4624
|
severity: "high",
|
|
4625
4625
|
category: "Configuration",
|
|
4626
|
-
description: "Setting Access-Control-Allow-Origin: * in serverless.yml, vercel.json, or similar configs
|
|
4626
|
+
description: "Setting Access-Control-Allow-Origin: * in serverless.yml, vercel.json, or similar configs lets any website read your API's responses.",
|
|
4627
4627
|
check(content, filePath) {
|
|
4628
4628
|
if (!filePath.match(/serverless\.(yml|yaml)|vercel\.json|netlify\.toml|amplify\.yml/i)) return [];
|
|
4629
4629
|
const matches = [];
|
|
@@ -5413,7 +5413,7 @@ var complianceMap = {
|
|
|
5413
5413
|
VC022: { owasp: "A03:2021", cwe: "CWE-79" },
|
|
5414
5414
|
VC023: { owasp: "A08:2021", cwe: "CWE-1321" },
|
|
5415
5415
|
VC024: { owasp: "A04:2021", cwe: "CWE-770" },
|
|
5416
|
-
VC025: { owasp: "
|
|
5416
|
+
VC025: { owasp: "A01:2021", cwe: "CWE-22" },
|
|
5417
5417
|
VC026: { owasp: "A05:2021", cwe: "CWE-693" },
|
|
5418
5418
|
VC027: { owasp: "A05:2021", cwe: "CWE-693" },
|
|
5419
5419
|
VC028: { owasp: "A07:2021", cwe: "CWE-20" },
|
|
@@ -5441,7 +5441,7 @@ var complianceMap = {
|
|
|
5441
5441
|
VC050: { owasp: "A02:2021", cwe: "CWE-319" },
|
|
5442
5442
|
VC051: { owasp: "A05:2021", cwe: "CWE-200" },
|
|
5443
5443
|
VC052: { owasp: "A04:2021", cwe: "CWE-770" },
|
|
5444
|
-
VC053: { owasp: "A05:2021", cwe: "CWE-
|
|
5444
|
+
VC053: { owasp: "A05:2021", cwe: "CWE-547" },
|
|
5445
5445
|
VC054: { owasp: "A07:2021", cwe: "CWE-922" },
|
|
5446
5446
|
VC055: { owasp: "A05:2021", cwe: "CWE-540" },
|
|
5447
5447
|
VC056: { owasp: "A05:2021", cwe: "CWE-1021" },
|
|
@@ -5499,13 +5499,13 @@ var complianceMap = {
|
|
|
5499
5499
|
VC108: { owasp: "A01:2021", cwe: "CWE-284" },
|
|
5500
5500
|
VC109: { owasp: "A01:2021", cwe: "CWE-284" },
|
|
5501
5501
|
VC110: { owasp: "A09:2021", cwe: "CWE-778" },
|
|
5502
|
-
VC111: { owasp: "A05:2021", cwe: "CWE-
|
|
5502
|
+
VC111: { owasp: "A05:2021", cwe: "CWE-653" },
|
|
5503
5503
|
VC112: { owasp: "A06:2021", cwe: "CWE-1104" },
|
|
5504
5504
|
VC113: { owasp: "A05:2021", cwe: "CWE-200" },
|
|
5505
5505
|
VC114: { owasp: "A05:2021", cwe: "CWE-16" },
|
|
5506
5506
|
VC115: { owasp: "A02:2021", cwe: "CWE-311" },
|
|
5507
5507
|
VC116: { owasp: "A05:2021", cwe: "CWE-770" },
|
|
5508
|
-
VC117: { owasp: "
|
|
5508
|
+
VC117: { owasp: "A01:2021", cwe: "CWE-22" },
|
|
5509
5509
|
VC118: { owasp: "A09:2021", cwe: "CWE-532" },
|
|
5510
5510
|
VC119: { owasp: "A07:2021", cwe: "CWE-798" },
|
|
5511
5511
|
VC120: { owasp: "A07:2021", cwe: "CWE-352" },
|
|
@@ -5548,7 +5548,7 @@ var complianceMap = {
|
|
|
5548
5548
|
VC154: { owasp: "A03:2021", cwe: "CWE-20" },
|
|
5549
5549
|
VC155: { owasp: "A04:2021", cwe: "CWE-770" },
|
|
5550
5550
|
VC156: { owasp: "A04:2021", cwe: "CWE-770" },
|
|
5551
|
-
VC157: { owasp: "A05:2021", cwe: "CWE-
|
|
5551
|
+
VC157: { owasp: "A05:2021", cwe: "CWE-1327" },
|
|
5552
5552
|
VC158: { owasp: "A01:2021", cwe: "CWE-639" },
|
|
5553
5553
|
// VC159–VC183: Additional service-specific API key detection.
|
|
5554
5554
|
// All map to A07:2021 (Identification & Auth Failures) / CWE-798 (Hardcoded
|
|
@@ -6227,7 +6227,7 @@ var piiInLogs = {
|
|
|
6227
6227
|
title: "Personally Identifiable Information in Logs",
|
|
6228
6228
|
severity: "high",
|
|
6229
6229
|
category: "Information Leakage",
|
|
6230
|
-
description: "Logging statements that include
|
|
6230
|
+
description: "Logging statements that include passwords, secrets, tokens, authorization headers, SSNs, credit card numbers or CVVs can leak sensitive data to log aggregation systems.",
|
|
6231
6231
|
check(content, filePath) {
|
|
6232
6232
|
if (isTestFile(filePath)) return [];
|
|
6233
6233
|
if (!filePath.match(/\.(js|ts|jsx|tsx|py|rb|go|java|php)$/)) return [];
|
|
@@ -6670,7 +6670,7 @@ var vulnerableDependencies = {
|
|
|
6670
6670
|
title: "Potentially Vulnerable Dependency",
|
|
6671
6671
|
severity: "high",
|
|
6672
6672
|
category: "Supply Chain",
|
|
6673
|
-
description: "
|
|
6673
|
+
description: "Dependency versions with known security issues.",
|
|
6674
6674
|
check(content, filePath) {
|
|
6675
6675
|
if (!filePath.endsWith("package.json")) return [];
|
|
6676
6676
|
if (/node_modules|\.next|dist|build/.test(filePath)) return [];
|
|
@@ -6679,7 +6679,7 @@ var vulnerableDependencies = {
|
|
|
6679
6679
|
[/"jsonwebtoken"\s*:\s*"[\^~]?[0-7]\./g, "jsonwebtoken < 8.x has signature bypass vulnerabilities"],
|
|
6680
6680
|
[/"lodash"\s*:\s*"[\^~]?[0-3]\./g, "lodash < 4.x has prototype pollution vulnerabilities"],
|
|
6681
6681
|
[/"minimist"\s*:\s*"[\^~]?[01]\.[01]\./g, "minimist < 1.2.6 has prototype pollution"],
|
|
6682
|
-
[/"node-fetch"\s*:\s*"[\^~]?[12]\./g, "node-fetch
|
|
6682
|
+
[/"node-fetch"\s*:\s*"[\^~]?[12]\./g, "node-fetch before 2.6.7 (and 3.x before 3.1.1) forwards cookie and authorization headers on cross-origin redirects (CVE-2022-0235); check that this 1.x/2.x range resolves to 2.6.7 or later"],
|
|
6683
6683
|
[/"express"\s*:\s*"[\^~]?[0-3]\./g, "express < 4.x has multiple known vulnerabilities"],
|
|
6684
6684
|
[/"axios"\s*:\s*"[\^~]?0\.[0-9]\./g, "axios < 0.21 has SSRF vulnerabilities"],
|
|
6685
6685
|
[/"tar"\s*:\s*"[\^~]?[0-5]\./g, "tar < 6.x has path traversal vulnerabilities"],
|
|
@@ -7616,7 +7616,7 @@ var ghaThirdPartyActionWithSecrets = {
|
|
|
7616
7616
|
title: "GitHub Actions: secrets passed to third-party action",
|
|
7617
7617
|
severity: "medium",
|
|
7618
7618
|
category: "Supply Chain",
|
|
7619
|
-
description: "Passing repository secrets (`${{ secrets.* }}`) via the `with:` block to a third-party action means the action's source code \u2014 and any transitive dependencies it pulls \u2014 has access to those secrets.
|
|
7619
|
+
description: "Passing repository secrets (`${{ secrets.* }}`) via the `with:` block to a third-party action means the action's source code \u2014 and any transitive dependencies it pulls \u2014 has access to those secrets. A compromised action can read every secret its job has access to: in the March 2025 tj-actions/changed-files compromise, the hijacked action dumped secrets from runner memory into build logs. Common when intentional (AWS, Cloudflare, GCP credential actions) but worth flagging for review.",
|
|
7620
7620
|
check(content, filePath) {
|
|
7621
7621
|
if (!GHA_WORKFLOW_RE.test(filePath)) return [];
|
|
7622
7622
|
const findings = [];
|
|
@@ -8678,7 +8678,7 @@ var secretInURLParam = {
|
|
|
8678
8678
|
title: "Secret Passed in URL Query Parameter",
|
|
8679
8679
|
severity: "critical",
|
|
8680
8680
|
category: "Secrets",
|
|
8681
|
-
description: "API keys or tokens in URL query parameters are logged in server access logs, browser history, referrer headers, and proxy logs.
|
|
8681
|
+
description: "API keys or tokens in URL query parameters are logged in server access logs, browser history, referrer headers, and proxy logs.",
|
|
8682
8682
|
check(content, filePath) {
|
|
8683
8683
|
if (isTestFile(filePath)) return [];
|
|
8684
8684
|
if (!filePath.match(/\.(js|ts|jsx|tsx|py|rb|go|java|php)$/)) return [];
|
|
@@ -10031,7 +10031,7 @@ function assessHeaders(headers) {
|
|
|
10031
10031
|
out.push({
|
|
10032
10032
|
header: "Strict-Transport-Security",
|
|
10033
10033
|
severity: "medium",
|
|
10034
|
-
message: "No HSTS.
|
|
10034
|
+
message: "No HSTS. Any visit that starts over http can be intercepted before the redirect to https."
|
|
10035
10035
|
});
|
|
10036
10036
|
}
|
|
10037
10037
|
if (!h["x-content-type-options"]) {
|
|
@@ -10045,7 +10045,7 @@ function assessHeaders(headers) {
|
|
|
10045
10045
|
out.push({
|
|
10046
10046
|
header: "Referrer-Policy",
|
|
10047
10047
|
severity: "low",
|
|
10048
|
-
message: "No referrer policy.
|
|
10048
|
+
message: "No referrer policy, so the browser default applies. Current browsers send only your origin to other sites, but older ones send full URLs \u2014 including any ids in the path."
|
|
10049
10049
|
});
|
|
10050
10050
|
}
|
|
10051
10051
|
return out;
|
|
@@ -10105,6 +10105,12 @@ function buildQualityContext(files) {
|
|
|
10105
10105
|
});
|
|
10106
10106
|
return { files: built, byPath: new Map(built.map((f) => [f.path, f])) };
|
|
10107
10107
|
}
|
|
10108
|
+
function isClientTarget(file) {
|
|
10109
|
+
return !file.excluded && file.isClient && !file.isServer;
|
|
10110
|
+
}
|
|
10111
|
+
function isServerTarget(file) {
|
|
10112
|
+
return !file.excluded && file.isServer;
|
|
10113
|
+
}
|
|
10108
10114
|
function lineAt(content, index) {
|
|
10109
10115
|
let line = 1;
|
|
10110
10116
|
for (let i = 0; i < index && i < content.length; i++) {
|
|
@@ -12319,6 +12325,55 @@ var unassociatedLabel = {
|
|
|
12319
12325
|
|
|
12320
12326
|
// src/quality/rules/failed-read-empty-state.ts
|
|
12321
12327
|
import _traverse4 from "@babel/traverse";
|
|
12328
|
+
import { getBindingIdentifiers } from "@babel/types";
|
|
12329
|
+
|
|
12330
|
+
// src/quality/rules/scope.ts
|
|
12331
|
+
function unwrap(node) {
|
|
12332
|
+
let cur = node;
|
|
12333
|
+
while (cur.type === "TSAsExpression" || cur.type === "TSNonNullExpression" || cur.type === "TSTypeAssertion" || cur.type === "TSSatisfiesExpression") {
|
|
12334
|
+
cur = cur.expression;
|
|
12335
|
+
}
|
|
12336
|
+
return cur;
|
|
12337
|
+
}
|
|
12338
|
+
function calleeName3(node) {
|
|
12339
|
+
if (node.type !== "CallExpression" && node.type !== "OptionalCallExpression") return null;
|
|
12340
|
+
const c = node.callee;
|
|
12341
|
+
if (c.type === "Identifier") return c.name;
|
|
12342
|
+
if ((c.type === "MemberExpression" || c.type === "OptionalMemberExpression") && c.property.type === "Identifier") {
|
|
12343
|
+
return c.property.name;
|
|
12344
|
+
}
|
|
12345
|
+
return null;
|
|
12346
|
+
}
|
|
12347
|
+
function useStateBinding(at, name) {
|
|
12348
|
+
const binding = at.scope.getBinding(name);
|
|
12349
|
+
if (!binding) return void 0;
|
|
12350
|
+
const decl = binding.path;
|
|
12351
|
+
if (!decl.isVariableDeclarator()) return void 0;
|
|
12352
|
+
const id = decl.node.id;
|
|
12353
|
+
const init = decl.node.init;
|
|
12354
|
+
if (id.type !== "ArrayPattern") return void 0;
|
|
12355
|
+
if (!init || calleeName3(init) !== "useState") return void 0;
|
|
12356
|
+
const first = id.elements[0];
|
|
12357
|
+
if (!first || first.type !== "Identifier" || first.name !== name) return void 0;
|
|
12358
|
+
const second = id.elements[1];
|
|
12359
|
+
return {
|
|
12360
|
+
initial: init.arguments[0],
|
|
12361
|
+
setter: second && second.type === "Identifier" ? second.name : null,
|
|
12362
|
+
decl
|
|
12363
|
+
};
|
|
12364
|
+
}
|
|
12365
|
+
function isEmptyInitial(node) {
|
|
12366
|
+
if (!node) return false;
|
|
12367
|
+
if (node.type === "ArrayExpression") return node.elements.length === 0;
|
|
12368
|
+
if (node.type === "ObjectExpression") return node.properties.length === 0;
|
|
12369
|
+
if (node.type === "StringLiteral") return node.value === "";
|
|
12370
|
+
if (node.type === "TemplateLiteral") {
|
|
12371
|
+
return node.quasis.length === 1 && node.quasis[0].value.raw === "";
|
|
12372
|
+
}
|
|
12373
|
+
return false;
|
|
12374
|
+
}
|
|
12375
|
+
|
|
12376
|
+
// src/quality/rules/failed-read-empty-state.ts
|
|
12322
12377
|
var traverse4 = typeof _traverse4 === "function" ? _traverse4 : _traverse4.default;
|
|
12323
12378
|
var READ_ERROR_PATH_SIGNALS = ERROR_PATH_SIGNALS.filter(
|
|
12324
12379
|
(re) => re.source !== /\.catch\s*\(/.source
|
|
@@ -12336,19 +12391,15 @@ function setterName(callee) {
|
|
|
12336
12391
|
function isPropertyRead(node) {
|
|
12337
12392
|
return node.type === "MemberExpression" || node.type === "OptionalMemberExpression";
|
|
12338
12393
|
}
|
|
12339
|
-
function
|
|
12340
|
-
|
|
12341
|
-
while (cur && (cur.type === "TSAsExpression" || cur.type === "TSNonNullExpression" || cur.type === "TSTypeAssertion" || cur.type === "TSSatisfiesExpression" || cur.type === "ParenthesizedExpression")) {
|
|
12342
|
-
cur = cur.expression;
|
|
12343
|
-
}
|
|
12344
|
-
return cur;
|
|
12394
|
+
function mentionsJsonParse(node, code) {
|
|
12395
|
+
return /\.json\s*\(/.test(code.slice(nodeStart(node), nodeEnd(node)));
|
|
12345
12396
|
}
|
|
12346
12397
|
function chainParsesBody(node, code) {
|
|
12347
12398
|
let cur = unwrap(node);
|
|
12348
|
-
|
|
12399
|
+
for (; ; ) {
|
|
12349
12400
|
if (cur.type === "CallExpression" || cur.type === "OptionalCallExpression") {
|
|
12350
12401
|
const callee = unwrap(cur.callee);
|
|
12351
|
-
if (
|
|
12402
|
+
if ((callee.type === "MemberExpression" || callee.type === "OptionalMemberExpression") && callee.property.type === "Identifier") {
|
|
12352
12403
|
const method = callee.property.name;
|
|
12353
12404
|
if (method === "json") return true;
|
|
12354
12405
|
if (method === "then" || method === "catch") {
|
|
@@ -12360,7 +12411,7 @@ function chainParsesBody(node, code) {
|
|
|
12360
12411
|
cur = unwrap(callee.object);
|
|
12361
12412
|
continue;
|
|
12362
12413
|
}
|
|
12363
|
-
cur =
|
|
12414
|
+
cur = callee;
|
|
12364
12415
|
continue;
|
|
12365
12416
|
}
|
|
12366
12417
|
if (cur.type === "MemberExpression" || cur.type === "OptionalMemberExpression") {
|
|
@@ -12372,23 +12423,14 @@ function chainParsesBody(node, code) {
|
|
|
12372
12423
|
return false;
|
|
12373
12424
|
}
|
|
12374
12425
|
function boundNames(id, into) {
|
|
12375
|
-
|
|
12376
|
-
into.add(id.name);
|
|
12377
|
-
return;
|
|
12378
|
-
}
|
|
12379
|
-
if (id.type === "ObjectPattern") {
|
|
12380
|
-
for (const prop of id.properties) {
|
|
12381
|
-
if (prop.type === "ObjectProperty") boundNames(prop.value, into);
|
|
12382
|
-
else if (prop.type === "RestElement") boundNames(prop.argument, into);
|
|
12383
|
-
}
|
|
12384
|
-
}
|
|
12426
|
+
for (const name of Object.keys(getBindingIdentifiers(id))) into.add(name);
|
|
12385
12427
|
}
|
|
12386
12428
|
function parsedBodyBindings(unit, code) {
|
|
12387
12429
|
const names = /* @__PURE__ */ new Set();
|
|
12388
12430
|
const record = (id, init) => {
|
|
12389
|
-
if (!id) return;
|
|
12431
|
+
if (!id || !init) return;
|
|
12390
12432
|
const awaited = unwrap(init);
|
|
12391
|
-
if (
|
|
12433
|
+
if (awaited.type !== "AwaitExpression") return;
|
|
12392
12434
|
if (!chainParsesBody(awaited.argument, code)) return;
|
|
12393
12435
|
boundNames(id, names);
|
|
12394
12436
|
};
|
|
@@ -12412,7 +12454,7 @@ function parsedBodyBindings(unit, code) {
|
|
|
12412
12454
|
return;
|
|
12413
12455
|
if (callee.property.type !== "Identifier" || callee.property.name !== "then") return;
|
|
12414
12456
|
const receiver = callee.object;
|
|
12415
|
-
if (
|
|
12457
|
+
if (!mentionsJsonParse(receiver, code)) return;
|
|
12416
12458
|
const cb = call.node.arguments[0];
|
|
12417
12459
|
if (!cb) return;
|
|
12418
12460
|
if (cb.type !== "ArrowFunctionExpression" && cb.type !== "FunctionExpression") return;
|
|
@@ -12427,13 +12469,9 @@ function derivesFromParsedBody(node, bodies, code) {
|
|
|
12427
12469
|
while (cur && (cur.type === "MemberExpression" || cur.type === "OptionalMemberExpression")) {
|
|
12428
12470
|
cur = unwrap(cur.object);
|
|
12429
12471
|
}
|
|
12430
|
-
if (!cur) return false;
|
|
12431
12472
|
if (cur.type === "Identifier") return bodies.has(cur.name);
|
|
12432
|
-
if (cur.type === "AwaitExpression")
|
|
12433
|
-
|
|
12434
|
-
return chainParsesBody(cur, code);
|
|
12435
|
-
}
|
|
12436
|
-
return false;
|
|
12473
|
+
if (cur.type === "AwaitExpression") cur = unwrap(cur.argument);
|
|
12474
|
+
return chainParsesBody(cur, code);
|
|
12437
12475
|
}
|
|
12438
12476
|
function emptyFallbackArgument(node) {
|
|
12439
12477
|
if (node.type !== "LogicalExpression") return null;
|
|
@@ -12483,6 +12521,7 @@ var failedReadEmptyState = {
|
|
|
12483
12521
|
if (!file.isClient) continue;
|
|
12484
12522
|
if (file.isServer) continue;
|
|
12485
12523
|
if (/^\s*["']use server["']/m.test(file.code)) continue;
|
|
12524
|
+
if (!file.code.includes("fetch")) continue;
|
|
12486
12525
|
const parsed = file.parsed;
|
|
12487
12526
|
if (!parsed) continue;
|
|
12488
12527
|
const examined = /* @__PURE__ */ new Set();
|
|
@@ -12528,6 +12567,20 @@ var failedReadEmptyState = {
|
|
|
12528
12567
|
// src/quality/rules/autosave-armed-by-failed-load.ts
|
|
12529
12568
|
import _traverse5 from "@babel/traverse";
|
|
12530
12569
|
var traverse5 = typeof _traverse5 === "function" ? _traverse5 : _traverse5.default;
|
|
12570
|
+
function writerTouchesEmptyState(writers) {
|
|
12571
|
+
for (const writer of writers) {
|
|
12572
|
+
let found = false;
|
|
12573
|
+
writer.traverse({
|
|
12574
|
+
Identifier(id) {
|
|
12575
|
+
if (found) return;
|
|
12576
|
+
if (!id.isReferencedIdentifier()) return;
|
|
12577
|
+
if (isEmptyInitial(useStateBinding(id, id.node.name)?.initial)) found = true;
|
|
12578
|
+
}
|
|
12579
|
+
});
|
|
12580
|
+
if (found) return true;
|
|
12581
|
+
}
|
|
12582
|
+
return false;
|
|
12583
|
+
}
|
|
12531
12584
|
var PERSISTENT_WRITE = /\bfetch\s*\([^)]{0,400}?method\s*:\s*["'`](?:POST|PUT|PATCH)["'`]|\blocalStorage\s*\.\s*setItem\s*\(|\bsessionStorage\s*\.\s*setItem\s*\(/is;
|
|
12532
12585
|
var EMPTY_INITIAL = /\buseState\s*(?:<[^>]*>)?\s*\(\s*(?:\[\s*\]|\{\s*\}|""|''|``)\s*\)/;
|
|
12533
12586
|
function calleeIdentifier(node) {
|
|
@@ -12541,22 +12594,6 @@ function isEffectCall2(node) {
|
|
|
12541
12594
|
const name = calleeIdentifier(node);
|
|
12542
12595
|
return name === "useEffect" || name === "useLayoutEffect";
|
|
12543
12596
|
}
|
|
12544
|
-
function initialFor(call, state) {
|
|
12545
|
-
const binding = call.scope.getBinding(state);
|
|
12546
|
-
if (!binding) return void 0;
|
|
12547
|
-
const decl = binding.path;
|
|
12548
|
-
if (!decl.isVariableDeclarator()) return void 0;
|
|
12549
|
-
const id = decl.node.id;
|
|
12550
|
-
const init = decl.node.init;
|
|
12551
|
-
if (!id || id.type !== "ArrayPattern") return void 0;
|
|
12552
|
-
if (!init || init.type !== "CallExpression") return void 0;
|
|
12553
|
-
const callee = init.callee;
|
|
12554
|
-
const name = callee.type === "Identifier" ? callee.name : callee.type === "MemberExpression" && callee.property.type === "Identifier" ? callee.property.name : null;
|
|
12555
|
-
if (name !== "useState") return void 0;
|
|
12556
|
-
const first = id.elements[0];
|
|
12557
|
-
if (!first || first.type !== "Identifier" || first.name !== state) return void 0;
|
|
12558
|
-
return init.arguments[0];
|
|
12559
|
-
}
|
|
12560
12597
|
function sameLiteral(a, b) {
|
|
12561
12598
|
if (!a || !b || a.type !== b.type) return false;
|
|
12562
12599
|
switch (a.type) {
|
|
@@ -12604,9 +12641,7 @@ var autosaveArmedByFailedLoad = {
|
|
|
12604
12641
|
check(ctx) {
|
|
12605
12642
|
const hits = [];
|
|
12606
12643
|
for (const file of ctx.files) {
|
|
12607
|
-
if (file
|
|
12608
|
-
if (!file.isClient) continue;
|
|
12609
|
-
if (file.isServer) continue;
|
|
12644
|
+
if (!isClientTarget(file)) continue;
|
|
12610
12645
|
const parsed = file.parsed;
|
|
12611
12646
|
if (!parsed) continue;
|
|
12612
12647
|
if (!EMPTY_INITIAL.test(file.code)) continue;
|
|
@@ -12621,29 +12656,32 @@ var autosaveArmedByFailedLoad = {
|
|
|
12621
12656
|
if (!name) return;
|
|
12622
12657
|
const state = stateFromSetter(name);
|
|
12623
12658
|
if (!state) return;
|
|
12624
|
-
if (setsBackToInitial(call.node,
|
|
12659
|
+
if (setsBackToInitial(call.node, useStateBinding(call, state)?.initial)) return;
|
|
12625
12660
|
armedInFinally.set(state, nodeStart(call.node));
|
|
12626
12661
|
}
|
|
12627
12662
|
});
|
|
12628
12663
|
}
|
|
12629
12664
|
});
|
|
12630
12665
|
if (armedInFinally.size === 0) continue;
|
|
12631
|
-
const writingFunctions = /* @__PURE__ */ new
|
|
12666
|
+
const writingFunctions = /* @__PURE__ */ new Map();
|
|
12632
12667
|
traverse5(parsed.ast, {
|
|
12633
12668
|
Function(path) {
|
|
12634
12669
|
const src = file.code.slice(nodeStart(path.node), nodeEnd(path.node));
|
|
12635
12670
|
if (!PERSISTENT_WRITE.test(src)) return;
|
|
12671
|
+
const deps = [];
|
|
12636
12672
|
let owner = path.parentPath;
|
|
12637
12673
|
for (let hops = 0; owner && hops < 3; hops++, owner = owner.parentPath) {
|
|
12638
12674
|
const node = owner.node;
|
|
12639
12675
|
if (node.type === "VariableDeclarator" && node.id.type === "Identifier") {
|
|
12640
|
-
writingFunctions.
|
|
12676
|
+
writingFunctions.set(node.id.name, [path, ...deps]);
|
|
12641
12677
|
break;
|
|
12642
12678
|
}
|
|
12643
12679
|
if (node.type !== "CallExpression") break;
|
|
12680
|
+
const depArg = owner.get("arguments.1");
|
|
12681
|
+
if (depArg && depArg.node) deps.push(depArg);
|
|
12644
12682
|
}
|
|
12645
12683
|
const n = path.node;
|
|
12646
|
-
if (n.id && n.id.name) writingFunctions.
|
|
12684
|
+
if (n.id && n.id.name) writingFunctions.set(n.id.name, [path, ...deps]);
|
|
12647
12685
|
}
|
|
12648
12686
|
});
|
|
12649
12687
|
const reported = /* @__PURE__ */ new Set();
|
|
@@ -12655,8 +12693,15 @@ var autosaveArmedByFailedLoad = {
|
|
|
12655
12693
|
const body = file.code.slice(nodeStart(cb.node), nodeEnd(cb.node));
|
|
12656
12694
|
const names = identifiersIn(cb);
|
|
12657
12695
|
const writesDirectly = PERSISTENT_WRITE.test(body);
|
|
12658
|
-
const
|
|
12659
|
-
if (!writesDirectly &&
|
|
12696
|
+
const calledWriters = [...writingFunctions.entries()].filter(([fn]) => names.has(fn)).flatMap(([, paths]) => paths);
|
|
12697
|
+
if (!writesDirectly && calledWriters.length === 0) return;
|
|
12698
|
+
const effectDeps = path.get("arguments.1");
|
|
12699
|
+
const writers = [
|
|
12700
|
+
...writesDirectly ? [cb] : [],
|
|
12701
|
+
...calledWriters,
|
|
12702
|
+
...effectDeps && effectDeps.node ? [effectDeps] : []
|
|
12703
|
+
];
|
|
12704
|
+
if (!writerTouchesEmptyState(writers)) return;
|
|
12660
12705
|
for (const [state, armLine] of armedInFinally) {
|
|
12661
12706
|
if (!names.has(state)) continue;
|
|
12662
12707
|
if (reported.has(state)) continue;
|
|
@@ -12683,7 +12728,7 @@ var DURABLE_WRITE = /\b(?:INSERT\s+INTO\b|UPDATE\s+\w+\s+SET\b|DELETE\s+FROM\b)|
|
|
|
12683
12728
|
var EXTERNAL_MUTATION = /\b\w+\s*\.\s*\w+\s*\.\s*(?:create|send|update|delete|cancel|charge|capture|refund)\s*\(|\bfetch\s*\([^)]{0,300}?method\s*:\s*["'`](?:POST|PUT|PATCH|DELETE)["'`]/is;
|
|
12684
12729
|
var BOOKKEEPING = /analytics|telemetry|track|metric|event|beacon|log|audit|ping/i;
|
|
12685
12730
|
var DIRECT_ENV_TEST = /\bprocess\s*\.\s*env\b|\bDeno\s*\.\s*env\s*\.\s*get\s*\(/;
|
|
12686
|
-
function
|
|
12731
|
+
function calleeName4(node) {
|
|
12687
12732
|
if (node.type !== "CallExpression") return null;
|
|
12688
12733
|
const c = node.callee;
|
|
12689
12734
|
if (c.type === "Identifier") return c.name;
|
|
@@ -12705,11 +12750,11 @@ function successPayloadShape(ret, source, offset) {
|
|
|
12705
12750
|
if (!arg || arg.type !== "CallExpression") return null;
|
|
12706
12751
|
const text = source.slice(nodeStart(ret) - offset, nodeEnd(ret) - offset);
|
|
12707
12752
|
if (/status\s*:\s*[45]\d\d|,\s*\{\s*status\s*:\s*[45]\d\d/.test(text)) return null;
|
|
12708
|
-
const name =
|
|
12753
|
+
const name = calleeName4(arg);
|
|
12709
12754
|
if (name !== "json" && name !== "Response" && name !== "NextResponse") return null;
|
|
12710
12755
|
const first = arg.arguments[0];
|
|
12711
12756
|
if (!first) return null;
|
|
12712
|
-
if (first.type === "CallExpression" &&
|
|
12757
|
+
if (first.type === "CallExpression" && calleeName4(first) === "stringify") {
|
|
12713
12758
|
return keyShape(first.arguments[0]);
|
|
12714
12759
|
}
|
|
12715
12760
|
return keyShape(first);
|
|
@@ -12889,9 +12934,7 @@ var staleResponseWins = {
|
|
|
12889
12934
|
check(ctx) {
|
|
12890
12935
|
const hits = [];
|
|
12891
12936
|
for (const file of ctx.files) {
|
|
12892
|
-
if (file
|
|
12893
|
-
if (!file.isClient) continue;
|
|
12894
|
-
if (file.isServer) continue;
|
|
12937
|
+
if (!isClientTarget(file)) continue;
|
|
12895
12938
|
const parsed = file.parsed;
|
|
12896
12939
|
if (!parsed) continue;
|
|
12897
12940
|
traverse7(parsed.ast, {
|
|
@@ -12936,7 +12979,10 @@ var staleResponseWins = {
|
|
|
12936
12979
|
for (const ident2 of interpolated) {
|
|
12937
12980
|
if (!derivesFromDep(ident2, deps, cb, file.code)) continue;
|
|
12938
12981
|
if (new RegExp(`\\b${ident2}\\b`).test(afterCall)) continue;
|
|
12939
|
-
|
|
12982
|
+
const driving = [...deps].filter(
|
|
12983
|
+
(d) => derivesFromDep(ident2, /* @__PURE__ */ new Set([d]), cb, file.code)
|
|
12984
|
+
);
|
|
12985
|
+
if (!driving.some((d) => userDriven(d, cb))) continue;
|
|
12940
12986
|
hit = { line: lineAt(file.content, nodeStart(inner.node)), ident: ident2 };
|
|
12941
12987
|
return;
|
|
12942
12988
|
}
|
|
@@ -12955,10 +13001,26 @@ var staleResponseWins = {
|
|
|
12955
13001
|
return hits;
|
|
12956
13002
|
}
|
|
12957
13003
|
};
|
|
12958
|
-
function userDriven(dep,
|
|
12959
|
-
const
|
|
12960
|
-
|
|
12961
|
-
|
|
13004
|
+
function userDriven(dep, at) {
|
|
13005
|
+
const binding = useStateBinding(at, dep);
|
|
13006
|
+
const setter = binding?.setter;
|
|
13007
|
+
if (!setter) return false;
|
|
13008
|
+
const owner = binding.decl.getFunctionParent() ?? binding.decl.scope.path;
|
|
13009
|
+
let wired = false;
|
|
13010
|
+
owner.traverse({
|
|
13011
|
+
JSXAttribute(attr) {
|
|
13012
|
+
if (wired) return;
|
|
13013
|
+
const name = attr.node.name;
|
|
13014
|
+
if (name.type !== "JSXIdentifier") return;
|
|
13015
|
+
if (!/^on(?:Change|Click|Input|Select)$/.test(name.name)) return;
|
|
13016
|
+
attr.traverse({
|
|
13017
|
+
Identifier(id) {
|
|
13018
|
+
if (id.node.name === setter) wired = true;
|
|
13019
|
+
}
|
|
13020
|
+
});
|
|
13021
|
+
}
|
|
13022
|
+
});
|
|
13023
|
+
return wired;
|
|
12962
13024
|
}
|
|
12963
13025
|
|
|
12964
13026
|
// src/quality/rules/lost-update-counter.ts
|
|
@@ -13479,8 +13541,8 @@ var qualityRules = [
|
|
|
13479
13541
|
var unmeasuredQualityRules = [
|
|
13480
13542
|
lostUpdateCounter
|
|
13481
13543
|
];
|
|
13482
|
-
function scanQuality(
|
|
13483
|
-
const ctx =
|
|
13544
|
+
function scanQuality(input, rules = qualityRules) {
|
|
13545
|
+
const ctx = Array.isArray(input) ? buildQualityContext(input) : input;
|
|
13484
13546
|
const findings = [];
|
|
13485
13547
|
for (const rule of rules) {
|
|
13486
13548
|
let hits;
|
|
@@ -13664,8 +13726,10 @@ export {
|
|
|
13664
13726
|
insecureWebSocket,
|
|
13665
13727
|
ipcPathTraversal,
|
|
13666
13728
|
isCalleeNamed,
|
|
13729
|
+
isClientTarget,
|
|
13667
13730
|
isMethodCall,
|
|
13668
13731
|
isPrivateAddress,
|
|
13732
|
+
isServerTarget,
|
|
13669
13733
|
isVendoredFinding,
|
|
13670
13734
|
isVendoredPath,
|
|
13671
13735
|
javaDeserialization,
|