@nifrajs/cli 5.8.0 → 5.9.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/CHANGELOG.md +134 -0
- package/dist/agent-files.d.ts +0 -22
- package/dist/agent-files.d.ts.map +1 -1
- package/dist/agent-files.js +3 -1
- package/dist/agent-files.js.map +1 -1
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +2 -10
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +3 -3
- package/dist/assure.js.map +1 -1
- package/dist/check-scan.d.ts +2 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +54 -86
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts +3 -0
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +20 -23
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +8 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +42 -13
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +20 -30
- package/dist/command-catalog.js.map +1 -1
- package/dist/config-target.js +1 -1
- package/dist/config-target.js.map +1 -1
- package/dist/db-child.js +3 -10
- package/dist/db-child.js.map +1 -1
- package/dist/db-config.d.ts +2 -0
- package/dist/db-config.d.ts.map +1 -1
- package/dist/db-config.js +2 -0
- package/dist/db-config.js.map +1 -1
- package/dist/doctor.d.ts +14 -3
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +91 -6
- package/dist/doctor.js.map +1 -1
- package/dist/frontend-guidance.d.ts +19 -0
- package/dist/frontend-guidance.d.ts.map +1 -1
- package/dist/frontend-guidance.js +267 -23
- package/dist/frontend-guidance.js.map +1 -1
- package/dist/hand-built-manifest.d.ts.map +1 -1
- package/dist/hand-built-manifest.js +1 -1
- package/dist/hand-built-manifest.js.map +1 -1
- package/dist/internal/control-character.d.ts +3 -0
- package/dist/internal/control-character.d.ts.map +1 -0
- package/dist/internal/control-character.js +10 -0
- package/dist/internal/control-character.js.map +1 -0
- package/dist/internal/escape-regexp.d.ts +3 -0
- package/dist/internal/escape-regexp.d.ts.map +1 -0
- package/dist/internal/escape-regexp.js +5 -0
- package/dist/internal/escape-regexp.js.map +1 -0
- package/dist/internal/line-at.d.ts +3 -0
- package/dist/internal/line-at.d.ts.map +1 -0
- package/dist/internal/line-at.js +5 -0
- package/dist/internal/line-at.js.map +1 -0
- package/dist/internal/nifra-project.d.ts.map +1 -1
- package/dist/internal/nifra-project.js +35 -41
- package/dist/internal/nifra-project.js.map +1 -1
- package/dist/internal/posix-path.d.ts +3 -0
- package/dist/internal/posix-path.d.ts.map +1 -0
- package/dist/internal/posix-path.js +5 -0
- package/dist/internal/posix-path.js.map +1 -0
- package/dist/internal/project-specifiers.d.ts.map +1 -1
- package/dist/internal/project-specifiers.js +3 -10
- package/dist/internal/project-specifiers.js.map +1 -1
- package/dist/internal/realpath-or-self.d.ts +3 -0
- package/dist/internal/realpath-or-self.d.ts.map +1 -0
- package/dist/internal/realpath-or-self.js +11 -0
- package/dist/internal/realpath-or-self.js.map +1 -0
- package/dist/internal/record.d.ts +3 -0
- package/dist/internal/record.d.ts.map +1 -0
- package/dist/internal/record.js +5 -0
- package/dist/internal/record.js.map +1 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +28 -25
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/introspect.d.ts +0 -22
- package/dist/introspect.d.ts.map +1 -1
- package/dist/introspect.js +11 -151
- package/dist/introspect.js.map +1 -1
- package/dist/levels-tool.d.ts +2 -0
- package/dist/levels-tool.d.ts.map +1 -1
- package/dist/levels-tool.js +54 -64
- package/dist/levels-tool.js.map +1 -1
- package/dist/load.d.ts +6 -1
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js.map +1 -1
- package/dist/local-cli.d.ts +7 -0
- package/dist/local-cli.d.ts.map +1 -1
- package/dist/local-cli.js +13 -0
- package/dist/local-cli.js.map +1 -1
- package/dist/mcp-docs-tools.d.ts +1 -1
- package/dist/mcp-docs-tools.d.ts.map +1 -1
- package/dist/mcp-docs-tools.js +46 -3
- package/dist/mcp-docs-tools.js.map +1 -1
- package/dist/mcp-http.d.ts +1 -1
- package/dist/mcp-http.js +2 -2
- package/dist/mcp-io.d.ts +16 -0
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +63 -0
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-isolate.d.ts.map +1 -1
- package/dist/mcp-isolate.js +2 -1
- package/dist/mcp-isolate.js.map +1 -1
- package/dist/mcp-project-child.d.ts.map +1 -1
- package/dist/mcp-project-child.js +5 -12
- package/dist/mcp-project-child.js.map +1 -1
- package/dist/mcp-render.d.ts.map +1 -1
- package/dist/mcp-render.js +9 -51
- package/dist/mcp-render.js.map +1 -1
- package/dist/mcp-root.js +1 -1
- package/dist/mcp-root.js.map +1 -1
- package/dist/mcp-run.d.ts.map +1 -1
- package/dist/mcp-run.js +3 -46
- package/dist/mcp-run.js.map +1 -1
- package/dist/mcp-ws.d.ts.map +1 -1
- package/dist/mcp-ws.js +2 -18
- package/dist/mcp-ws.js.map +1 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +36 -57
- package/dist/migrate-layout.js.map +1 -1
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +7 -7
- package/dist/output-schemas.js.map +1 -1
- package/dist/port.d.ts.map +1 -1
- package/dist/port.js +1 -2
- package/dist/port.js.map +1 -1
- package/dist/ppr-read-fix.js +2 -2
- package/dist/ppr-read-fix.js.map +1 -1
- package/dist/recipes/5.9.0.d.ts +10 -0
- package/dist/recipes/5.9.0.d.ts.map +1 -0
- package/dist/recipes/5.9.0.js +41 -0
- package/dist/recipes/5.9.0.js.map +1 -0
- package/dist/recipes/index.d.ts +5 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +2 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +9 -13
- package/dist/review.js.map +1 -1
- package/dist/rules/contract-visibility.d.ts.map +1 -1
- package/dist/rules/contract-visibility.js +3 -9
- package/dist/rules/contract-visibility.js.map +1 -1
- package/dist/rules/data-guard.d.ts.map +1 -1
- package/dist/rules/data-guard.js +3 -10
- package/dist/rules/data-guard.js.map +1 -1
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +41 -58
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +20 -27
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +206 -313
- package/dist/rules/security.js.map +1 -1
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +3 -10
- package/dist/rules/zones.js.map +1 -1
- package/dist/runtime-differences.d.ts +62 -0
- package/dist/runtime-differences.d.ts.map +1 -0
- package/dist/runtime-differences.js +222 -0
- package/dist/runtime-differences.js.map +1 -0
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +43 -43
- package/dist/sdk.js.map +1 -1
- package/dist/smoke.d.ts.map +1 -1
- package/dist/smoke.js +4 -12
- package/dist/smoke.js.map +1 -1
- package/dist/source-rewrites.d.ts +27 -0
- package/dist/source-rewrites.d.ts.map +1 -0
- package/dist/source-rewrites.js +402 -0
- package/dist/source-rewrites.js.map +1 -0
- package/dist/stylex-migrate.d.ts.map +1 -1
- package/dist/stylex-migrate.js +1 -1
- package/dist/stylex-migrate.js.map +1 -1
- package/dist/symptom-search.d.ts +5 -0
- package/dist/symptom-search.d.ts.map +1 -0
- package/dist/symptom-search.js +21 -0
- package/dist/symptom-search.js.map +1 -0
- package/dist/upgrade.d.ts +28 -3
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +153 -64
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +5 -3
- package/dist/verification-plan.js.map +1 -1
- package/docs/examples.json +32 -2
- package/docs/llms-full.txt +749 -95
- package/docs/types.json +300 -61
- package/package.json +11 -11
- package/src/agent-files.ts +4 -1
- package/src/assure-hydration.ts +2 -9
- package/src/assure.ts +3 -4
- package/src/check-scan.ts +65 -82
- package/src/check.ts +25 -23
- package/src/cli.ts +61 -13
- package/src/command-catalog.ts +22 -32
- package/src/config-target.ts +1 -1
- package/src/db-child.ts +3 -10
- package/src/db-config.ts +4 -0
- package/src/doctor.ts +128 -12
- package/src/frontend-guidance.ts +344 -25
- package/src/hand-built-manifest.ts +1 -2
- package/src/internal/control-character.ts +8 -0
- package/src/internal/escape-regexp.ts +4 -0
- package/src/internal/line-at.ts +4 -0
- package/src/internal/nifra-project.ts +39 -35
- package/src/internal/posix-path.ts +4 -0
- package/src/internal/project-specifiers.ts +3 -10
- package/src/internal/realpath-or-self.ts +10 -0
- package/src/internal/record.ts +4 -0
- package/src/internal/source-facts.ts +39 -29
- package/src/introspect.ts +16 -156
- package/src/levels-tool.ts +71 -78
- package/src/load.ts +6 -1
- package/src/local-cli.ts +12 -0
- package/src/mcp-docs-tools.ts +51 -3
- package/src/mcp-http.ts +2 -2
- package/src/mcp-io.ts +77 -0
- package/src/mcp-isolate.ts +2 -3
- package/src/mcp-project-child.ts +5 -14
- package/src/mcp-render.ts +11 -59
- package/src/mcp-root.ts +1 -1
- package/src/mcp-run.ts +5 -54
- package/src/mcp-ws.ts +2 -19
- package/src/migrate-layout.ts +52 -72
- package/src/output-schemas.ts +7 -8
- package/src/port.ts +1 -4
- package/src/ppr-read-fix.ts +2 -2
- package/src/recipes/5.9.0.ts +42 -0
- package/src/recipes/index.ts +7 -0
- package/src/review.ts +12 -15
- package/src/rules/contract-visibility.ts +3 -8
- package/src/rules/data-guard.ts +3 -10
- package/src/rules/pages.ts +47 -58
- package/src/rules/routes.ts +21 -27
- package/src/rules/security.ts +224 -255
- package/src/rules/zones.ts +3 -10
- package/src/runtime-differences.ts +302 -0
- package/src/sdk.ts +55 -58
- package/src/smoke.ts +4 -13
- package/src/source-rewrites.ts +463 -0
- package/src/stylex-migrate.ts +1 -3
- package/src/symptom-search.ts +27 -0
- package/src/upgrade.ts +194 -74
- package/src/verification-plan.ts +10 -4
package/dist/rules/security.js
CHANGED
|
@@ -127,6 +127,35 @@ function isPresenceComparison(ts, node) {
|
|
|
127
127
|
}
|
|
128
128
|
return false;
|
|
129
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Runs `onFile` on every parsed source file, or reports that the scan could not run because TypeScript
|
|
132
|
+
* is missing.
|
|
133
|
+
*/
|
|
134
|
+
async function scanFiles(ctx, code, title, onFile) {
|
|
135
|
+
const loaded = await loadRuleTypeScript(ctx);
|
|
136
|
+
if (loaded.diagnostics !== undefined)
|
|
137
|
+
return loaded.diagnostics;
|
|
138
|
+
const ts = loaded.compiler;
|
|
139
|
+
if (ts === undefined)
|
|
140
|
+
return didNotRun(code, title);
|
|
141
|
+
const findings = [];
|
|
142
|
+
for (const file of ctx.project.source.files) {
|
|
143
|
+
const parsed = parsedFile(ts, ctx.project.source, file);
|
|
144
|
+
if (parsed !== undefined)
|
|
145
|
+
onFile(ts, { file, ...parsed }, findings);
|
|
146
|
+
}
|
|
147
|
+
return findings;
|
|
148
|
+
}
|
|
149
|
+
/** {@link scanFiles} over every node of each file, children included. */
|
|
150
|
+
function scanNodes(ctx, code, title, onNode) {
|
|
151
|
+
return scanFiles(ctx, code, title, (ts, source, findings) => {
|
|
152
|
+
const visit = (node) => {
|
|
153
|
+
onNode(ts, node, source, findings);
|
|
154
|
+
ts.forEachChild(node, visit);
|
|
155
|
+
};
|
|
156
|
+
visit(source.tree);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
130
159
|
function parse(ts, file, source) {
|
|
131
160
|
return ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true, scriptKindOf(ts, file));
|
|
132
161
|
}
|
|
@@ -197,6 +226,16 @@ function bindsName(ts, binding, name) {
|
|
|
197
226
|
return binding.text === name;
|
|
198
227
|
return binding.elements.some((element) => !ts.isOmittedExpression(element) && bindsName(ts, element.name, name));
|
|
199
228
|
}
|
|
229
|
+
/** Whether `node` is a loop or a catch clause that declares `name` for its body. */
|
|
230
|
+
function loopOrCatchBinds(ts, node, name) {
|
|
231
|
+
if (ts.isForStatement(node) || ts.isForOfStatement(node) || ts.isForInStatement(node))
|
|
232
|
+
return (node.initializer !== undefined &&
|
|
233
|
+
ts.isVariableDeclarationList(node.initializer) &&
|
|
234
|
+
node.initializer.declarations.some((d) => bindsName(ts, d.name, name)));
|
|
235
|
+
return (ts.isCatchClause(node) &&
|
|
236
|
+
node.variableDeclaration !== undefined &&
|
|
237
|
+
bindsName(ts, node.variableDeclaration.name, name));
|
|
238
|
+
}
|
|
200
239
|
/**
|
|
201
240
|
* Whether `id` names a plain parameter of an enclosing function, not a value the file builds: the
|
|
202
241
|
* nearest declaration of the name, walking out, must be that parameter. A loop or catch variable, a
|
|
@@ -216,14 +255,7 @@ function isParameterRef(ts, id) {
|
|
|
216
255
|
}
|
|
217
256
|
if ((ts.isBlock(node) || ts.isSourceFile(node)) && declaresIn(ts, node.statements, id.text))
|
|
218
257
|
return false;
|
|
219
|
-
if ((ts
|
|
220
|
-
node.initializer !== undefined &&
|
|
221
|
-
ts.isVariableDeclarationList(node.initializer) &&
|
|
222
|
-
node.initializer.declarations.some((d) => bindsName(ts, d.name, id.text)))
|
|
223
|
-
return false;
|
|
224
|
-
if (ts.isCatchClause(node) &&
|
|
225
|
-
node.variableDeclaration !== undefined &&
|
|
226
|
-
bindsName(ts, node.variableDeclaration.name, id.text))
|
|
258
|
+
if (loopOrCatchBinds(ts, node, id.text))
|
|
227
259
|
return false;
|
|
228
260
|
}
|
|
229
261
|
return false;
|
|
@@ -279,14 +311,7 @@ function constInitializer(ts, id) {
|
|
|
279
311
|
for (let node = id.parent; node !== undefined; node = node.parent) {
|
|
280
312
|
if (ts.isFunctionLike(node) && node.parameters.some((p) => bindsName(ts, p.name, id.text)))
|
|
281
313
|
return undefined;
|
|
282
|
-
if ((ts
|
|
283
|
-
node.initializer !== undefined &&
|
|
284
|
-
ts.isVariableDeclarationList(node.initializer) &&
|
|
285
|
-
node.initializer.declarations.some((d) => bindsName(ts, d.name, id.text)))
|
|
286
|
-
return undefined;
|
|
287
|
-
if (ts.isCatchClause(node) &&
|
|
288
|
-
node.variableDeclaration !== undefined &&
|
|
289
|
-
bindsName(ts, node.variableDeclaration.name, id.text))
|
|
314
|
+
if (loopOrCatchBinds(ts, node, id.text))
|
|
290
315
|
return undefined;
|
|
291
316
|
if (!ts.isBlock(node) && !ts.isSourceFile(node))
|
|
292
317
|
continue;
|
|
@@ -413,20 +438,9 @@ export function rewriteSecretComparisons(ts, file, source, browser) {
|
|
|
413
438
|
export const secretComparisonRule = {
|
|
414
439
|
code: "NF-S002",
|
|
415
440
|
title: "Non-constant-time secret comparison",
|
|
416
|
-
|
|
417
|
-
const loaded = await loadRuleTypeScript(ctx);
|
|
418
|
-
if (loaded.diagnostics !== undefined)
|
|
419
|
-
return loaded.diagnostics;
|
|
420
|
-
const ts = loaded.compiler;
|
|
421
|
-
if (ts === undefined)
|
|
422
|
-
return didNotRun("NF-S002", "Non-constant-time secret comparison scan");
|
|
423
|
-
const findings = [];
|
|
441
|
+
scan(ctx) {
|
|
424
442
|
const webDirs = createWebAppProbe(ctx.root);
|
|
425
|
-
|
|
426
|
-
const parsed = parsedFile(ts, ctx.project.source, file);
|
|
427
|
-
if (parsed === undefined)
|
|
428
|
-
continue;
|
|
429
|
-
const { tree, lines } = parsed;
|
|
443
|
+
return scanFiles(ctx, "NF-S002", "Non-constant-time secret comparison scan", (ts, { file, tree, lines }, findings) => {
|
|
430
444
|
const browser = provenBrowserFile(ctx.root, file, webDirs);
|
|
431
445
|
for (const { left, right, line } of secretComparisons(ts, tree, browser)) {
|
|
432
446
|
const reviewed = expectedReason(lines, line, "NF-S002") !== undefined;
|
|
@@ -453,59 +467,40 @@ export const secretComparisonRule = {
|
|
|
453
467
|
verify: "nifra check --lints-only",
|
|
454
468
|
}));
|
|
455
469
|
}
|
|
456
|
-
}
|
|
457
|
-
return findings;
|
|
470
|
+
});
|
|
458
471
|
},
|
|
459
472
|
};
|
|
460
473
|
export const piiLogRule = {
|
|
461
474
|
code: "NF-S003",
|
|
462
475
|
title: "Sensitive value in log call",
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
const line = tree.getLineAndCharacterOfPosition(node.getStart(tree)).line + 1;
|
|
487
|
-
const reviewed = expectedReason(lines, line, "NF-S003") !== undefined;
|
|
488
|
-
findings.push(diagnostic({
|
|
489
|
-
code: "NF-S003",
|
|
490
|
-
severity: reviewed ? "info" : "warn",
|
|
491
|
-
file,
|
|
492
|
-
line,
|
|
493
|
-
message: reviewed
|
|
494
|
-
? "sensitive value in log call is expected here"
|
|
495
|
-
: unexpectedMessage("PII-shaped values must not be passed directly to log calls", lines, line, "NF-S003"),
|
|
496
|
-
evidence: [name, ...expectationEvidence(lines, line, "NF-S003")],
|
|
497
|
-
verify: "nifra check --lints-only",
|
|
498
|
-
}));
|
|
499
|
-
}
|
|
500
|
-
}
|
|
476
|
+
scan: (ctx) => scanNodes(ctx, "NF-S003", "Sensitive-value-in-log scan", (ts, node, { file, tree, lines }, findings) => {
|
|
477
|
+
if (ts.isCallExpression(node)) {
|
|
478
|
+
const expression = node.expression;
|
|
479
|
+
const callee = ts.isPropertyAccessExpression(expression)
|
|
480
|
+
? `${nameOf(ts, expression.expression) ?? ""}.${expression.name.text}`
|
|
481
|
+
: (nameOf(ts, expression) ?? "");
|
|
482
|
+
if (/^(?:console|logger)\./.test(callee)) {
|
|
483
|
+
for (const arg of node.arguments) {
|
|
484
|
+
const name = nameOf(ts, arg);
|
|
485
|
+
if (name !== undefined && PII.test(name)) {
|
|
486
|
+
const line = tree.getLineAndCharacterOfPosition(node.getStart(tree)).line + 1;
|
|
487
|
+
const reviewed = expectedReason(lines, line, "NF-S003") !== undefined;
|
|
488
|
+
findings.push(diagnostic({
|
|
489
|
+
code: "NF-S003",
|
|
490
|
+
severity: reviewed ? "info" : "warn",
|
|
491
|
+
file,
|
|
492
|
+
line,
|
|
493
|
+
message: reviewed
|
|
494
|
+
? "sensitive value in log call is expected here"
|
|
495
|
+
: unexpectedMessage("PII-shaped values must not be passed directly to log calls", lines, line, "NF-S003"),
|
|
496
|
+
evidence: [name, ...expectationEvidence(lines, line, "NF-S003")],
|
|
497
|
+
verify: "nifra check --lints-only",
|
|
498
|
+
}));
|
|
501
499
|
}
|
|
502
500
|
}
|
|
503
|
-
|
|
504
|
-
};
|
|
505
|
-
visit(tree);
|
|
501
|
+
}
|
|
506
502
|
}
|
|
507
|
-
|
|
508
|
-
},
|
|
503
|
+
}),
|
|
509
504
|
};
|
|
510
505
|
/**
|
|
511
506
|
* A function's own name, or for an anonymous arrow/function expression the name it is bound to
|
|
@@ -612,20 +607,9 @@ function isDenial(ts, expression, authenticator) {
|
|
|
612
607
|
export const failOpenGateRule = {
|
|
613
608
|
code: "NF-S001",
|
|
614
609
|
title: "Fail-open gate",
|
|
615
|
-
|
|
616
|
-
const loaded = await loadRuleTypeScript(ctx);
|
|
617
|
-
if (loaded.diagnostics !== undefined)
|
|
618
|
-
return loaded.diagnostics;
|
|
619
|
-
const ts = loaded.compiler;
|
|
620
|
-
if (ts === undefined)
|
|
621
|
-
return didNotRun("NF-S001", "Fail-open gate scan");
|
|
622
|
-
const findings = [];
|
|
610
|
+
scan(ctx) {
|
|
623
611
|
const webDirs = createWebAppProbe(ctx.root);
|
|
624
|
-
|
|
625
|
-
const parsed = parsedFile(ts, ctx.project.source, file);
|
|
626
|
-
if (parsed === undefined)
|
|
627
|
-
continue;
|
|
628
|
-
const { tree, lines } = parsed;
|
|
612
|
+
return scanFiles(ctx, "NF-S001", "Fail-open gate scan", (ts, { file, tree, lines }, findings) => {
|
|
629
613
|
let browser;
|
|
630
614
|
const visit = (node) => {
|
|
631
615
|
if (ts.isCatchClause(node)) {
|
|
@@ -660,8 +644,7 @@ export const failOpenGateRule = {
|
|
|
660
644
|
ts.forEachChild(node, visit);
|
|
661
645
|
};
|
|
662
646
|
visit(tree);
|
|
663
|
-
}
|
|
664
|
-
return findings;
|
|
647
|
+
});
|
|
665
648
|
},
|
|
666
649
|
};
|
|
667
650
|
/** True when `param` is referenced anywhere inside `body`. */
|
|
@@ -682,114 +665,78 @@ function usesParam(ts, body, param) {
|
|
|
682
665
|
export const corsOriginPredicateRule = {
|
|
683
666
|
code: "NF-S004",
|
|
684
667
|
title: "CORS origin predicate ignores the origin",
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
?
|
|
713
|
-
:
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
code: "NF-S004",
|
|
721
|
-
severity: reviewed ? "info" : "warn",
|
|
722
|
-
file,
|
|
723
|
-
line,
|
|
724
|
-
message: reviewed
|
|
725
|
-
? "constant CORS origin predicate is expected here"
|
|
726
|
-
: unexpectedMessage("CORS origin predicate never inspects the origin - it allows every origin; list explicit origins or use the argument", lines, line, "NF-S004"),
|
|
727
|
-
evidence: [
|
|
728
|
-
"origin predicate",
|
|
729
|
-
...expectationEvidence(lines, line, "NF-S004"),
|
|
730
|
-
],
|
|
731
|
-
verify: "nifra check --lints-only",
|
|
732
|
-
}));
|
|
733
|
-
}
|
|
734
|
-
}
|
|
668
|
+
scan: (ctx) => scanNodes(ctx, "NF-S004", "CORS origin predicate scan", (ts, node, { file, tree, lines }, findings) => {
|
|
669
|
+
if (ts.isCallExpression(node) && nameOf(ts, node.expression) === "cors") {
|
|
670
|
+
const arg = node.arguments[0];
|
|
671
|
+
if (arg !== undefined && ts.isObjectLiteralExpression(arg)) {
|
|
672
|
+
for (const prop of arg.properties) {
|
|
673
|
+
if (ts.isPropertyAssignment(prop) &&
|
|
674
|
+
nameOf(ts, prop.name) === "origin" &&
|
|
675
|
+
(ts.isArrowFunction(prop.initializer) || ts.isFunctionExpression(prop.initializer))) {
|
|
676
|
+
const fn = prop.initializer;
|
|
677
|
+
const param = fn.parameters[0]?.name;
|
|
678
|
+
// A predicate with no parameter, or one that never reads it, allows every origin -
|
|
679
|
+
// the guardrail the predicate form exists for is bypassed. A destructured parameter
|
|
680
|
+
// is left alone (can't cheaply prove non-use).
|
|
681
|
+
const ignoresOrigin = param === undefined
|
|
682
|
+
? true
|
|
683
|
+
: ts.isIdentifier(param)
|
|
684
|
+
? !usesParam(ts, fn.body, param.text)
|
|
685
|
+
: false;
|
|
686
|
+
if (ignoresOrigin) {
|
|
687
|
+
const line = tree.getLineAndCharacterOfPosition(prop.getStart(tree)).line + 1;
|
|
688
|
+
const reviewed = expectedReason(lines, line, "NF-S004") !== undefined;
|
|
689
|
+
findings.push(diagnostic({
|
|
690
|
+
code: "NF-S004",
|
|
691
|
+
severity: reviewed ? "info" : "warn",
|
|
692
|
+
file,
|
|
693
|
+
line,
|
|
694
|
+
message: reviewed
|
|
695
|
+
? "constant CORS origin predicate is expected here"
|
|
696
|
+
: unexpectedMessage("CORS origin predicate never inspects the origin - it allows every origin; list explicit origins or use the argument", lines, line, "NF-S004"),
|
|
697
|
+
evidence: [
|
|
698
|
+
"origin predicate",
|
|
699
|
+
...expectationEvidence(lines, line, "NF-S004"),
|
|
700
|
+
],
|
|
701
|
+
verify: "nifra check --lints-only",
|
|
702
|
+
}));
|
|
735
703
|
}
|
|
736
704
|
}
|
|
737
705
|
}
|
|
738
|
-
|
|
739
|
-
};
|
|
740
|
-
visit(tree);
|
|
706
|
+
}
|
|
741
707
|
}
|
|
742
|
-
|
|
743
|
-
},
|
|
708
|
+
}),
|
|
744
709
|
};
|
|
745
710
|
export const externalRedirectRule = {
|
|
746
711
|
code: "NF-S005",
|
|
747
712
|
title: "External redirect opt-out",
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
const line = tree.getLineAndCharacterOfPosition(node.getStart(tree)).line + 1;
|
|
771
|
-
const reviewed = expectedReason(lines, line, "NF-S005") !== undefined;
|
|
772
|
-
findings.push(diagnostic({
|
|
773
|
-
code: "NF-S005",
|
|
774
|
-
severity: reviewed ? "info" : "warn",
|
|
775
|
-
file,
|
|
776
|
-
line,
|
|
777
|
-
message: reviewed
|
|
778
|
-
? "external redirect is expected here"
|
|
779
|
-
: unexpectedMessage("redirect opts out of the same-origin default - verify the target can never be derived from request input (open-redirect risk)", lines, line, "NF-S005"),
|
|
780
|
-
evidence: ["external: true", ...expectationEvidence(lines, line, "NF-S005")],
|
|
781
|
-
verify: "nifra check --lints-only",
|
|
782
|
-
}));
|
|
783
|
-
}
|
|
784
|
-
}
|
|
713
|
+
scan: (ctx) => scanNodes(ctx, "NF-S005", "External redirect opt-out scan", (ts, node, { file, tree, lines }, findings) => {
|
|
714
|
+
if (ts.isCallExpression(node) && nameOf(ts, node.expression) === "redirect") {
|
|
715
|
+
for (const arg of node.arguments) {
|
|
716
|
+
if (!ts.isObjectLiteralExpression(arg))
|
|
717
|
+
continue;
|
|
718
|
+
for (const prop of arg.properties) {
|
|
719
|
+
if (ts.isPropertyAssignment(prop) &&
|
|
720
|
+
nameOf(ts, prop.name) === "external" &&
|
|
721
|
+
prop.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
722
|
+
const line = tree.getLineAndCharacterOfPosition(node.getStart(tree)).line + 1;
|
|
723
|
+
const reviewed = expectedReason(lines, line, "NF-S005") !== undefined;
|
|
724
|
+
findings.push(diagnostic({
|
|
725
|
+
code: "NF-S005",
|
|
726
|
+
severity: reviewed ? "info" : "warn",
|
|
727
|
+
file,
|
|
728
|
+
line,
|
|
729
|
+
message: reviewed
|
|
730
|
+
? "external redirect is expected here"
|
|
731
|
+
: unexpectedMessage("redirect opts out of the same-origin default - verify the target can never be derived from request input (open-redirect risk)", lines, line, "NF-S005"),
|
|
732
|
+
evidence: ["external: true", ...expectationEvidence(lines, line, "NF-S005")],
|
|
733
|
+
verify: "nifra check --lints-only",
|
|
734
|
+
}));
|
|
785
735
|
}
|
|
786
736
|
}
|
|
787
|
-
|
|
788
|
-
};
|
|
789
|
-
visit(tree);
|
|
737
|
+
}
|
|
790
738
|
}
|
|
791
|
-
|
|
792
|
-
},
|
|
739
|
+
}),
|
|
793
740
|
};
|
|
794
741
|
const ESCAPE_HATCHES = {
|
|
795
742
|
allowLengthless: "body-limit stops publishing BODY_BOUNDED evidence - lengthless (chunked) bodies bypass the Content-Length gate",
|
|
@@ -799,96 +746,60 @@ const ESCAPE_HATCHES = {
|
|
|
799
746
|
export const assuranceEscapeHatchRule = {
|
|
800
747
|
code: "NF-S006",
|
|
801
748
|
title: "Security escape hatch enabled",
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
const reviewed = expectedReason(lines, line, "NF-S006") !== undefined;
|
|
822
|
-
findings.push(diagnostic({
|
|
823
|
-
code: "NF-S006",
|
|
824
|
-
severity: reviewed ? "info" : "warn",
|
|
825
|
-
file,
|
|
826
|
-
line,
|
|
827
|
-
message: reviewed
|
|
828
|
-
? `${name} escape hatch is expected here`
|
|
829
|
-
: unexpectedMessage(`${name}: ${consequence}`, lines, line, "NF-S006"),
|
|
830
|
-
evidence: [name, ...expectationEvidence(lines, line, "NF-S006")],
|
|
831
|
-
verify: "nifra check --lints-only",
|
|
832
|
-
}));
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
ts.forEachChild(node, visit);
|
|
836
|
-
};
|
|
837
|
-
visit(tree);
|
|
749
|
+
scan: (ctx) => scanNodes(ctx, "NF-S006", "Security escape hatch scan", (ts, node, { file, tree, lines }, findings) => {
|
|
750
|
+
if (ts.isPropertyAssignment(node) && node.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
751
|
+
const name = nameOf(ts, node.name);
|
|
752
|
+
const consequence = name !== undefined ? ESCAPE_HATCHES[name] : undefined;
|
|
753
|
+
if (name !== undefined && consequence !== undefined) {
|
|
754
|
+
const line = tree.getLineAndCharacterOfPosition(node.getStart(tree)).line + 1;
|
|
755
|
+
const reviewed = expectedReason(lines, line, "NF-S006") !== undefined;
|
|
756
|
+
findings.push(diagnostic({
|
|
757
|
+
code: "NF-S006",
|
|
758
|
+
severity: reviewed ? "info" : "warn",
|
|
759
|
+
file,
|
|
760
|
+
line,
|
|
761
|
+
message: reviewed
|
|
762
|
+
? `${name} escape hatch is expected here`
|
|
763
|
+
: unexpectedMessage(`${name}: ${consequence}`, lines, line, "NF-S006"),
|
|
764
|
+
evidence: [name, ...expectationEvidence(lines, line, "NF-S006")],
|
|
765
|
+
verify: "nifra check --lints-only",
|
|
766
|
+
}));
|
|
767
|
+
}
|
|
838
768
|
}
|
|
839
|
-
|
|
840
|
-
},
|
|
769
|
+
}),
|
|
841
770
|
};
|
|
842
771
|
const COOKIE_PREFIX = /^__(?:Host|Secure)-/;
|
|
843
772
|
export const unprefixedSecureCookieRule = {
|
|
844
773
|
code: "NF-S007",
|
|
845
774
|
title: "Secure cookie without a __Host-/__Secure- prefix",
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
prop.initializer.kind === ts.SyntaxKind.TrueKeyword));
|
|
871
|
-
// Only literal names are judged - a dynamic name can't be checked for a prefix.
|
|
872
|
-
if (secure && !hasPrefix && nameArg !== undefined && ts.isStringLiteralLike(nameArg)) {
|
|
873
|
-
const line = tree.getLineAndCharacterOfPosition(node.getStart(tree)).line + 1;
|
|
874
|
-
findings.push(diagnostic({
|
|
875
|
-
code: "NF-S007",
|
|
876
|
-
severity: "info",
|
|
877
|
-
file,
|
|
878
|
-
line,
|
|
879
|
-
message: "Secure cookie without a __Host-/__Secure- prefix - a prefix stops subdomains and insecure contexts from shadowing it",
|
|
880
|
-
evidence: [nameArg.text],
|
|
881
|
-
verify: "nifra check --lints-only",
|
|
882
|
-
}));
|
|
883
|
-
}
|
|
884
|
-
}
|
|
775
|
+
scan: (ctx) => scanNodes(ctx, "NF-S007", "Secure cookie prefix scan", (ts, node, { file, tree }, findings) => {
|
|
776
|
+
if (ts.isCallExpression(node)) {
|
|
777
|
+
const callee = nameOf(ts, node.expression);
|
|
778
|
+
if (callee === "cookie" || callee === "serializeCookie") {
|
|
779
|
+
const nameArg = node.arguments[0];
|
|
780
|
+
const hasPrefix = nameArg !== undefined &&
|
|
781
|
+
ts.isStringLiteralLike(nameArg) &&
|
|
782
|
+
COOKIE_PREFIX.test(nameArg.text);
|
|
783
|
+
const secure = node.arguments.some((arg) => ts.isObjectLiteralExpression(arg) &&
|
|
784
|
+
arg.properties.some((prop) => ts.isPropertyAssignment(prop) &&
|
|
785
|
+
nameOf(ts, prop.name) === "secure" &&
|
|
786
|
+
prop.initializer.kind === ts.SyntaxKind.TrueKeyword));
|
|
787
|
+
// Only literal names are judged - a dynamic name can't be checked for a prefix.
|
|
788
|
+
if (secure && !hasPrefix && nameArg !== undefined && ts.isStringLiteralLike(nameArg)) {
|
|
789
|
+
const line = tree.getLineAndCharacterOfPosition(node.getStart(tree)).line + 1;
|
|
790
|
+
findings.push(diagnostic({
|
|
791
|
+
code: "NF-S007",
|
|
792
|
+
severity: "info",
|
|
793
|
+
file,
|
|
794
|
+
line,
|
|
795
|
+
message: "Secure cookie without a __Host-/__Secure- prefix - a prefix stops subdomains and insecure contexts from shadowing it",
|
|
796
|
+
evidence: [nameArg.text],
|
|
797
|
+
verify: "nifra check --lints-only",
|
|
798
|
+
}));
|
|
885
799
|
}
|
|
886
|
-
|
|
887
|
-
};
|
|
888
|
-
visit(tree);
|
|
800
|
+
}
|
|
889
801
|
}
|
|
890
|
-
|
|
891
|
-
},
|
|
802
|
+
}),
|
|
892
803
|
};
|
|
893
804
|
/** Reads the backend the contract-lock check loaded; this rule runs no project code of its own. */
|
|
894
805
|
export const inputBeforeAuthenticationRule = {
|
|
@@ -943,53 +854,35 @@ function callsJsonParse(ts, node) {
|
|
|
943
854
|
export const unvalidatedWsFrameRule = {
|
|
944
855
|
code: "NF-S009",
|
|
945
856
|
title: "WebSocket frames parsed without a messageSchema",
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
const line = tree.getLineAndCharacterOfPosition(node.expression.name.getStart(tree)).line + 1;
|
|
972
|
-
const reviewed = expectedReason(lines, line, "NF-S009") !== undefined;
|
|
973
|
-
findings.push(diagnostic({
|
|
974
|
-
code: "NF-S009",
|
|
975
|
-
severity: "info",
|
|
976
|
-
file,
|
|
977
|
-
line,
|
|
978
|
-
message: reviewed
|
|
979
|
-
? `ws("${path.text}") parsing its own frames is expected here`
|
|
980
|
-
: `ws("${path.text}") parses frames with JSON.parse in message() and declares no messageSchema, so a client's frame reaches the handler unvalidated and the typed client's send() takes unknown. Declare messageSchema: message() then receives the parsed, validated value, invalid frames go to onInvalidMessage, and send() is typed from it`,
|
|
981
|
-
evidence: [path.text, ...expectationEvidence(lines, line, "NF-S009")],
|
|
982
|
-
verify: "nifra check --lints-only",
|
|
983
|
-
}));
|
|
984
|
-
}
|
|
985
|
-
}
|
|
857
|
+
scan: (ctx) => scanNodes(ctx, "NF-S009", "WebSocket messageSchema scan", (ts, node, { file, tree, lines }, findings) => {
|
|
858
|
+
if (ts.isCallExpression(node) &&
|
|
859
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
860
|
+
node.expression.name.text === "ws") {
|
|
861
|
+
const [path, handler] = node.arguments;
|
|
862
|
+
if (path !== undefined &&
|
|
863
|
+
ts.isStringLiteralLike(path) &&
|
|
864
|
+
handler !== undefined &&
|
|
865
|
+
ts.isObjectLiteralExpression(handler) &&
|
|
866
|
+
!handler.properties.some((prop) => ts.isSpreadAssignment(prop) || propertyName(ts, prop) === "messageSchema")) {
|
|
867
|
+
const body = wsMessageHandler(ts, handler);
|
|
868
|
+
if (body !== undefined && callsJsonParse(ts, body)) {
|
|
869
|
+
const line = tree.getLineAndCharacterOfPosition(node.expression.name.getStart(tree)).line + 1;
|
|
870
|
+
const reviewed = expectedReason(lines, line, "NF-S009") !== undefined;
|
|
871
|
+
findings.push(diagnostic({
|
|
872
|
+
code: "NF-S009",
|
|
873
|
+
severity: "info",
|
|
874
|
+
file,
|
|
875
|
+
line,
|
|
876
|
+
message: reviewed
|
|
877
|
+
? `ws("${path.text}") parsing its own frames is expected here`
|
|
878
|
+
: `ws("${path.text}") parses frames with JSON.parse in message() and declares no messageSchema, so a client's frame reaches the handler unvalidated and the typed client's send() takes unknown. Declare messageSchema: message() then receives the parsed, validated value, invalid frames go to onInvalidMessage, and send() is typed from it`,
|
|
879
|
+
evidence: [path.text, ...expectationEvidence(lines, line, "NF-S009")],
|
|
880
|
+
verify: "nifra check --lints-only",
|
|
881
|
+
}));
|
|
986
882
|
}
|
|
987
|
-
|
|
988
|
-
};
|
|
989
|
-
visit(tree);
|
|
883
|
+
}
|
|
990
884
|
}
|
|
991
|
-
|
|
992
|
-
},
|
|
885
|
+
}),
|
|
993
886
|
};
|
|
994
887
|
export const securityRules = Object.freeze([
|
|
995
888
|
failOpenGateRule,
|