@nifrajs/cli 5.16.0 → 5.18.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 +67 -0
- package/dist/check-diagnostics.d.ts +7 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +3 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan-sql.d.ts +95 -0
- package/dist/check-scan-sql.d.ts.map +1 -0
- package/dist/check-scan-sql.js +1190 -0
- package/dist/check-scan-sql.js.map +1 -0
- package/dist/check-scan.d.ts +5 -93
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +20 -1207
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +9 -0
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +2 -6
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +249 -80
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +3 -0
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +18 -4
- package/dist/command-catalog.js.map +1 -1
- package/dist/frontend-guidance.js +1 -1
- package/dist/frontend-guidance.js.map +1 -1
- package/dist/internal/a11y-element.d.ts +33 -0
- package/dist/internal/a11y-element.d.ts.map +1 -0
- package/dist/internal/a11y-element.js +124 -0
- package/dist/internal/a11y-element.js.map +1 -0
- package/dist/internal/a11y-jsx.d.ts +12 -0
- package/dist/internal/a11y-jsx.d.ts.map +1 -0
- package/dist/internal/a11y-jsx.js +42 -0
- package/dist/internal/a11y-jsx.js.map +1 -0
- package/dist/internal/a11y-template.d.ts +11 -0
- package/dist/internal/a11y-template.d.ts.map +1 -0
- package/dist/internal/a11y-template.js +56 -0
- package/dist/internal/a11y-template.js.map +1 -0
- package/dist/internal/aria-data.d.ts +23 -0
- package/dist/internal/aria-data.d.ts.map +1 -0
- package/dist/internal/aria-data.js +220 -0
- package/dist/internal/aria-data.js.map +1 -0
- package/dist/internal/edit-distance.d.ts +3 -0
- package/dist/internal/edit-distance.d.ts.map +1 -0
- package/dist/internal/edit-distance.js +12 -0
- package/dist/internal/edit-distance.js.map +1 -0
- package/dist/internal/imported-as.d.ts +10 -0
- package/dist/internal/imported-as.d.ts.map +1 -0
- package/dist/internal/imported-as.js +23 -0
- package/dist/internal/imported-as.js.map +1 -0
- package/dist/internal/source-facts.d.ts +3 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +2 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/template-markup.d.ts +58 -0
- package/dist/internal/template-markup.d.ts.map +1 -0
- package/dist/internal/template-markup.js +221 -0
- package/dist/internal/template-markup.js.map +1 -0
- package/dist/internal/typescript-import.d.ts.map +1 -1
- package/dist/internal/typescript-import.js +11 -0
- package/dist/internal/typescript-import.js.map +1 -1
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +37 -23
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +5 -3
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-root.js +1 -1
- package/dist/mcp-root.js.map +1 -1
- package/dist/mcp-ws.d.ts.map +1 -1
- package/dist/mcp-ws.js +3 -2
- package/dist/mcp-ws.js.map +1 -1
- package/dist/migrate-layout-config.d.ts +63 -0
- package/dist/migrate-layout-config.d.ts.map +1 -0
- package/dist/migrate-layout-config.js +507 -0
- package/dist/migrate-layout-config.js.map +1 -0
- package/dist/migrate-layout-split.d.ts +46 -0
- package/dist/migrate-layout-split.d.ts.map +1 -0
- package/dist/migrate-layout-split.js +687 -0
- package/dist/migrate-layout-split.js.map +1 -0
- package/dist/migrate-layout.d.ts +4 -24
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +8 -1183
- package/dist/migrate-layout.js.map +1 -1
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +78 -10
- package/dist/output-schemas.js.map +1 -1
- package/dist/recipes/5.17.0.d.ts +10 -0
- package/dist/recipes/5.17.0.d.ts.map +1 -0
- package/dist/recipes/5.17.0.js +20 -0
- package/dist/recipes/5.17.0.js.map +1 -0
- package/dist/recipes/5.18.0.d.ts +9 -0
- package/dist/recipes/5.18.0.d.ts.map +1 -0
- package/dist/recipes/5.18.0.js +56 -0
- package/dist/recipes/5.18.0.js.map +1 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +4 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +6 -0
- package/dist/review.js.map +1 -1
- package/dist/rules/a11y.d.ts +5 -0
- package/dist/rules/a11y.d.ts.map +1 -0
- package/dist/rules/a11y.js +78 -0
- package/dist/rules/a11y.js.map +1 -0
- package/dist/rules/codes.d.ts +6 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +6 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/comment-markers.js +1 -1
- package/dist/rules/comment-markers.js.map +1 -1
- package/dist/rules/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +30 -0
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/host-exposure.d.ts +23 -0
- package/dist/rules/host-exposure.d.ts.map +1 -0
- package/dist/rules/host-exposure.js +380 -0
- package/dist/rules/host-exposure.js.map +1 -0
- package/dist/rules/internal-links.d.ts.map +1 -1
- package/dist/rules/internal-links.js +16 -141
- package/dist/rules/internal-links.js.map +1 -1
- package/dist/rules/islands.d.ts +54 -0
- package/dist/rules/islands.d.ts.map +1 -1
- package/dist/rules/islands.js +577 -80
- package/dist/rules/islands.js.map +1 -1
- package/dist/rules/security.d.ts +1 -0
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +34 -7
- package/dist/rules/security.js.map +1 -1
- package/dist/runtime-differences.js +3 -3
- package/dist/runtime-differences.js.map +1 -1
- package/dist/scaffold.d.ts +1 -1
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +2 -2
- package/dist/scaffold.js.map +1 -1
- package/dist/source-rewrites.d.ts.map +1 -1
- package/dist/source-rewrites.js +2 -19
- package/dist/source-rewrites.js.map +1 -1
- package/docs/examples.json +4 -4
- package/docs/llms-full.txt +443 -46
- package/docs/types.json +490 -66
- package/package.json +12 -12
- package/src/check-diagnostics.ts +11 -0
- package/src/check-scan-sql.ts +1746 -0
- package/src/check-scan.ts +34 -1754
- package/src/check.ts +10 -1
- package/src/cli.ts +258 -98
- package/src/command-catalog.ts +21 -4
- package/src/frontend-guidance.ts +1 -1
- package/src/internal/a11y-element.ts +227 -0
- package/src/internal/a11y-jsx.ts +54 -0
- package/src/internal/a11y-template.ts +74 -0
- package/src/internal/aria-data.ts +242 -0
- package/src/internal/edit-distance.ts +16 -0
- package/src/internal/imported-as.ts +30 -0
- package/src/internal/source-facts.ts +4 -0
- package/src/internal/template-markup.ts +270 -0
- package/src/internal/typescript-import.ts +15 -0
- package/src/mcp-exec.ts +43 -22
- package/src/mcp-http.ts +1 -1
- package/src/mcp-io.ts +5 -3
- package/src/mcp-root.ts +1 -1
- package/src/mcp-ws.ts +3 -2
- package/src/migrate-layout-config.ts +615 -0
- package/src/migrate-layout-split.ts +870 -0
- package/src/migrate-layout.ts +37 -1468
- package/src/output-schemas.ts +85 -17
- package/src/recipes/5.17.0.ts +28 -0
- package/src/recipes/5.18.0.ts +63 -0
- package/src/recipes/index.ts +4 -0
- package/src/review.ts +6 -0
- package/src/rules/a11y.ts +119 -0
- package/src/rules/codes.ts +6 -0
- package/src/rules/comment-markers.ts +2 -2
- package/src/rules/explanations.ts +30 -0
- package/src/rules/host-exposure.ts +531 -0
- package/src/rules/internal-links.ts +21 -154
- package/src/rules/islands.ts +698 -86
- package/src/rules/security.ts +48 -7
- package/src/runtime-differences.ts +3 -3
- package/src/scaffold.ts +3 -3
- package/src/source-rewrites.ts +2 -15
package/src/rules/security.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
commentBlockHasMarker,
|
|
10
10
|
MISSING_EXPECTATION_REASON,
|
|
11
11
|
} from "./comment-markers.ts"
|
|
12
|
+
import { createHostExposureRule } from "./host-exposure.ts"
|
|
12
13
|
import type { CheckRule, RuleContext, SourceIndex } from "./index.ts"
|
|
13
14
|
import { loadRuleTypeScript } from "./typescript.ts"
|
|
14
15
|
|
|
@@ -469,15 +470,48 @@ function timingSafeHelper(file: string): string {
|
|
|
469
470
|
'import { timingSafeEqual as nifraTimingSafeEqualBytes } from "node:crypto"',
|
|
470
471
|
"",
|
|
471
472
|
typed
|
|
472
|
-
? "function nifraTimingSafeEqual(left:
|
|
473
|
+
? "function nifraTimingSafeEqual(left: unknown, right: unknown): boolean {"
|
|
473
474
|
: "function nifraTimingSafeEqual(left, right) {",
|
|
474
|
-
|
|
475
|
-
"
|
|
476
|
-
"
|
|
475
|
+
' if (typeof left !== "string" || typeof right !== "string") return left === right',
|
|
476
|
+
" if (left.length !== right.length) return false",
|
|
477
|
+
" const leftUnits = new Uint16Array(left.length)",
|
|
478
|
+
" const rightUnits = new Uint16Array(right.length)",
|
|
479
|
+
" for (let index = 0; index < left.length; index++) {",
|
|
480
|
+
" leftUnits[index] = left.charCodeAt(index)",
|
|
481
|
+
" rightUnits[index] = right.charCodeAt(index)",
|
|
482
|
+
" }",
|
|
483
|
+
" return nifraTimingSafeEqualBytes(leftUnits, rightUnits)",
|
|
477
484
|
"}",
|
|
478
485
|
].join("\n")
|
|
479
486
|
}
|
|
480
487
|
|
|
488
|
+
function canRewriteSecretComparison(
|
|
489
|
+
ts: typeof TSApi,
|
|
490
|
+
tree: TSApi.SourceFile,
|
|
491
|
+
browser: boolean,
|
|
492
|
+
): boolean {
|
|
493
|
+
const fileName = tree.fileName.replaceAll("\\", "/").toLowerCase()
|
|
494
|
+
return (
|
|
495
|
+
!browser &&
|
|
496
|
+
!`/${fileName}`.includes("/shared/") &&
|
|
497
|
+
!/\.shared\.[^./]+$/.test(fileName) &&
|
|
498
|
+
tree.statements.some(
|
|
499
|
+
(statement) =>
|
|
500
|
+
ts.isImportDeclaration(statement) &&
|
|
501
|
+
statement.importClause?.isTypeOnly !== true &&
|
|
502
|
+
ts.isStringLiteralLike(statement.moduleSpecifier) &&
|
|
503
|
+
statement.moduleSpecifier.text === "node:crypto",
|
|
504
|
+
)
|
|
505
|
+
)
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function isStrictSecretComparison(ts: typeof TSApi, node: TSApi.BinaryExpression): boolean {
|
|
509
|
+
return (
|
|
510
|
+
node.operatorToken.kind === ts.SyntaxKind.EqualsEqualsEqualsToken ||
|
|
511
|
+
node.operatorToken.kind === ts.SyntaxKind.ExclamationEqualsEqualsToken
|
|
512
|
+
)
|
|
513
|
+
}
|
|
514
|
+
|
|
481
515
|
/**
|
|
482
516
|
* Rewrite every unreviewed NF-S002 comparison in one file to `nifraTimingSafeEqual(left, right)` and
|
|
483
517
|
* add the helper once. Sites come from the syntax tree, not a reported line: the helper lands above
|
|
@@ -491,9 +525,12 @@ export function rewriteSecretComparisons(
|
|
|
491
525
|
browser: boolean,
|
|
492
526
|
): string {
|
|
493
527
|
const tree = parse(ts, file, source)
|
|
528
|
+
if (!canRewriteSecretComparison(ts, tree, browser)) return source
|
|
494
529
|
const lines = tree.text.split("\n")
|
|
495
530
|
const sites = secretComparisons(ts, tree, browser).filter(
|
|
496
|
-
(site) =>
|
|
531
|
+
(site) =>
|
|
532
|
+
isStrictSecretComparison(ts, site.node) &&
|
|
533
|
+
expectedReason(lines, site.line, "NF-S002") === undefined,
|
|
497
534
|
)
|
|
498
535
|
// A comparison nested inside another (`(token === a) === flag`) is left for the next run, so every
|
|
499
536
|
// edit below covers a disjoint range and applying them from the end keeps earlier offsets valid.
|
|
@@ -535,7 +572,8 @@ export const secretComparisonRule: CheckRule = {
|
|
|
535
572
|
"Non-constant-time secret comparison scan",
|
|
536
573
|
(ts, { file, tree, lines }, findings) => {
|
|
537
574
|
const browser = provenBrowserFile(ctx.root, file, webDirs)
|
|
538
|
-
|
|
575
|
+
const canRewrite = canRewriteSecretComparison(ts, tree, browser)
|
|
576
|
+
for (const { node, left, right, line } of secretComparisons(ts, tree, browser)) {
|
|
539
577
|
const reviewed = expectedReason(lines, line, "NF-S002") !== undefined
|
|
540
578
|
findings.push(
|
|
541
579
|
diagnostic({
|
|
@@ -555,7 +593,7 @@ export const secretComparisonRule: CheckRule = {
|
|
|
555
593
|
left ?? right ?? "secret comparison",
|
|
556
594
|
...expectationEvidence(lines, line, "NF-S002"),
|
|
557
595
|
],
|
|
558
|
-
...(reviewed
|
|
596
|
+
...(reviewed || !canRewrite || !isStrictSecretComparison(ts, node)
|
|
559
597
|
? {}
|
|
560
598
|
: {
|
|
561
599
|
fix: {
|
|
@@ -1113,6 +1151,8 @@ export const unvalidatedWsFrameRule: CheckRule = {
|
|
|
1113
1151
|
),
|
|
1114
1152
|
}
|
|
1115
1153
|
|
|
1154
|
+
export const hostExposureRule = createHostExposureRule(parsedFile)
|
|
1155
|
+
|
|
1116
1156
|
export const securityRules = Object.freeze([
|
|
1117
1157
|
failOpenGateRule,
|
|
1118
1158
|
secretComparisonRule,
|
|
@@ -1123,4 +1163,5 @@ export const securityRules = Object.freeze([
|
|
|
1123
1163
|
unprefixedSecureCookieRule,
|
|
1124
1164
|
inputBeforeAuthenticationRule,
|
|
1125
1165
|
unvalidatedWsFrameRule,
|
|
1166
|
+
hostExposureRule,
|
|
1126
1167
|
])
|
|
@@ -65,12 +65,12 @@ export const RUNTIME_DIFFERENCES: readonly RuntimeEntry[] = [
|
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
id: "host-builds-url",
|
|
68
|
-
runtimes: ["deno", "bun"],
|
|
68
|
+
runtimes: ["deno", "bun", "node"],
|
|
69
69
|
symptom:
|
|
70
70
|
"`c.req.url` points at a path the client did not ask for, or is a relative string, after a request with an odd `Host` header such as `Host: h.test/admin#`.",
|
|
71
71
|
cause:
|
|
72
|
-
"With `Host: h.test/admin#` and no options set, Deno builds `Request.url` from the Host as received and routes `/admin`, Bun leaves `c.req.url` relative (`/url`), and `@nifrajs/node`
|
|
73
|
-
fix:
|
|
72
|
+
"With `Host: h.test/admin#` and no options set, Deno builds `Request.url` from the Host as received and routes `/admin`, Bun leaves `c.req.url` relative (`/url`), and `@nifrajs/node` and `@nifrajs/node-uws` answer `400 Bad Request` on their ordinary request paths (a fixed route that `@nifrajs/node-uws` registers with uWebSockets directly is answered before that check runs).",
|
|
73
|
+
fix: 'On Bun and Deno, set `validateHost: true` (`server({ validateHost: true })`) so Nifra answers `400 invalid_host` for a Host the request target cannot safely be built on. Off by default: reading the Host header measured about 6% of a bare route on Bun. The Node adapters already refuse these Hosts on their ordinary request paths. Behind a proxy that checks Host, leave it off and say so with `"hostTopology": "proxied"` in nifra.check.json: `nifra check` (NF-S010) warns about a listener that terminates TLS itself with no Host check.',
|
|
74
74
|
verify:
|
|
75
75
|
"`printf 'GET /url HTTP/1.1\\r\\nhost: h.test/admin#\\r\\n\\r\\n' | nc 127.0.0.1 <port>` against a route that echoes `c.req.url`.",
|
|
76
76
|
seeAlso: "validateHost invalid_host Host header",
|
package/src/scaffold.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type Framework = "react" | "preact" | "solid" | "vue" | "svelte" | "vanil
|
|
|
20
20
|
/** A scaffold flavour on top of the framework. `default` is the plain page stub; `stateful` only
|
|
21
21
|
* applies to vanilla and emits a reactive island (`bindIsland` state + `data-bind-*` markup + keyed
|
|
22
22
|
* `bindList`) instead of the static island stub - the small-app lane whose binding names, binding
|
|
23
|
-
* hosts and list keys NF-C047/C048/C022 check statically. */
|
|
23
|
+
* hosts and list keys NF-C047/C048/C022/C064/C065/C066 check statically. */
|
|
24
24
|
export type ScaffoldVariant = "default" | "stateful"
|
|
25
25
|
|
|
26
26
|
const EXT: Record<Framework, string> = {
|
|
@@ -274,7 +274,7 @@ export default function Page({ data }: Route.ComponentProps) {
|
|
|
274
274
|
// mountIslands({ todos })
|
|
275
275
|
//
|
|
276
276
|
// Cross-island coordination: one createIslandBus() closed over in each enhancer. nifra_docs("islands")
|
|
277
|
-
// has the full cookbook; \`nifra check\` runs NF-C047/C048/C022 over the page and client you write.
|
|
277
|
+
// has the full cookbook; \`nifra check\` runs NF-C047/C048/C022/C064/C065/C066 over the page and client you write.
|
|
278
278
|
`
|
|
279
279
|
}
|
|
280
280
|
|
|
@@ -315,7 +315,7 @@ export function scaffoldRoute(
|
|
|
315
315
|
file,
|
|
316
316
|
content: statefulStub(file),
|
|
317
317
|
backend,
|
|
318
|
-
note: `Create ${file} and ${backend.file} as a zero-runtime @nifrajs/web-vanilla route with a reactive island. ${ROUTE_CONTRACT}\nThe stub embeds the island client (bindIsland state + data-bind-* markup + keyed bindList); write it as the companion .client.ts. \`nifra check\` runs NF-C047/C048/C022 over the page and client; nifra_docs("islands") is the full cookbook.`,
|
|
318
|
+
note: `Create ${file} and ${backend.file} as a zero-runtime @nifrajs/web-vanilla route with a reactive island. ${ROUTE_CONTRACT}\nThe stub embeds the island client (bindIsland state + data-bind-* markup + keyed bindList); write it as the companion .client.ts. \`nifra check\` runs NF-C047/C048/C022/C064/C065/C066 over the page and client; nifra_docs("islands") is the full cookbook.`,
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
321
|
if (framework === "react" || framework === "preact" || framework === "solid") {
|
package/src/source-rewrites.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { isSameOriginPath } from "@nifrajs/core/pattern"
|
|
7
7
|
import type * as TS from "typescript"
|
|
8
8
|
import { codeUnitOrder } from "./internal/code-unit-order.ts"
|
|
9
|
+
import { importedAs } from "./internal/imported-as.ts"
|
|
9
10
|
import {
|
|
10
11
|
applyEdits,
|
|
11
12
|
type Edit,
|
|
@@ -449,21 +450,7 @@ function rewritePprOption(ts: typeof TS, file: string, text: string): RewriteRes
|
|
|
449
450
|
const manual: ManualSite[] = []
|
|
450
451
|
let count = 0
|
|
451
452
|
// The names createWebApp is imported under, and the names @nifrajs/web is imported as a namespace.
|
|
452
|
-
const locals =
|
|
453
|
-
const namespaces = new Set<string>()
|
|
454
|
-
for (const statement of tree.statements) {
|
|
455
|
-
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))
|
|
456
|
-
continue
|
|
457
|
-
if (statement.moduleSpecifier.text !== WEB) continue
|
|
458
|
-
const bindings = statement.importClause?.namedBindings
|
|
459
|
-
if (bindings === undefined) continue
|
|
460
|
-
if (ts.isNamespaceImport(bindings)) namespaces.add(bindings.name.text)
|
|
461
|
-
else {
|
|
462
|
-
for (const element of bindings.elements) {
|
|
463
|
-
if ((element.propertyName ?? element.name).text === WEB_APP) locals.add(element.name.text)
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
453
|
+
const { locals, namespaces } = importedAs(ts, tree, (from) => from === WEB, WEB_APP)
|
|
467
454
|
const isCreateWebApp = (callee: TS.Expression): boolean =>
|
|
468
455
|
(ts.isIdentifier(callee) && locals.has(callee.text)) ||
|
|
469
456
|
(ts.isPropertyAccessExpression(callee) &&
|