@starci/eslint-canon-be 3.5.0 → 3.6.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/CHANGELOG.md +21 -0
- package/README.md +13 -2
- package/dist/ambient-id.d.ts +9 -0
- package/{ambient-id.mjs → dist/ambient-id.js} +43 -39
- package/dist/app-composition.d.ts +21 -0
- package/{app-composition.mjs → dist/app-composition.js} +396 -300
- package/dist/async-discipline.d.ts +9 -0
- package/dist/async-discipline.js +77 -0
- package/dist/authorization.d.ts +12 -0
- package/{authorization.mjs → dist/authorization.js} +53 -59
- package/dist/boundary-schema.d.ts +15 -0
- package/{boundary-schema.mjs → dist/boundary-schema.js} +120 -105
- package/dist/builders.d.ts +21 -0
- package/{builders.mjs → dist/builders.js} +162 -146
- package/dist/cli.d.ts +15 -0
- package/{cli.mjs → dist/cli.js} +97 -82
- package/dist/comments.d.ts +52 -0
- package/dist/comments.js +412 -0
- package/dist/config-owner.d.ts +24 -0
- package/{config-owner.mjs → dist/config-owner.js} +256 -219
- package/dist/connections.d.ts +12 -0
- package/{connections.mjs → dist/connections.js} +138 -140
- package/dist/cookies.d.ts +9 -0
- package/{cookies.mjs → dist/cookies.js} +58 -58
- package/dist/cqrs.d.ts +27 -0
- package/{cqrs.mjs → dist/cqrs.js} +341 -282
- package/dist/data-access.d.ts +50 -0
- package/{data-access.mjs → dist/data-access.js} +238 -243
- package/dist/default-deny.d.ts +15 -0
- package/{default-deny.mjs → dist/default-deny.js} +103 -88
- package/dist/e2e-flow.d.ts +25 -0
- package/{e2e-flow.mjs → dist/e2e-flow.js} +113 -112
- package/dist/edge-hardening.d.ts +10 -0
- package/dist/edge-hardening.js +173 -0
- package/dist/error-handling.d.ts +21 -0
- package/{error-handling.mjs → dist/error-handling.js} +289 -239
- package/dist/event-bus.d.ts +14 -0
- package/{event-bus.mjs → dist/event-bus.js} +146 -129
- package/dist/feature-thin.d.ts +12 -0
- package/{feature-thin.mjs → dist/feature-thin.js} +208 -191
- package/dist/function-budget.d.ts +7 -0
- package/{function-budget.mjs → dist/function-budget.js} +24 -27
- package/dist/health-ready.d.ts +10 -0
- package/dist/health-ready.js +703 -0
- package/dist/idempotency.d.ts +10 -0
- package/{idempotency.mjs → dist/idempotency.js} +296 -226
- package/dist/index.d.ts +54 -0
- package/{index.mjs → dist/index.js} +91 -109
- package/dist/infra-owner.d.ts +18 -0
- package/{infra-owner.mjs → dist/infra-owner.js} +58 -51
- package/dist/injection.d.ts +30 -0
- package/{injection.mjs → dist/injection.js} +397 -344
- package/dist/input-bounds.d.ts +15 -0
- package/{input-bounds.mjs → dist/input-bounds.js} +143 -132
- package/dist/jobs.d.ts +17 -0
- package/{jobs.mjs → dist/jobs.js} +116 -99
- package/dist/jwt-alg.d.ts +6 -0
- package/dist/jwt-alg.js +49 -0
- package/dist/lib/app-roles.d.ts +25 -0
- package/{lib/app-roles.mjs → dist/lib/app-roles.js} +15 -17
- package/dist/lib/ast.d.ts +40 -0
- package/dist/lib/ast.js +100 -0
- package/dist/lib/client-idempotency.d.ts +3 -0
- package/{lib/client-idempotency.mjs → dist/lib/client-idempotency.js} +316 -268
- package/dist/lib/config.d.ts +36 -0
- package/{lib/config.mjs → dist/lib/config.js} +24 -27
- package/dist/lib/db-writes.d.ts +29 -0
- package/{lib/db-writes.mjs → dist/lib/db-writes.js} +27 -27
- package/dist/lib/declared.d.ts +77 -0
- package/{lib/declared.mjs → dist/lib/declared.js} +83 -78
- package/dist/lib/doors.d.ts +50 -0
- package/{lib/doors.mjs → dist/lib/doors.js} +45 -50
- package/dist/lib/edition.d.ts +25 -0
- package/{lib/edition.mjs → dist/lib/edition.js} +15 -20
- package/dist/lib/entity-writes.d.ts +7 -0
- package/{lib/entity-writes.mjs → dist/lib/entity-writes.js} +31 -22
- package/dist/lib/hfs-view.d.ts +127 -0
- package/dist/lib/hfs-view.js +1 -0
- package/dist/lib/hfs.d.ts +34 -0
- package/{lib/hfs.mjs → dist/lib/hfs.js} +31 -29
- package/dist/lib/import-source.d.ts +63 -0
- package/dist/lib/import-source.js +134 -0
- package/dist/lib/path.d.ts +8 -0
- package/{lib/path.mjs → dist/lib/path.js} +4 -7
- package/dist/lib/persistence.d.ts +115 -0
- package/{lib/persistence.mjs → dist/lib/persistence.js} +55 -66
- package/dist/lib/ports.d.ts +70 -0
- package/{lib/ports.mjs → dist/lib/ports.js} +62 -66
- package/dist/lib/rule.d.ts +31 -0
- package/dist/lib/rule.js +2 -0
- package/dist/lib/runtime-root.d.ts +4 -0
- package/dist/lib/runtime-root.js +10 -0
- package/dist/lib/schema-values.d.ts +13 -0
- package/{lib/schema-values.mjs → dist/lib/schema-values.js} +67 -59
- package/dist/lib/specifier.d.ts +12 -0
- package/dist/lib/specifier.js +29 -0
- package/dist/lib/subject-values.d.ts +4 -0
- package/dist/lib/subject-values.js +61 -0
- package/dist/lib/transactions.d.ts +18 -0
- package/{lib/transactions.mjs → dist/lib/transactions.js} +17 -15
- package/dist/lib/transport-slots.d.ts +17 -0
- package/{lib/transport-slots.mjs → dist/lib/transport-slots.js} +2 -4
- package/dist/lib/types.d.ts +96 -0
- package/dist/lib/types.js +150 -0
- package/dist/lib/unit-spec.d.ts +48 -0
- package/{lib/unit-spec.mjs → dist/lib/unit-spec.js} +35 -44
- package/dist/lib/webhook-ack.d.ts +4 -0
- package/{lib/webhook-ack.mjs → dist/lib/webhook-ack.js} +78 -62
- package/dist/lib/webhook-handoff-inbox.d.ts +3 -0
- package/{lib/webhook-handoff-inbox.mjs → dist/lib/webhook-handoff-inbox.js} +195 -167
- package/dist/lib/webhook-handoff-intake.d.ts +4 -0
- package/{lib/webhook-handoff-intake.mjs → dist/lib/webhook-handoff-intake.js} +125 -102
- package/dist/lib/webhook-handoff.d.ts +15 -0
- package/{lib/webhook-handoff.mjs → dist/lib/webhook-handoff.js} +107 -100
- package/dist/lib/webhook-verifiers.d.ts +20 -0
- package/{lib/webhook-verifiers.mjs → dist/lib/webhook-verifiers.js} +108 -104
- package/dist/lib/why.d.ts +9 -0
- package/{lib/why.mjs → dist/lib/why.js} +6 -6
- package/dist/log-safety.d.ts +20 -0
- package/dist/log-safety.js +308 -0
- package/dist/module-layering.d.ts +42 -0
- package/dist/module-layering.js +257 -0
- package/dist/module-shape.d.ts +47 -0
- package/{module-shape.mjs → dist/module-shape.js} +278 -236
- package/dist/naming.d.ts +49 -0
- package/dist/naming.js +246 -0
- package/dist/observability.d.ts +25 -0
- package/dist/observability.js +245 -0
- package/dist/operations.d.ts +23 -0
- package/{operations.mjs → dist/operations.js} +410 -332
- package/dist/project-graph.d.ts +9 -0
- package/{project-graph.mjs → dist/project-graph.js} +8 -13
- package/dist/projections.d.ts +11 -0
- package/{projections.mjs → dist/projections.js} +60 -57
- package/dist/query-safety.d.ts +21 -0
- package/{query-safety.mjs → dist/query-safety.js} +92 -108
- package/dist/realtime.d.ts +15 -0
- package/{realtime.mjs → dist/realtime.js} +108 -106
- package/dist/resilience.d.ts +15 -0
- package/dist/resilience.js +319 -0
- package/dist/schema-authority.d.ts +15 -0
- package/{schema-authority.mjs → dist/schema-authority.js} +256 -220
- package/dist/service-deps.d.ts +17 -0
- package/{service-deps.mjs → dist/service-deps.js} +133 -130
- package/dist/service-isolation.d.ts +8 -0
- package/dist/service-isolation.js +76 -0
- package/dist/size-budget.d.ts +9 -0
- package/{size-budget.mjs → dist/size-budget.js} +27 -27
- package/dist/sonar-parity.d.ts +5 -0
- package/{sonar-parity.mjs → dist/sonar-parity.js} +7 -7
- package/dist/spec-no-skip.d.ts +9 -0
- package/dist/spec-no-skip.js +81 -0
- package/dist/spec-quality.d.ts +10 -0
- package/{spec-quality.mjs → dist/spec-quality.js} +103 -87
- package/dist/suppression.d.ts +26 -0
- package/{suppression.mjs → dist/suppression.js} +30 -45
- package/dist/temporal.d.ts +9 -0
- package/{temporal.mjs → dist/temporal.js} +75 -65
- package/dist/test-world.d.ts +28 -0
- package/{test-world.mjs → dist/test-world.js} +102 -83
- package/dist/testing.d.ts +51 -0
- package/dist/testing.js +368 -0
- package/dist/third-party-owner.d.ts +8 -0
- package/{third-party-owner.mjs → dist/third-party-owner.js} +105 -91
- package/dist/transport.d.ts +24 -0
- package/{transport.mjs → dist/transport.js} +279 -240
- package/dist/type-safety.d.ts +25 -0
- package/dist/type-safety.js +297 -0
- package/dist/unit-spec.d.ts +30 -0
- package/{unit-spec.mjs → dist/unit-spec.js} +473 -399
- package/dist/uploads.d.ts +9 -0
- package/{uploads.mjs → dist/uploads.js} +62 -54
- package/dist/user-copy.d.ts +9 -0
- package/{user-copy.mjs → dist/user-copy.js} +76 -67
- package/dist/webhooks.d.ts +16 -0
- package/{webhooks.mjs → dist/webhooks.js} +243 -231
- package/package.json +23 -8
- package/runtime/knowledge/hfs/canon-pins.yaml +18 -11
- package/runtime/scripts/hfs/repo-identity.mjs +5 -4
- package/async-discipline.mjs +0 -83
- package/comments.mjs +0 -416
- package/edge-hardening.mjs +0 -139
- package/health-ready.mjs +0 -539
- package/jwt-alg.mjs +0 -45
- package/lib/ast.mjs +0 -88
- package/lib/import-source.mjs +0 -104
- package/lib/specifier.mjs +0 -27
- package/lib/subject-values.mjs +0 -55
- package/lib/types.mjs +0 -133
- package/log-safety.mjs +0 -303
- package/module-layering.mjs +0 -270
- package/naming.mjs +0 -251
- package/observability.mjs +0 -241
- package/resilience.mjs +0 -304
- package/service-isolation.mjs +0 -75
- package/spec-no-skip.mjs +0 -85
- package/testing.mjs +0 -384
- package/type-safety.mjs +0 -323
|
@@ -24,25 +24,20 @@
|
|
|
24
24
|
*
|
|
25
25
|
* No test lane is exempt: a spec builds its `EnvSource` from a literal record and never touches the process environment.
|
|
26
26
|
*/
|
|
27
|
-
import ts from "typescript"
|
|
28
|
-
import { APP_ENV_ROLE, appRoleOf } from "./lib/app-roles.
|
|
29
|
-
import { keyName, staticText, walk, wordsOf } from "./lib/ast.
|
|
30
|
-
import { isOwnedBy, isOwnedType, originsOf } from "./lib/declared.
|
|
31
|
-
import { hfsOf, inTestWorld } from "./lib/hfs.
|
|
32
|
-
import { isDeclarationFile, normalizePath } from "./lib/path.
|
|
33
|
-
import { moduleOf, originsOfType, typed } from "./lib/types.
|
|
34
|
-
|
|
27
|
+
import ts from "typescript";
|
|
28
|
+
import { APP_ENV_ROLE, appRoleOf } from "./lib/app-roles.js";
|
|
29
|
+
import { keyName, staticText, walk, wordsOf } from "./lib/ast.js";
|
|
30
|
+
import { isOwnedBy, isOwnedType, originsOf } from "./lib/declared.js";
|
|
31
|
+
import { hfsOf, inTestWorld } from "./lib/hfs.js";
|
|
32
|
+
import { isDeclarationFile, normalizePath } from "./lib/path.js";
|
|
33
|
+
import { moduleOf, originsOfType, typed } from "./lib/types.js";
|
|
35
34
|
/** The test composition root (slot `be.tests.world`): it composes app options like `main.ts` and hands run state to jest workers through the environment. */
|
|
36
|
-
const isTestWorld = inTestWorld
|
|
37
|
-
|
|
38
|
-
const PROCESS_MODULES = new Set(["process", "node:process"])
|
|
39
|
-
|
|
35
|
+
const isTestWorld = inTestWorld;
|
|
36
|
+
const PROCESS_MODULES = new Set(["process", "node:process"]);
|
|
40
37
|
/** `@nestjs/config`, `dotenv` and their subpaths. */
|
|
41
|
-
const isConfigPackage = (source) => /^(?:@nestjs\/config|dotenv)(?:\/|$)/.test(source)
|
|
42
|
-
|
|
38
|
+
const isConfigPackage = (source) => /^(?:@nestjs\/config|dotenv)(?:\/|$)/.test(source);
|
|
43
39
|
/** True when the property of a member expression spells `env`. */
|
|
44
|
-
const spellsEnv = (node) => (node.computed ? staticText(node.property) === "env" : keyName(node.property) === "env")
|
|
45
|
-
|
|
40
|
+
const spellsEnv = (node) => (node.computed ? staticText(node.property) === "env" : keyName(node.property) === "env");
|
|
46
41
|
/** Only EnvSource, the app bootstrap roles and the test world read the process environment. */
|
|
47
42
|
export const noDirectEnvRead = {
|
|
48
43
|
meta: {
|
|
@@ -56,149 +51,174 @@ export const noDirectEnvRead = {
|
|
|
56
51
|
},
|
|
57
52
|
},
|
|
58
53
|
create(context) {
|
|
59
|
-
const filename = normalizePath(context.filename || context.getFilename())
|
|
60
|
-
if (isDeclarationFile(filename))
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
54
|
+
const filename = normalizePath(context.filename || context.getFilename());
|
|
55
|
+
if (isDeclarationFile(filename))
|
|
56
|
+
return {};
|
|
57
|
+
const hfs = hfsOf(context);
|
|
58
|
+
const inConfigOwner = isOwnedBy(hfs, filename, "platform", "config");
|
|
59
|
+
let declaresEnvSource = false;
|
|
64
60
|
const variableOf = (identifier) => {
|
|
65
61
|
for (let scope = context.sourceCode.getScope(identifier); scope; scope = scope.upper) {
|
|
66
|
-
const variable = scope.set.get(identifier.name)
|
|
67
|
-
if (variable)
|
|
62
|
+
const variable = scope.set.get(identifier.name);
|
|
63
|
+
if (variable)
|
|
64
|
+
return variable;
|
|
68
65
|
}
|
|
69
|
-
return null
|
|
70
|
-
}
|
|
71
|
-
const isGlobal = (node) => node?.type === "Identifier" && ["globalThis", "global"].includes(node.name) && !variableOf(node)?.defs.length
|
|
66
|
+
return null;
|
|
67
|
+
};
|
|
68
|
+
const isGlobal = (node) => node?.type === "Identifier" && ["globalThis", "global"].includes(node.name) && !variableOf(node)?.defs.length;
|
|
72
69
|
// Resolve aliases by their lexical binding: an identically named local or parameter is not Node's process.
|
|
73
70
|
const isProcess = (node, seen = new Set()) => {
|
|
74
|
-
if (!node)
|
|
75
|
-
|
|
71
|
+
if (!node)
|
|
72
|
+
return false;
|
|
73
|
+
if (node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "TSSatisfiesExpression" || node.type === "ChainExpression")
|
|
74
|
+
return isProcess(node.expression, seen);
|
|
76
75
|
if (node.type === "MemberExpression") {
|
|
77
|
-
return isGlobal(node.object) && (node.computed ? staticText(node.property) : keyName(node.property)) === "process"
|
|
76
|
+
return isGlobal(node.object) && (node.computed ? staticText(node.property) : keyName(node.property)) === "process";
|
|
78
77
|
}
|
|
79
|
-
if (node.type !== "Identifier")
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
78
|
+
if (node.type !== "Identifier")
|
|
79
|
+
return false;
|
|
80
|
+
const variable = variableOf(node);
|
|
81
|
+
if (!variable?.defs.length)
|
|
82
|
+
return node.name === "process";
|
|
83
|
+
if (seen.has(node))
|
|
84
|
+
return false;
|
|
85
|
+
seen.add(node);
|
|
84
86
|
return variable.defs.some((definition) => {
|
|
85
87
|
if (definition.type === "ImportBinding") {
|
|
86
|
-
const specifier = definition.node
|
|
87
|
-
return PROCESS_MODULES.has(definition.parent.source.value)
|
|
88
|
-
&& (specifier.type !== "ImportSpecifier" || keyName(specifier.imported) === "default")
|
|
88
|
+
const specifier = definition.node;
|
|
89
|
+
return definition.parent.type === "ImportDeclaration" && PROCESS_MODULES.has(definition.parent.source.value)
|
|
90
|
+
&& (specifier.type !== "ImportSpecifier" || keyName(specifier.imported) === "default");
|
|
89
91
|
}
|
|
90
|
-
if (definition.type !== "Variable")
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
if (definition.type !== "Variable")
|
|
93
|
+
return false;
|
|
94
|
+
const readScope = context.sourceCode.getScope(node).variableScope;
|
|
95
|
+
const write = variable.references.filter((reference) => {
|
|
96
|
+
if (!reference.isWrite() || ![readScope, variable.scope.variableScope].includes(reference.from.variableScope))
|
|
97
|
+
return false;
|
|
98
|
+
const writeEnd = reference.writeExpr?.range[1];
|
|
99
|
+
return writeEnd !== undefined && writeEnd <= node.range[0];
|
|
100
|
+
})
|
|
101
|
+
.sort((left, right) => right.identifier.range[0] - left.identifier.range[0])[0];
|
|
96
102
|
// A const captured by a function keeps its initializer even when the function is declared first.
|
|
97
|
-
const source = write?.writeExpr ?? (definition.parent.kind === "const" ? definition.node.init : null)
|
|
98
|
-
if (!source)
|
|
99
|
-
|
|
100
|
-
const
|
|
103
|
+
const source = write?.writeExpr ?? (definition.parent.kind === "const" ? definition.node.init : null);
|
|
104
|
+
if (!source)
|
|
105
|
+
return false;
|
|
106
|
+
const identifier = write?.identifier ?? definition.name;
|
|
107
|
+
const parent = identifier.parent;
|
|
101
108
|
if (parent.type === "Property" && parent.value === identifier && parent.parent.type === "ObjectPattern") {
|
|
102
|
-
return isGlobal(source) && (parent.computed ? staticText(parent.key) : keyName(parent.key)) === "process"
|
|
109
|
+
return isGlobal(source) && (parent.computed ? staticText(parent.key) : keyName(parent.key)) === "process";
|
|
103
110
|
}
|
|
104
|
-
return isProcess(source, seen)
|
|
105
|
-
})
|
|
106
|
-
}
|
|
107
|
-
const isEnvSourceFile = () => inConfigOwner && declaresEnvSource
|
|
108
|
-
const inWorld = isTestWorld(hfs, filename)
|
|
109
|
-
const appRole = appRoleOf(hfs, filename)?.entry
|
|
110
|
-
const inAppEntry = appRole === "main.ts" || appRole === APP_ENV_ROLE
|
|
111
|
+
return isProcess(source, seen);
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
const isEnvSourceFile = () => inConfigOwner && declaresEnvSource;
|
|
115
|
+
const inWorld = isTestWorld(hfs, filename);
|
|
116
|
+
const appRole = appRoleOf(hfs, filename)?.entry;
|
|
117
|
+
const inAppEntry = appRole === "main.ts" || appRole === APP_ENV_ROLE;
|
|
111
118
|
const reportEnv = (node) => {
|
|
112
|
-
if (!isEnvSourceFile() && !inWorld && !inAppEntry)
|
|
113
|
-
|
|
119
|
+
if (!isEnvSourceFile() && !inWorld && !inAppEntry)
|
|
120
|
+
context.report({ node, messageId: "env" });
|
|
121
|
+
};
|
|
114
122
|
const reportSource = (node, source) => {
|
|
115
|
-
if (isConfigPackage(source))
|
|
116
|
-
|
|
123
|
+
if (isConfigPackage(source))
|
|
124
|
+
context.report({ node, messageId: "package", data: { source } });
|
|
125
|
+
};
|
|
117
126
|
return {
|
|
118
127
|
Program(program) {
|
|
119
128
|
declaresEnvSource = program.body.some((statement) => {
|
|
120
|
-
const declaration = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" ? statement.declaration : statement
|
|
121
|
-
return declaration?.type === "ClassDeclaration" && declaration.id?.name === "EnvSource"
|
|
122
|
-
})
|
|
129
|
+
const declaration = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" ? statement.declaration : statement;
|
|
130
|
+
return declaration?.type === "ClassDeclaration" && declaration.id?.name === "EnvSource";
|
|
131
|
+
});
|
|
123
132
|
},
|
|
124
133
|
ImportDeclaration(node) {
|
|
125
|
-
const source = String(node.source.value)
|
|
126
|
-
reportSource(node, source)
|
|
127
|
-
if (!PROCESS_MODULES.has(source))
|
|
134
|
+
const source = String(node.source.value);
|
|
135
|
+
reportSource(node, source);
|
|
136
|
+
if (!PROCESS_MODULES.has(source))
|
|
137
|
+
return;
|
|
128
138
|
for (const specifier of node.specifiers) {
|
|
129
|
-
if (specifier.type === "ImportSpecifier" && (specifier.imported.name
|
|
139
|
+
if (specifier.type === "ImportSpecifier" && (specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value) === "env")
|
|
140
|
+
reportEnv(specifier);
|
|
130
141
|
}
|
|
131
142
|
},
|
|
132
143
|
ImportExpression(node) {
|
|
133
|
-
const source = staticText(node.source)
|
|
134
|
-
if (source !== null)
|
|
144
|
+
const source = staticText(node.source);
|
|
145
|
+
if (source !== null)
|
|
146
|
+
reportSource(node, source);
|
|
135
147
|
},
|
|
136
148
|
MemberExpression(node) {
|
|
137
|
-
if (isProcess(node.object) && spellsEnv(node))
|
|
149
|
+
if (isProcess(node.object) && spellsEnv(node))
|
|
150
|
+
reportEnv(node);
|
|
138
151
|
},
|
|
139
152
|
VariableDeclarator(node) {
|
|
140
|
-
if (!node.init || !isProcess(node.init) || node.id.type !== "ObjectPattern")
|
|
141
|
-
|
|
153
|
+
if (!node.init || !isProcess(node.init) || node.id.type !== "ObjectPattern")
|
|
154
|
+
return;
|
|
155
|
+
if (node.id.properties.some((property) => property.type === "Property" && (property.computed ? staticText(property.key) : keyName(property.key)) === "env"))
|
|
156
|
+
reportEnv(node);
|
|
142
157
|
},
|
|
143
158
|
AssignmentExpression(node) {
|
|
144
|
-
if (node.operator !== "=" || node.left.type !== "ObjectPattern" || !isProcess(node.right))
|
|
145
|
-
|
|
159
|
+
if (node.operator !== "=" || node.left.type !== "ObjectPattern" || !isProcess(node.right))
|
|
160
|
+
return;
|
|
161
|
+
if (node.left.properties.some((property) => property.type === "Property" && (property.computed ? staticText(property.key) : keyName(property.key)) === "env"))
|
|
162
|
+
reportEnv(node);
|
|
146
163
|
},
|
|
147
164
|
CallExpression(node) {
|
|
148
|
-
const callee = node.callee
|
|
165
|
+
const callee = node.callee;
|
|
149
166
|
if (callee.type === "Identifier" && callee.name === "require") {
|
|
150
|
-
const source = staticText(node.arguments[0])
|
|
151
|
-
if (source !== null)
|
|
167
|
+
const source = staticText(node.arguments[0]);
|
|
168
|
+
if (source !== null)
|
|
169
|
+
reportSource(node, source);
|
|
152
170
|
}
|
|
153
|
-
if (callee.type !== "MemberExpression")
|
|
171
|
+
if (callee.type !== "MemberExpression")
|
|
172
|
+
return;
|
|
154
173
|
if (callee.object.type === "Identifier" && callee.object.name === "Reflect" && keyName(callee.property) === "get") {
|
|
155
|
-
if (node.arguments[0] && isProcess(node.arguments[0]) && staticText(node.arguments[1]) === "env")
|
|
174
|
+
if (node.arguments[0] && isProcess(node.arguments[0]) && staticText(node.arguments[1]) === "env")
|
|
175
|
+
reportEnv(node);
|
|
156
176
|
}
|
|
157
177
|
if (["join", "resolve"].includes(keyName(callee.property) ?? "") && !isEnvSourceFile()) {
|
|
158
|
-
let cwd = false
|
|
178
|
+
let cwd = false;
|
|
159
179
|
walk(node, (child) => {
|
|
160
|
-
if (child.type === "CallExpression" && child.callee.type === "MemberExpression" && isProcess(child.callee.object) && keyName(child.callee.property) === "cwd")
|
|
161
|
-
|
|
162
|
-
|
|
180
|
+
if (child.type === "CallExpression" && child.callee.type === "MemberExpression" && isProcess(child.callee.object) && keyName(child.callee.property) === "cwd")
|
|
181
|
+
cwd = true;
|
|
182
|
+
});
|
|
183
|
+
if (!cwd)
|
|
184
|
+
return;
|
|
163
185
|
for (const argument of node.arguments) {
|
|
164
|
-
const text = staticText(argument)
|
|
165
|
-
const segment = text === null ? null : text.split(/[\\/]/).find((part) => part === "src" || part === ".starcistacks")
|
|
166
|
-
if (segment)
|
|
186
|
+
const text = staticText(argument);
|
|
187
|
+
const segment = text === null ? null : text.split(/[\\/]/).find((part) => part === "src" || part === ".starcistacks");
|
|
188
|
+
if (segment)
|
|
189
|
+
context.report({ node, messageId: "cwdPath", data: { segment } });
|
|
167
190
|
}
|
|
168
191
|
}
|
|
169
192
|
},
|
|
170
|
-
}
|
|
193
|
+
};
|
|
171
194
|
},
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
const baseOf = (file) => normalizePath(file).split("/").at(-1) ?? ""
|
|
179
|
-
|
|
195
|
+
};
|
|
196
|
+
const CONFIG_SUFFIX = ".config.ts";
|
|
197
|
+
const OPTIONS_SUFFIX = ".options.ts";
|
|
198
|
+
const CONFIG_SPEC_SUFFIX = ".config.spec.ts";
|
|
199
|
+
const baseOf = (file) => normalizePath(file).split("/").at(-1) ?? "";
|
|
180
200
|
/** A file in a slot of the repository whose role is `<c>.config.ts` (a file with the suffix that no slot claims is not one). */
|
|
181
|
-
const isConfigFile = (hfs, file) => baseOf(file).endsWith(CONFIG_SUFFIX) && hfs.slotOf(file) !== null
|
|
182
|
-
|
|
201
|
+
const isConfigFile = (hfs, file) => baseOf(file).endsWith(CONFIG_SUFFIX) && hfs.slotOf(file) !== null;
|
|
183
202
|
/** A file in a slot of the repository whose role is `<c>.options.ts`. */
|
|
184
|
-
const isOptionsFile = (hfs, file) => baseOf(file).endsWith(OPTIONS_SUFFIX) && hfs.slotOf(file) !== null
|
|
185
|
-
|
|
203
|
+
const isOptionsFile = (hfs, file) => baseOf(file).endsWith(OPTIONS_SUFFIX) && hfs.slotOf(file) !== null;
|
|
186
204
|
/** The declaration of a plain function (declaration, or arrow/function expression bound to a variable), else null: a method is not a getter. */
|
|
187
205
|
const functionDeclarationOf = (declaration) => {
|
|
188
|
-
if (!declaration)
|
|
189
|
-
|
|
190
|
-
if (
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
206
|
+
if (!declaration)
|
|
207
|
+
return null;
|
|
208
|
+
if (ts.isFunctionDeclaration(declaration))
|
|
209
|
+
return declaration;
|
|
210
|
+
if ((ts.isArrowFunction(declaration) || ts.isFunctionExpression(declaration)) && ts.isVariableDeclaration(declaration.parent))
|
|
211
|
+
return declaration;
|
|
212
|
+
return null;
|
|
213
|
+
};
|
|
194
214
|
/** True when the node is evaluated when the module loads: no function, method or class member body encloses it. */
|
|
195
215
|
const isModuleScope = (node) => {
|
|
196
216
|
for (let parent = node.parent; parent; parent = parent.parent) {
|
|
197
|
-
if (/Function|MethodDefinition|PropertyDefinition|StaticBlock/.test(parent.type))
|
|
217
|
+
if (/Function|MethodDefinition|PropertyDefinition|StaticBlock/.test(parent.type))
|
|
218
|
+
return false;
|
|
198
219
|
}
|
|
199
|
-
return true
|
|
200
|
-
}
|
|
201
|
-
|
|
220
|
+
return true;
|
|
221
|
+
};
|
|
202
222
|
/** Config is parsed once, in `main.ts` or its app's env file; other app roles do not read the environment. */
|
|
203
223
|
export const configParsedInMain = {
|
|
204
224
|
meta: {
|
|
@@ -211,54 +231,60 @@ export const configParsedInMain = {
|
|
|
211
231
|
},
|
|
212
232
|
},
|
|
213
233
|
create(context) {
|
|
214
|
-
const filename = normalizePath(context.filename || context.getFilename())
|
|
215
|
-
if (isDeclarationFile(filename))
|
|
216
|
-
|
|
217
|
-
const
|
|
234
|
+
const filename = normalizePath(context.filename || context.getFilename());
|
|
235
|
+
if (isDeclarationFile(filename))
|
|
236
|
+
return {};
|
|
237
|
+
const hfs = hfsOf(context);
|
|
238
|
+
const slot = hfs.slotOf(filename) ?? "";
|
|
218
239
|
// The app entry and its matching env file parse options; options files and composition groups only consume them.
|
|
219
240
|
// The test world and provider contract specs parse the declared sandbox keys to register their modules.
|
|
220
|
-
const inApp = slot.startsWith("be.app.")
|
|
221
|
-
const role = appRoleOf(hfs, filename)?.entry
|
|
222
|
-
const isEntry = role === "main.ts" || role === APP_ENV_ROLE
|
|
223
|
-
const isComposingTest = isTestWorld(hfs, filename) || slot === "be.tests.contract"
|
|
224
|
-
const isOwnSpec = !inApp && baseOf(filename).endsWith(CONFIG_SPEC_SUFFIX)
|
|
225
|
-
if (isEntry || isComposingTest || isOwnSpec)
|
|
226
|
-
|
|
241
|
+
const inApp = slot.startsWith("be.app.");
|
|
242
|
+
const role = appRoleOf(hfs, filename)?.entry;
|
|
243
|
+
const isEntry = role === "main.ts" || role === APP_ENV_ROLE;
|
|
244
|
+
const isComposingTest = isTestWorld(hfs, filename) || slot === "be.tests.contract";
|
|
245
|
+
const isOwnSpec = !inApp && baseOf(filename).endsWith(CONFIG_SPEC_SUFFIX);
|
|
246
|
+
if (isEntry || isComposingTest || isOwnSpec)
|
|
247
|
+
return {};
|
|
248
|
+
const { checker, toTs } = typed(context);
|
|
227
249
|
return {
|
|
228
250
|
CallExpression(node) {
|
|
229
|
-
const tsCall = toTs(node)
|
|
230
|
-
if (!tsCall)
|
|
231
|
-
|
|
232
|
-
const
|
|
251
|
+
const tsCall = toTs(node);
|
|
252
|
+
if (!tsCall)
|
|
253
|
+
return;
|
|
254
|
+
const signature = checker.getResolvedSignature(tsCall);
|
|
255
|
+
const resolvedDeclaration = signature?.declaration;
|
|
233
256
|
if (inApp && resolvedDeclaration && ts.isMethodDeclaration(resolvedDeclaration)
|
|
234
257
|
&& ts.isClassDeclaration(resolvedDeclaration.parent) && resolvedDeclaration.parent.name?.text === "EnvSource") {
|
|
235
|
-
const declaredIn = normalizePath(resolvedDeclaration.getSourceFile().fileName)
|
|
258
|
+
const declaredIn = normalizePath(resolvedDeclaration.getSourceFile().fileName);
|
|
236
259
|
if (isOwnedBy(hfs, declaredIn, "platform", "config")) {
|
|
237
|
-
context.report({ node, messageId: "parsed", data: { name: context.sourceCode.getText(node.callee), file: baseOf(declaredIn) } })
|
|
238
|
-
return
|
|
260
|
+
context.report({ node, messageId: "parsed", data: { name: context.sourceCode.getText(node.callee), file: baseOf(declaredIn) } });
|
|
261
|
+
return;
|
|
239
262
|
}
|
|
240
263
|
}
|
|
241
|
-
const declaration = functionDeclarationOf(resolvedDeclaration)
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
264
|
+
const declaration = functionDeclarationOf(resolvedDeclaration);
|
|
265
|
+
// a declaration comes from a signature, so `!signature` adds no case
|
|
266
|
+
if (!declaration || !signature)
|
|
267
|
+
return;
|
|
268
|
+
const declaredIn = normalizePath(declaration.getSourceFile().fileName);
|
|
269
|
+
const name = context.sourceCode.getText(node.callee);
|
|
245
270
|
if (isConfigFile(hfs, declaredIn) || appRoleOf(hfs, declaredIn)?.entry === APP_ENV_ROLE) {
|
|
246
|
-
if (declaredIn !== filename)
|
|
247
|
-
|
|
271
|
+
if (declaredIn !== filename)
|
|
272
|
+
context.report({ node, messageId: "parsed", data: { name, file: baseOf(declaredIn) } });
|
|
273
|
+
return;
|
|
248
274
|
}
|
|
249
|
-
if (!isModuleScope(node))
|
|
250
|
-
|
|
251
|
-
|
|
275
|
+
if (!isModuleScope(node))
|
|
276
|
+
return;
|
|
277
|
+
const returned = originsOfType(checker, checker.getReturnTypeOfSignature(signature));
|
|
278
|
+
if (returned.some((origin) => isOptionsFile(hfs, origin.file)))
|
|
279
|
+
context.report({ node, messageId: "moduleScope", data: { name } });
|
|
252
280
|
},
|
|
253
|
-
}
|
|
281
|
+
};
|
|
254
282
|
},
|
|
255
|
-
}
|
|
256
|
-
|
|
283
|
+
};
|
|
257
284
|
/** The brand classes of `platform/config` a default must never be given to. */
|
|
258
|
-
const BRANDS = new Set(["Secret", "Url"])
|
|
259
|
-
const SECRET_READERS = new Set(["secret", "url", "host"])
|
|
260
|
-
const DEFAULT_LITERAL = /^(?:localhost|127\.0\.0\.1|0\.0\.0\.0|https?:\/\/.*)?$/i
|
|
261
|
-
|
|
285
|
+
const BRANDS = new Set(["Secret", "Url"]);
|
|
286
|
+
const SECRET_READERS = new Set(["secret", "url", "host"]);
|
|
287
|
+
const DEFAULT_LITERAL = /^(?:localhost|127\.0\.0\.1|0\.0\.0\.0|https?:\/\/.*)?$/i;
|
|
262
288
|
/** No secret or URL value has a default of any kind: a missing value stops the boot. */
|
|
263
289
|
export const noSecretDefault = {
|
|
264
290
|
meta: {
|
|
@@ -272,56 +298,65 @@ export const noSecretDefault = {
|
|
|
272
298
|
},
|
|
273
299
|
},
|
|
274
300
|
create(context) {
|
|
275
|
-
const filename = normalizePath(context.filename || context.getFilename())
|
|
276
|
-
if (isDeclarationFile(filename))
|
|
277
|
-
|
|
301
|
+
const filename = normalizePath(context.filename || context.getFilename());
|
|
302
|
+
if (isDeclarationFile(filename))
|
|
303
|
+
return {};
|
|
304
|
+
const hfs = hfsOf(context);
|
|
278
305
|
/** True when the node's type is (or contains) `Secret` or `Url` as `platform/config` declares them. */
|
|
279
|
-
const isBrand = (node) => originsOf(context, node).some((origin) => BRANDS.has(origin.name) && isOwnedBy(hfs, origin.file, "platform", "config"))
|
|
280
|
-
const isEnvSource = (node) => originsOf(context, node).some((origin) => origin.name === "EnvSource" && isOwnedBy(hfs, origin.file, "platform", "config"))
|
|
306
|
+
const isBrand = (node) => originsOf(context, node).some((origin) => BRANDS.has(origin.name) && isOwnedBy(hfs, origin.file, "platform", "config"));
|
|
307
|
+
const isEnvSource = (node) => originsOf(context, node).some((origin) => origin.name === "EnvSource" && isOwnedBy(hfs, origin.file, "platform", "config"));
|
|
281
308
|
const checkFallback = (node, operator, left) => {
|
|
282
|
-
if (isBrand(left))
|
|
283
|
-
|
|
309
|
+
if (isBrand(left))
|
|
310
|
+
context.report({ node, messageId: "fallback", data: { operator } });
|
|
311
|
+
};
|
|
284
312
|
return {
|
|
285
313
|
LogicalExpression(node) {
|
|
286
|
-
if (node.operator === "??" || node.operator === "||")
|
|
314
|
+
if (node.operator === "??" || node.operator === "||")
|
|
315
|
+
checkFallback(node, node.operator, node.left);
|
|
287
316
|
},
|
|
288
317
|
AssignmentExpression(node) {
|
|
289
|
-
if (node.operator === "??=" || node.operator === "||=")
|
|
318
|
+
if (node.operator === "??=" || node.operator === "||=")
|
|
319
|
+
checkFallback(node, node.operator, node.left);
|
|
290
320
|
},
|
|
291
321
|
CallExpression(node) {
|
|
292
|
-
if (node.arguments.length < 2)
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
|
|
322
|
+
if (node.arguments.length < 2)
|
|
323
|
+
return;
|
|
324
|
+
const defaultArgument = node.arguments[1];
|
|
325
|
+
if (defaultArgument === undefined)
|
|
326
|
+
return;
|
|
327
|
+
const callee = node.callee;
|
|
328
|
+
const method = callee.type === "MemberExpression" && !callee.computed ? keyName(callee.property) : null;
|
|
329
|
+
// a method name comes only from a member expression, so the type test adds no case
|
|
330
|
+
const onEnvSource = method !== null && callee.type === "MemberExpression" && isEnvSource(callee.object);
|
|
296
331
|
if (onEnvSource && (SECRET_READERS.has(method) || isBrand(node))) {
|
|
297
|
-
context.report({ node:
|
|
298
|
-
return
|
|
332
|
+
context.report({ node: defaultArgument, messageId: "argument", data: { method } });
|
|
333
|
+
return;
|
|
299
334
|
}
|
|
300
|
-
if (!isBrand(node))
|
|
335
|
+
if (!isBrand(node))
|
|
336
|
+
return;
|
|
301
337
|
const literal = node.arguments.slice(1).find((argument) => {
|
|
302
|
-
const text = staticText(argument)
|
|
303
|
-
return text !== null && DEFAULT_LITERAL.test(text)
|
|
304
|
-
})
|
|
305
|
-
if (literal)
|
|
338
|
+
const text = staticText(argument);
|
|
339
|
+
return text !== null && DEFAULT_LITERAL.test(text);
|
|
340
|
+
});
|
|
341
|
+
if (literal)
|
|
342
|
+
context.report({ node: literal, messageId: "literal" });
|
|
306
343
|
},
|
|
307
|
-
}
|
|
344
|
+
};
|
|
308
345
|
},
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
const
|
|
313
|
-
const NOT_A_VALUE_WORDS = new Set(["type", "kind", "length", "count", "ttl", "name", "prefix", "header", "scheme", "field", "path", "regex", "pattern"])
|
|
314
|
-
|
|
346
|
+
};
|
|
347
|
+
const SECRET_COMPARE_WORDS = new Set(["secret", "password", "passwd", "passphrase", "token", "signature", "hmac", "credential", "credentials", "apikey", "authorization"]);
|
|
348
|
+
const KEY_PREFIXES = new Set(["api", "secret", "private", "access", "signing", "encryption", "master", "auth", "jwt", "session"]);
|
|
349
|
+
const NOT_A_VALUE_WORDS = new Set(["type", "kind", "length", "count", "ttl", "name", "prefix", "header", "scheme", "field", "path", "regex", "pattern"]);
|
|
315
350
|
/** The identifier or property a comparison operand ends in, else null. */
|
|
316
351
|
const operandName = (node) => {
|
|
317
|
-
if (node.type === "Identifier")
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
352
|
+
if (node.type === "Identifier")
|
|
353
|
+
return node.name;
|
|
354
|
+
if (node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier")
|
|
355
|
+
return node.property.name;
|
|
356
|
+
return null;
|
|
357
|
+
};
|
|
322
358
|
/** Words before the last one that make a token a counter or a cursor, not a credential. */
|
|
323
|
-
const NOT_A_CREDENTIAL_QUALIFIERS = new Set(["fencing", "idempotency", "cursor", "page", "next", "continuation", "pagination", "sync", "csrf"])
|
|
324
|
-
|
|
359
|
+
const NOT_A_CREDENTIAL_QUALIFIERS = new Set(["fencing", "idempotency", "cursor", "page", "next", "continuation", "pagination", "sync", "csrf"]);
|
|
325
360
|
/**
|
|
326
361
|
* Whether a value's own name says it IS a credential: its last word is one (`password`, `accessToken`, `clientSecret`,
|
|
327
362
|
* `signingKey`), unless the name is an UPPER_SNAKE constant naming a key or a counter or cursor qualifies it. Shared by the
|
|
@@ -329,41 +364,42 @@ const NOT_A_CREDENTIAL_QUALIFIERS = new Set(["fencing", "idempotency", "cursor",
|
|
|
329
364
|
*/
|
|
330
365
|
export const isCredentialName = (name) => {
|
|
331
366
|
// an UPPER_SNAKE name is a constant naming a key, not the value it names
|
|
332
|
-
if (/^[A-Z][A-Z0-9_]*$/.test(name))
|
|
333
|
-
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
367
|
+
if (/^[A-Z][A-Z0-9_]*$/.test(name))
|
|
368
|
+
return false;
|
|
369
|
+
const words = wordsOf(name);
|
|
370
|
+
const last = words.at(-1);
|
|
371
|
+
if (!last || NOT_A_VALUE_WORDS.has(last) || words.some((word) => NOT_A_CREDENTIAL_QUALIFIERS.has(word)))
|
|
372
|
+
return false;
|
|
373
|
+
const prefix = words.at(-2);
|
|
374
|
+
return SECRET_COMPARE_WORDS.has(last) || (last === "key" && words.length > 1 && prefix !== undefined && KEY_PREFIXES.has(prefix));
|
|
375
|
+
};
|
|
339
376
|
/** An emptiness or presence check reveals nothing a timing attack could use. */
|
|
340
|
-
const isPresenceOperand = (node) =>
|
|
341
|
-
(node.type === "Literal" && (node.value === null || node.value === "" || typeof node.value === "boolean")) ||
|
|
377
|
+
const isPresenceOperand = (node) => (node.type === "Literal" && (node.value === null || node.value === "" || typeof node.value === "boolean")) ||
|
|
342
378
|
(node.type === "Identifier" && node.name === "undefined") ||
|
|
343
|
-
(node.type === "UnaryExpression" && node.operator === "typeof")
|
|
344
|
-
|
|
379
|
+
(node.type === "UnaryExpression" && node.operator === "typeof");
|
|
345
380
|
/** A value typed by the `Secret` brand of `platform/config`, or read out of one (`secret.reveal()`, `secret.value`): the TYPE says it is a secret. */
|
|
346
381
|
const isSecretValue = (context, node) => {
|
|
347
|
-
const holder = node.type === "CallExpression" && node.callee.type === "MemberExpression" ? node.callee.object : node.type === "MemberExpression" ? node.object : null
|
|
348
|
-
return isOwnedType(context, node, "Secret", "platform", "config") || (holder !== null && isOwnedType(context, holder, "Secret", "platform", "config"))
|
|
349
|
-
}
|
|
350
|
-
|
|
382
|
+
const holder = node.type === "CallExpression" && node.callee.type === "MemberExpression" ? node.callee.object : node.type === "MemberExpression" ? node.object : null;
|
|
383
|
+
return isOwnedType(context, node, "Secret", "platform", "config") || (holder !== null && isOwnedType(context, holder, "Secret", "platform", "config"));
|
|
384
|
+
};
|
|
351
385
|
/** The packages that declare the Node crypto types: a digest read out of a `Hash` or `Hmac` is secret-derived material. */
|
|
352
|
-
const CRYPTO_PACKAGES = new Set(["crypto", "node:crypto"])
|
|
353
|
-
|
|
386
|
+
const CRYPTO_PACKAGES = new Set(["crypto", "node:crypto"]);
|
|
354
387
|
/** A `.digest(...)` of a `Hash` or `Hmac` of Node's crypto, found by where the called signature is declared, never by the receiver's name. */
|
|
355
388
|
const isCryptoDigest = (context, node) => {
|
|
356
|
-
if (node.type !== "CallExpression" || node.callee.type !== "MemberExpression")
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
389
|
+
if (node.type !== "CallExpression" || node.callee.type !== "MemberExpression")
|
|
390
|
+
return false;
|
|
391
|
+
const { checker, toTs } = typed(context);
|
|
392
|
+
const tsCall = toTs(node);
|
|
393
|
+
const declaration = tsCall ? checker.getResolvedSignature(tsCall)?.declaration : undefined;
|
|
394
|
+
const declaredName = declaration && "name" in declaration ? declaration.name : undefined;
|
|
395
|
+
if (!declaration || !declaredName || declaredName.getText() !== "digest")
|
|
396
|
+
return false;
|
|
397
|
+
const owner = declaration.parent;
|
|
398
|
+
const ownerName = (ts.isInterfaceDeclaration(owner) || ts.isClassDeclaration(owner)) && owner.name ? owner.name.text : "";
|
|
399
|
+
if (ownerName !== "Hash" && ownerName !== "Hmac")
|
|
400
|
+
return false;
|
|
401
|
+
return CRYPTO_PACKAGES.has(moduleOf(declaration, String(declaration.getSourceFile().fileName).split("\\").join("/")));
|
|
402
|
+
};
|
|
367
403
|
/** A secret is compared with `timingSafeEqual`, never with an equality operator. */
|
|
368
404
|
export const secretCompareTimingSafe = {
|
|
369
405
|
meta: {
|
|
@@ -375,40 +411,41 @@ export const secretCompareTimingSafe = {
|
|
|
375
411
|
},
|
|
376
412
|
},
|
|
377
413
|
create(context) {
|
|
378
|
-
const filename = normalizePath(context.filename || context.getFilename())
|
|
379
|
-
if (isDeclarationFile(filename))
|
|
414
|
+
const filename = normalizePath(context.filename || context.getFilename());
|
|
415
|
+
if (isDeclarationFile(filename))
|
|
416
|
+
return {};
|
|
380
417
|
return {
|
|
381
418
|
BinaryExpression(node) {
|
|
382
|
-
if (!["===", "!==", "==", "!="].includes(node.operator))
|
|
383
|
-
|
|
419
|
+
if (!["===", "!==", "==", "!="].includes(node.operator))
|
|
420
|
+
return;
|
|
421
|
+
if (isPresenceOperand(node.left) || isPresenceOperand(node.right))
|
|
422
|
+
return;
|
|
384
423
|
for (const side of [node.left, node.right]) {
|
|
385
424
|
if (isSecretValue(context, side) || isCryptoDigest(context, side)) {
|
|
386
|
-
context.report({ node, messageId: "compare", data: { name: context.sourceCode.getText(side), operator: node.operator } })
|
|
387
|
-
return
|
|
425
|
+
context.report({ node, messageId: "compare", data: { name: context.sourceCode.getText(side), operator: node.operator } });
|
|
426
|
+
return;
|
|
388
427
|
}
|
|
389
|
-
const name = operandName(side)
|
|
428
|
+
const name = operandName(side);
|
|
390
429
|
if (name && isCredentialName(name)) {
|
|
391
|
-
context.report({ node, messageId: "compare", data: { name, operator: node.operator } })
|
|
392
|
-
return
|
|
430
|
+
context.report({ node, messageId: "compare", data: { name, operator: node.operator } });
|
|
431
|
+
return;
|
|
393
432
|
}
|
|
394
433
|
}
|
|
395
434
|
},
|
|
396
|
-
}
|
|
435
|
+
};
|
|
397
436
|
},
|
|
398
|
-
}
|
|
399
|
-
|
|
437
|
+
};
|
|
400
438
|
/** The rules this law contributes to the plugin. */
|
|
401
439
|
export const rules = {
|
|
402
440
|
"no-direct-env-read": noDirectEnvRead,
|
|
403
441
|
"config-parsed-in-main": configParsedInMain,
|
|
404
442
|
"no-secret-default": noSecretDefault,
|
|
405
443
|
"secret-compare-timing-safe": secretCompareTimingSafe,
|
|
406
|
-
}
|
|
407
|
-
|
|
444
|
+
};
|
|
408
445
|
/** All four start at error: a secret in source or a timing leak is never a warning. */
|
|
409
446
|
export const recommended = {
|
|
410
447
|
"starci-be/no-direct-env-read": "error",
|
|
411
448
|
"starci-be/config-parsed-in-main": "error",
|
|
412
449
|
"starci-be/no-secret-default": "error",
|
|
413
450
|
"starci-be/secret-compare-timing-safe": "error",
|
|
414
|
-
}
|
|
451
|
+
};
|