@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/src/rules/security.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
commentBlockHasMarker,
|
|
10
10
|
MISSING_EXPECTATION_REASON,
|
|
11
11
|
} from "./comment-markers.ts"
|
|
12
|
-
import type { CheckRule, SourceIndex } from "./index.ts"
|
|
12
|
+
import type { CheckRule, RuleContext, SourceIndex } from "./index.ts"
|
|
13
13
|
import { loadRuleTypeScript } from "./typescript.ts"
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -158,6 +158,51 @@ function isPresenceComparison(ts: typeof TSApi, node: TSApi.BinaryExpression): b
|
|
|
158
158
|
return false
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
/** A source file a scan reads: its path, tree and lines. */
|
|
162
|
+
interface ScannedFile {
|
|
163
|
+
readonly file: string
|
|
164
|
+
readonly tree: TSApi.SourceFile
|
|
165
|
+
readonly lines: readonly string[]
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Runs `onFile` on every parsed source file, or reports that the scan could not run because TypeScript
|
|
170
|
+
* is missing.
|
|
171
|
+
*/
|
|
172
|
+
async function scanFiles(
|
|
173
|
+
ctx: RuleContext,
|
|
174
|
+
code: string,
|
|
175
|
+
title: string,
|
|
176
|
+
onFile: (ts: typeof TSApi, source: ScannedFile, findings: Diagnostic[]) => void,
|
|
177
|
+
): Promise<readonly Diagnostic[]> {
|
|
178
|
+
const loaded = await loadRuleTypeScript(ctx)
|
|
179
|
+
if (loaded.diagnostics !== undefined) return loaded.diagnostics
|
|
180
|
+
const ts = loaded.compiler
|
|
181
|
+
if (ts === undefined) return didNotRun(code, title)
|
|
182
|
+
const findings: Diagnostic[] = []
|
|
183
|
+
for (const file of ctx.project.source.files) {
|
|
184
|
+
const parsed = parsedFile(ts, ctx.project.source, file)
|
|
185
|
+
if (parsed !== undefined) onFile(ts, { file, ...parsed }, findings)
|
|
186
|
+
}
|
|
187
|
+
return findings
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** {@link scanFiles} over every node of each file, children included. */
|
|
191
|
+
function scanNodes(
|
|
192
|
+
ctx: RuleContext,
|
|
193
|
+
code: string,
|
|
194
|
+
title: string,
|
|
195
|
+
onNode: (ts: typeof TSApi, node: TSApi.Node, source: ScannedFile, findings: Diagnostic[]) => void,
|
|
196
|
+
): Promise<readonly Diagnostic[]> {
|
|
197
|
+
return scanFiles(ctx, code, title, (ts, source, findings) => {
|
|
198
|
+
const visit = (node: TSApi.Node): void => {
|
|
199
|
+
onNode(ts, node, source, findings)
|
|
200
|
+
ts.forEachChild(node, visit)
|
|
201
|
+
}
|
|
202
|
+
visit(source.tree)
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
|
|
161
206
|
function parse(ts: typeof TSApi, file: string, source: string): TSApi.SourceFile {
|
|
162
207
|
return ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true, scriptKindOf(ts, file))
|
|
163
208
|
}
|
|
@@ -249,6 +294,21 @@ function bindsName(ts: typeof TSApi, binding: TSApi.BindingName, name: string):
|
|
|
249
294
|
)
|
|
250
295
|
}
|
|
251
296
|
|
|
297
|
+
/** Whether `node` is a loop or a catch clause that declares `name` for its body. */
|
|
298
|
+
function loopOrCatchBinds(ts: typeof TSApi, node: TSApi.Node, name: string): boolean {
|
|
299
|
+
if (ts.isForStatement(node) || ts.isForOfStatement(node) || ts.isForInStatement(node))
|
|
300
|
+
return (
|
|
301
|
+
node.initializer !== undefined &&
|
|
302
|
+
ts.isVariableDeclarationList(node.initializer) &&
|
|
303
|
+
node.initializer.declarations.some((d) => bindsName(ts, d.name, name))
|
|
304
|
+
)
|
|
305
|
+
return (
|
|
306
|
+
ts.isCatchClause(node) &&
|
|
307
|
+
node.variableDeclaration !== undefined &&
|
|
308
|
+
bindsName(ts, node.variableDeclaration.name, name)
|
|
309
|
+
)
|
|
310
|
+
}
|
|
311
|
+
|
|
252
312
|
/**
|
|
253
313
|
* Whether `id` names a plain parameter of an enclosing function, not a value the file builds: the
|
|
254
314
|
* nearest declaration of the name, walking out, must be that parameter. A loop or catch variable, a
|
|
@@ -265,19 +325,7 @@ function isParameterRef(ts: typeof TSApi, id: TSApi.Identifier): boolean {
|
|
|
265
325
|
}
|
|
266
326
|
if ((ts.isBlock(node) || ts.isSourceFile(node)) && declaresIn(ts, node.statements, id.text))
|
|
267
327
|
return false
|
|
268
|
-
if (
|
|
269
|
-
(ts.isForStatement(node) || ts.isForOfStatement(node) || ts.isForInStatement(node)) &&
|
|
270
|
-
node.initializer !== undefined &&
|
|
271
|
-
ts.isVariableDeclarationList(node.initializer) &&
|
|
272
|
-
node.initializer.declarations.some((d) => bindsName(ts, d.name, id.text))
|
|
273
|
-
)
|
|
274
|
-
return false
|
|
275
|
-
if (
|
|
276
|
-
ts.isCatchClause(node) &&
|
|
277
|
-
node.variableDeclaration !== undefined &&
|
|
278
|
-
bindsName(ts, node.variableDeclaration.name, id.text)
|
|
279
|
-
)
|
|
280
|
-
return false
|
|
328
|
+
if (loopOrCatchBinds(ts, node, id.text)) return false
|
|
281
329
|
}
|
|
282
330
|
return false
|
|
283
331
|
}
|
|
@@ -330,19 +378,7 @@ function constInitializer(ts: typeof TSApi, id: TSApi.Identifier): TSApi.Express
|
|
|
330
378
|
for (let node: TSApi.Node | undefined = id.parent; node !== undefined; node = node.parent) {
|
|
331
379
|
if (ts.isFunctionLike(node) && node.parameters.some((p) => bindsName(ts, p.name, id.text)))
|
|
332
380
|
return undefined
|
|
333
|
-
if (
|
|
334
|
-
(ts.isForStatement(node) || ts.isForOfStatement(node) || ts.isForInStatement(node)) &&
|
|
335
|
-
node.initializer !== undefined &&
|
|
336
|
-
ts.isVariableDeclarationList(node.initializer) &&
|
|
337
|
-
node.initializer.declarations.some((d) => bindsName(ts, d.name, id.text))
|
|
338
|
-
)
|
|
339
|
-
return undefined
|
|
340
|
-
if (
|
|
341
|
-
ts.isCatchClause(node) &&
|
|
342
|
-
node.variableDeclaration !== undefined &&
|
|
343
|
-
bindsName(ts, node.variableDeclaration.name, id.text)
|
|
344
|
-
)
|
|
345
|
-
return undefined
|
|
381
|
+
if (loopOrCatchBinds(ts, node, id.text)) return undefined
|
|
346
382
|
if (!ts.isBlock(node) && !ts.isSourceFile(node)) continue
|
|
347
383
|
for (const statement of node.statements) {
|
|
348
384
|
if (!ts.isVariableStatement(statement)) continue
|
|
@@ -491,69 +527,60 @@ export function rewriteSecretComparisons(
|
|
|
491
527
|
export const secretComparisonRule: CheckRule = {
|
|
492
528
|
code: "NF-S002",
|
|
493
529
|
title: "Non-constant-time secret comparison",
|
|
494
|
-
|
|
495
|
-
const loaded = await loadRuleTypeScript(ctx)
|
|
496
|
-
if (loaded.diagnostics !== undefined) return loaded.diagnostics
|
|
497
|
-
const ts = loaded.compiler
|
|
498
|
-
if (ts === undefined) return didNotRun("NF-S002", "Non-constant-time secret comparison scan")
|
|
499
|
-
const findings: Diagnostic[] = []
|
|
530
|
+
scan(ctx) {
|
|
500
531
|
const webDirs = createWebAppProbe(ctx.root)
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
532
|
+
return scanFiles(
|
|
533
|
+
ctx,
|
|
534
|
+
"NF-S002",
|
|
535
|
+
"Non-constant-time secret comparison scan",
|
|
536
|
+
(ts, { file, tree, lines }, findings) => {
|
|
537
|
+
const browser = provenBrowserFile(ctx.root, file, webDirs)
|
|
538
|
+
for (const { left, right, line } of secretComparisons(ts, tree, browser)) {
|
|
539
|
+
const reviewed = expectedReason(lines, line, "NF-S002") !== undefined
|
|
540
|
+
findings.push(
|
|
541
|
+
diagnostic({
|
|
542
|
+
code: "NF-S002",
|
|
543
|
+
severity: reviewed ? "info" : browser ? "warn" : "error",
|
|
544
|
+
file,
|
|
545
|
+
line,
|
|
546
|
+
message: reviewed
|
|
547
|
+
? "secret comparison is expected here"
|
|
548
|
+
: unexpectedMessage(
|
|
549
|
+
"secret-like values must use a length check and timing-safe comparison",
|
|
550
|
+
lines,
|
|
551
|
+
line,
|
|
552
|
+
"NF-S002",
|
|
553
|
+
),
|
|
554
|
+
evidence: [
|
|
555
|
+
left ?? right ?? "secret comparison",
|
|
556
|
+
...expectationEvidence(lines, line, "NF-S002"),
|
|
557
|
+
],
|
|
558
|
+
...(reviewed
|
|
559
|
+
? {}
|
|
560
|
+
: {
|
|
561
|
+
fix: {
|
|
562
|
+
recipe: "security.timing-safe-equal",
|
|
563
|
+
command: "nifra fix --code NF-S002",
|
|
564
|
+
},
|
|
565
|
+
}),
|
|
566
|
+
verify: "nifra check --lints-only",
|
|
567
|
+
}),
|
|
568
|
+
)
|
|
569
|
+
}
|
|
570
|
+
},
|
|
571
|
+
)
|
|
540
572
|
},
|
|
541
573
|
}
|
|
542
574
|
|
|
543
575
|
export const piiLogRule: CheckRule = {
|
|
544
576
|
code: "NF-S003",
|
|
545
577
|
title: "Sensitive value in log call",
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
for (const file of ctx.project.source.files) {
|
|
553
|
-
const parsed = parsedFile(ts, ctx.project.source, file)
|
|
554
|
-
if (parsed === undefined) continue
|
|
555
|
-
const { tree, lines } = parsed
|
|
556
|
-
const visit = (node: TSApi.Node): void => {
|
|
578
|
+
scan: (ctx) =>
|
|
579
|
+
scanNodes(
|
|
580
|
+
ctx,
|
|
581
|
+
"NF-S003",
|
|
582
|
+
"Sensitive-value-in-log scan",
|
|
583
|
+
(ts, node, { file, tree, lines }, findings) => {
|
|
557
584
|
if (ts.isCallExpression(node)) {
|
|
558
585
|
const expression = node.expression
|
|
559
586
|
const callee = ts.isPropertyAccessExpression(expression)
|
|
@@ -587,12 +614,8 @@ export const piiLogRule: CheckRule = {
|
|
|
587
614
|
}
|
|
588
615
|
}
|
|
589
616
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
visit(tree)
|
|
593
|
-
}
|
|
594
|
-
return findings
|
|
595
|
-
},
|
|
617
|
+
},
|
|
618
|
+
),
|
|
596
619
|
}
|
|
597
620
|
|
|
598
621
|
/**
|
|
@@ -720,59 +743,55 @@ function isDenial(ts: typeof TSApi, expression: TSApi.Expression, authenticator:
|
|
|
720
743
|
export const failOpenGateRule: CheckRule = {
|
|
721
744
|
code: "NF-S001",
|
|
722
745
|
title: "Fail-open gate",
|
|
723
|
-
|
|
724
|
-
const loaded = await loadRuleTypeScript(ctx)
|
|
725
|
-
if (loaded.diagnostics !== undefined) return loaded.diagnostics
|
|
726
|
-
const ts = loaded.compiler
|
|
727
|
-
if (ts === undefined) return didNotRun("NF-S001", "Fail-open gate scan")
|
|
728
|
-
const findings: Diagnostic[] = []
|
|
746
|
+
scan(ctx) {
|
|
729
747
|
const webDirs = createWebAppProbe(ctx.root)
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
if (
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
748
|
+
return scanFiles(
|
|
749
|
+
ctx,
|
|
750
|
+
"NF-S001",
|
|
751
|
+
"Fail-open gate scan",
|
|
752
|
+
(ts, { file, tree, lines }, findings) => {
|
|
753
|
+
let browser: boolean | undefined
|
|
754
|
+
const visit = (node: TSApi.Node): void => {
|
|
755
|
+
if (ts.isCatchClause(node)) {
|
|
756
|
+
let parent: TSApi.Node | undefined = node.parent
|
|
757
|
+
while (parent !== undefined && !ts.isFunctionLike(parent)) parent = parent.parent
|
|
758
|
+
const name = parent === undefined ? undefined : functionName(ts, parent)
|
|
759
|
+
if (name !== undefined && GATE_NAMES.some((gate) => gate.test(name))) {
|
|
760
|
+
if (!failsClosed(ts, node.block, name)) {
|
|
761
|
+
const line = tree.getLineAndCharacterOfPosition(node.getStart(tree)).line + 1
|
|
762
|
+
const reviewed = expectedReason(lines, line, "NF-S001") !== undefined
|
|
763
|
+
browser ??= provenBrowserFile(ctx.root, file, webDirs)
|
|
764
|
+
findings.push(
|
|
765
|
+
diagnostic({
|
|
766
|
+
code: "NF-S001",
|
|
767
|
+
severity: reviewed ? "info" : browser ? "warn" : "error",
|
|
768
|
+
file,
|
|
769
|
+
line,
|
|
770
|
+
message: reviewed
|
|
771
|
+
? "gate catch block is expected here"
|
|
772
|
+
: unexpectedMessage(
|
|
773
|
+
"gate catch blocks must rethrow or return an explicit denial",
|
|
774
|
+
lines,
|
|
775
|
+
line,
|
|
776
|
+
"NF-S001",
|
|
777
|
+
),
|
|
778
|
+
evidence: [
|
|
779
|
+
name,
|
|
780
|
+
"catch block has no denial or rethrow",
|
|
781
|
+
...(browser ? ["browser code: the server's own gate decides"] : []),
|
|
782
|
+
...expectationEvidence(lines, line, "NF-S001"),
|
|
783
|
+
],
|
|
784
|
+
verify: "nifra check --lints-only",
|
|
785
|
+
}),
|
|
786
|
+
)
|
|
787
|
+
}
|
|
768
788
|
}
|
|
769
789
|
}
|
|
790
|
+
ts.forEachChild(node, visit)
|
|
770
791
|
}
|
|
771
|
-
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
}
|
|
775
|
-
return findings
|
|
792
|
+
visit(tree)
|
|
793
|
+
},
|
|
794
|
+
)
|
|
776
795
|
},
|
|
777
796
|
}
|
|
778
797
|
|
|
@@ -794,17 +813,12 @@ function usesParam(ts: typeof TSApi, body: TSApi.Node, param: string): boolean {
|
|
|
794
813
|
export const corsOriginPredicateRule: CheckRule = {
|
|
795
814
|
code: "NF-S004",
|
|
796
815
|
title: "CORS origin predicate ignores the origin",
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
for (const file of ctx.project.source.files) {
|
|
804
|
-
const parsed = parsedFile(ts, ctx.project.source, file)
|
|
805
|
-
if (parsed === undefined) continue
|
|
806
|
-
const { tree, lines } = parsed
|
|
807
|
-
const visit = (node: TSApi.Node): void => {
|
|
816
|
+
scan: (ctx) =>
|
|
817
|
+
scanNodes(
|
|
818
|
+
ctx,
|
|
819
|
+
"NF-S004",
|
|
820
|
+
"CORS origin predicate scan",
|
|
821
|
+
(ts, node, { file, tree, lines }, findings) => {
|
|
808
822
|
if (ts.isCallExpression(node) && nameOf(ts, node.expression) === "cors") {
|
|
809
823
|
const arg = node.arguments[0]
|
|
810
824
|
if (arg !== undefined && ts.isObjectLiteralExpression(arg)) {
|
|
@@ -854,28 +868,19 @@ export const corsOriginPredicateRule: CheckRule = {
|
|
|
854
868
|
}
|
|
855
869
|
}
|
|
856
870
|
}
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
visit(tree)
|
|
860
|
-
}
|
|
861
|
-
return findings
|
|
862
|
-
},
|
|
871
|
+
},
|
|
872
|
+
),
|
|
863
873
|
}
|
|
864
874
|
|
|
865
875
|
export const externalRedirectRule: CheckRule = {
|
|
866
876
|
code: "NF-S005",
|
|
867
877
|
title: "External redirect opt-out",
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
for (const file of ctx.project.source.files) {
|
|
875
|
-
const parsed = parsedFile(ts, ctx.project.source, file)
|
|
876
|
-
if (parsed === undefined) continue
|
|
877
|
-
const { tree, lines } = parsed
|
|
878
|
-
const visit = (node: TSApi.Node): void => {
|
|
878
|
+
scan: (ctx) =>
|
|
879
|
+
scanNodes(
|
|
880
|
+
ctx,
|
|
881
|
+
"NF-S005",
|
|
882
|
+
"External redirect opt-out scan",
|
|
883
|
+
(ts, node, { file, tree, lines }, findings) => {
|
|
879
884
|
if (ts.isCallExpression(node) && nameOf(ts, node.expression) === "redirect") {
|
|
880
885
|
for (const arg of node.arguments) {
|
|
881
886
|
if (!ts.isObjectLiteralExpression(arg)) continue
|
|
@@ -909,12 +914,8 @@ export const externalRedirectRule: CheckRule = {
|
|
|
909
914
|
}
|
|
910
915
|
}
|
|
911
916
|
}
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
visit(tree)
|
|
915
|
-
}
|
|
916
|
-
return findings
|
|
917
|
-
},
|
|
917
|
+
},
|
|
918
|
+
),
|
|
918
919
|
}
|
|
919
920
|
|
|
920
921
|
const ESCAPE_HATCHES: Readonly<Record<string, string>> = {
|
|
@@ -929,17 +930,12 @@ const ESCAPE_HATCHES: Readonly<Record<string, string>> = {
|
|
|
929
930
|
export const assuranceEscapeHatchRule: CheckRule = {
|
|
930
931
|
code: "NF-S006",
|
|
931
932
|
title: "Security escape hatch enabled",
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
for (const file of ctx.project.source.files) {
|
|
939
|
-
const parsed = parsedFile(ts, ctx.project.source, file)
|
|
940
|
-
if (parsed === undefined) continue
|
|
941
|
-
const { tree, lines } = parsed
|
|
942
|
-
const visit = (node: TSApi.Node): void => {
|
|
933
|
+
scan: (ctx) =>
|
|
934
|
+
scanNodes(
|
|
935
|
+
ctx,
|
|
936
|
+
"NF-S006",
|
|
937
|
+
"Security escape hatch scan",
|
|
938
|
+
(ts, node, { file, tree, lines }, findings) => {
|
|
943
939
|
if (ts.isPropertyAssignment(node) && node.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
944
940
|
const name = nameOf(ts, node.name)
|
|
945
941
|
const consequence = name !== undefined ? ESCAPE_HATCHES[name] : undefined
|
|
@@ -961,12 +957,8 @@ export const assuranceEscapeHatchRule: CheckRule = {
|
|
|
961
957
|
)
|
|
962
958
|
}
|
|
963
959
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
visit(tree)
|
|
967
|
-
}
|
|
968
|
-
return findings
|
|
969
|
-
},
|
|
960
|
+
},
|
|
961
|
+
),
|
|
970
962
|
}
|
|
971
963
|
|
|
972
964
|
const COOKIE_PREFIX = /^__(?:Host|Secure)-/
|
|
@@ -974,59 +966,45 @@ const COOKIE_PREFIX = /^__(?:Host|Secure)-/
|
|
|
974
966
|
export const unprefixedSecureCookieRule: CheckRule = {
|
|
975
967
|
code: "NF-S007",
|
|
976
968
|
title: "Secure cookie without a __Host-/__Secure- prefix",
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
969
|
+
scan: (ctx) =>
|
|
970
|
+
scanNodes(ctx, "NF-S007", "Secure cookie prefix scan", (ts, node, { file, tree }, findings) => {
|
|
971
|
+
if (ts.isCallExpression(node)) {
|
|
972
|
+
const callee = nameOf(ts, node.expression)
|
|
973
|
+
if (callee === "cookie" || callee === "serializeCookie") {
|
|
974
|
+
const nameArg = node.arguments[0]
|
|
975
|
+
const hasPrefix =
|
|
976
|
+
nameArg !== undefined &&
|
|
977
|
+
ts.isStringLiteralLike(nameArg) &&
|
|
978
|
+
COOKIE_PREFIX.test(nameArg.text)
|
|
979
|
+
const secure = node.arguments.some(
|
|
980
|
+
(arg) =>
|
|
981
|
+
ts.isObjectLiteralExpression(arg) &&
|
|
982
|
+
arg.properties.some(
|
|
983
|
+
(prop) =>
|
|
984
|
+
ts.isPropertyAssignment(prop) &&
|
|
985
|
+
nameOf(ts, prop.name) === "secure" &&
|
|
986
|
+
prop.initializer.kind === ts.SyntaxKind.TrueKeyword,
|
|
987
|
+
),
|
|
988
|
+
)
|
|
989
|
+
// Only literal names are judged - a dynamic name can't be checked for a prefix.
|
|
990
|
+
if (secure && !hasPrefix && nameArg !== undefined && ts.isStringLiteralLike(nameArg)) {
|
|
991
|
+
const line = tree.getLineAndCharacterOfPosition(node.getStart(tree)).line + 1
|
|
992
|
+
findings.push(
|
|
993
|
+
diagnostic({
|
|
994
|
+
code: "NF-S007",
|
|
995
|
+
severity: "info",
|
|
996
|
+
file,
|
|
997
|
+
line,
|
|
998
|
+
message:
|
|
999
|
+
"Secure cookie without a __Host-/__Secure- prefix - a prefix stops subdomains and insecure contexts from shadowing it",
|
|
1000
|
+
evidence: [nameArg.text],
|
|
1001
|
+
verify: "nifra check --lints-only",
|
|
1002
|
+
}),
|
|
1005
1003
|
)
|
|
1006
|
-
// Only literal names are judged - a dynamic name can't be checked for a prefix.
|
|
1007
|
-
if (secure && !hasPrefix && nameArg !== undefined && ts.isStringLiteralLike(nameArg)) {
|
|
1008
|
-
const line = tree.getLineAndCharacterOfPosition(node.getStart(tree)).line + 1
|
|
1009
|
-
findings.push(
|
|
1010
|
-
diagnostic({
|
|
1011
|
-
code: "NF-S007",
|
|
1012
|
-
severity: "info",
|
|
1013
|
-
file,
|
|
1014
|
-
line,
|
|
1015
|
-
message:
|
|
1016
|
-
"Secure cookie without a __Host-/__Secure- prefix - a prefix stops subdomains and insecure contexts from shadowing it",
|
|
1017
|
-
evidence: [nameArg.text],
|
|
1018
|
-
verify: "nifra check --lints-only",
|
|
1019
|
-
}),
|
|
1020
|
-
)
|
|
1021
|
-
}
|
|
1022
1004
|
}
|
|
1023
1005
|
}
|
|
1024
|
-
ts.forEachChild(node, visit)
|
|
1025
1006
|
}
|
|
1026
|
-
|
|
1027
|
-
}
|
|
1028
|
-
return findings
|
|
1029
|
-
},
|
|
1007
|
+
}),
|
|
1030
1008
|
}
|
|
1031
1009
|
|
|
1032
1010
|
/** Reads the backend the contract-lock check loaded; this rule runs no project code of its own. */
|
|
@@ -1089,17 +1067,12 @@ function callsJsonParse(ts: typeof TSApi, node: TSApi.Node): boolean {
|
|
|
1089
1067
|
export const unvalidatedWsFrameRule: CheckRule = {
|
|
1090
1068
|
code: "NF-S009",
|
|
1091
1069
|
title: "WebSocket frames parsed without a messageSchema",
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
for (const file of ctx.project.source.files) {
|
|
1099
|
-
const parsed = parsedFile(ts, ctx.project.source, file)
|
|
1100
|
-
if (parsed === undefined) continue
|
|
1101
|
-
const { tree, lines } = parsed
|
|
1102
|
-
const visit = (node: TSApi.Node): void => {
|
|
1070
|
+
scan: (ctx) =>
|
|
1071
|
+
scanNodes(
|
|
1072
|
+
ctx,
|
|
1073
|
+
"NF-S009",
|
|
1074
|
+
"WebSocket messageSchema scan",
|
|
1075
|
+
(ts, node, { file, tree, lines }, findings) => {
|
|
1103
1076
|
if (
|
|
1104
1077
|
ts.isCallExpression(node) &&
|
|
1105
1078
|
ts.isPropertyAccessExpression(node.expression) &&
|
|
@@ -1136,12 +1109,8 @@ export const unvalidatedWsFrameRule: CheckRule = {
|
|
|
1136
1109
|
}
|
|
1137
1110
|
}
|
|
1138
1111
|
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
visit(tree)
|
|
1142
|
-
}
|
|
1143
|
-
return findings
|
|
1144
|
-
},
|
|
1112
|
+
},
|
|
1113
|
+
),
|
|
1145
1114
|
}
|
|
1146
1115
|
|
|
1147
1116
|
export const securityRules = Object.freeze([
|
package/src/rules/zones.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* file importing one in no zone, backend code importing frontend code, and shared code importing
|
|
8
8
|
* anything but shared code. NF-C029 owns private environment reads in browser code.
|
|
9
9
|
*/
|
|
10
|
-
import { existsSync, readFileSync
|
|
10
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
11
11
|
import { isAbsolute, join, relative } from "node:path"
|
|
12
12
|
import {
|
|
13
13
|
browserDenial,
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
withApiKindHint,
|
|
38
38
|
} from "../internal/nifra-project.ts"
|
|
39
39
|
import { createSpecifierResolver } from "../internal/project-specifiers.ts"
|
|
40
|
+
import { realpathOrSelf } from "../internal/realpath-or-self.ts"
|
|
40
41
|
import { createSourceFacts } from "../internal/source-facts.ts"
|
|
41
42
|
import type { CheckRule, RuleContext } from "./index.ts"
|
|
42
43
|
import { loadRuleTypeScript } from "./typescript.ts"
|
|
@@ -147,18 +148,10 @@ export function zonedFiles(ctx: RuleContext): {
|
|
|
147
148
|
return { files, classifierFor, configErrors }
|
|
148
149
|
}
|
|
149
150
|
|
|
150
|
-
const real = (path: string): string => {
|
|
151
|
-
try {
|
|
152
|
-
return realpathSync(path)
|
|
153
|
-
} catch {
|
|
154
|
-
return path
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
151
|
/** Where a resolved import lands, as the project names it. Both sides are real paths: a checkout
|
|
159
152
|
* reached through a symlink (`/var` -> `/private/var` on macOS) still names files project-relative. */
|
|
160
153
|
function display(root: string, file: string): string {
|
|
161
|
-
const rel = relative(
|
|
154
|
+
const rel = relative(realpathOrSelf(root), realpathOrSelf(file)).replaceAll("\\", "/")
|
|
162
155
|
return rel.startsWith("../") || isAbsolute(rel) ? file : rel
|
|
163
156
|
}
|
|
164
157
|
|