@noego/trust 0.5.0-dev.1 → 0.5.0-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -6
- package/dist/{baseline-Bkav9mS0.d.ts → baseline-DQGyHwig.d.ts} +35 -2
- package/dist/{chunk-7PY2Q6OX.js → chunk-EPWU2Q4U.js} +224 -3
- package/dist/chunk-EPWU2Q4U.js.map +1 -0
- package/dist/{chunk-XXLWC5DB.js → chunk-JX72GKXN.js} +2 -2
- package/dist/{chunk-UG6D3V4M.js → chunk-PMIYTMMA.js} +4674 -4604
- package/dist/chunk-PMIYTMMA.js.map +1 -0
- package/dist/cli/index.js +51 -8
- package/dist/cli/index.js.map +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -2
- package/dist/eslint/index.d.ts +3 -2
- package/dist/eslint/index.js +58 -17
- package/dist/eslint/index.js.map +1 -1
- package/dist/native/trust_native_wasm.wasm +0 -0
- package/package.json +6 -6
- package/dist/chunk-7PY2Q6OX.js.map +0 -1
- package/dist/chunk-UG6D3V4M.js.map +0 -1
- /package/dist/{chunk-XXLWC5DB.js.map → chunk-JX72GKXN.js.map} +0 -0
package/dist/cli/index.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
ANY_KIND,
|
|
3
4
|
TrustPolicy,
|
|
5
|
+
boundaryContext,
|
|
6
|
+
boundaryName,
|
|
4
7
|
callTypeVerdict,
|
|
5
8
|
checkSourceFile,
|
|
6
9
|
checkSourceFileWithAccepted,
|
|
7
10
|
claimSpan,
|
|
8
11
|
decide,
|
|
9
12
|
emptyTrustConfig,
|
|
13
|
+
excludeMatches,
|
|
14
|
+
fileBoundaries,
|
|
10
15
|
guardCallOf,
|
|
16
|
+
isStrictByConfig,
|
|
17
|
+
itemLabel,
|
|
11
18
|
policyFor,
|
|
12
19
|
positionAt,
|
|
13
20
|
startOf,
|
|
@@ -17,7 +24,7 @@ import {
|
|
|
17
24
|
untrustedValueContext,
|
|
18
25
|
untrustedValueMessage,
|
|
19
26
|
untrustedValuesIn
|
|
20
|
-
} from "../chunk-
|
|
27
|
+
} from "../chunk-EPWU2Q4U.js";
|
|
21
28
|
import {
|
|
22
29
|
compareFindings,
|
|
23
30
|
forEachSourceFile,
|
|
@@ -27,8 +34,9 @@ import {
|
|
|
27
34
|
logWalkFailure,
|
|
28
35
|
relativeTo,
|
|
29
36
|
resolveFiles
|
|
30
|
-
} from "../chunk-
|
|
37
|
+
} from "../chunk-JX72GKXN.js";
|
|
31
38
|
import {
|
|
39
|
+
BOUNDARY_RULE,
|
|
32
40
|
DROPPED_RESULT_RULE,
|
|
33
41
|
SvelteFileError,
|
|
34
42
|
SvelteInputs,
|
|
@@ -40,6 +48,7 @@ import {
|
|
|
40
48
|
compareToBaseline,
|
|
41
49
|
createPrograms,
|
|
42
50
|
describeBaselineDelta,
|
|
51
|
+
formatFailureKinds,
|
|
43
52
|
groupByTsconfig,
|
|
44
53
|
groupMatches,
|
|
45
54
|
isRuleEnabled,
|
|
@@ -53,7 +62,7 @@ import {
|
|
|
53
62
|
svelteFor,
|
|
54
63
|
svelteForSource,
|
|
55
64
|
updateBaseline
|
|
56
|
-
} from "../chunk-
|
|
65
|
+
} from "../chunk-PMIYTMMA.js";
|
|
57
66
|
|
|
58
67
|
// src/cli/baseline-command.ts
|
|
59
68
|
import { existsSync, writeFileSync } from "fs";
|
|
@@ -114,6 +123,9 @@ async function runBaselineCommand(options) {
|
|
|
114
123
|
if (added.some((delta) => delta.rule === DROPPED_RESULT_RULE)) {
|
|
115
124
|
options.log("Return each dropped failure (`if (!r.ok) return r;`) or handle it with Trust.decide.");
|
|
116
125
|
}
|
|
126
|
+
if (added.some((delta) => delta.rule === BOUNDARY_RULE)) {
|
|
127
|
+
options.log('Decide every kind at each boundary (an exhaustive `switch`) and return plain data, or exclude it under "boundaries" in trust.config.json.');
|
|
128
|
+
}
|
|
117
129
|
const alsoShows = `${hasTypeClaims ? ", and why a line is a type claim" : ""}${hasUntrustedValues ? ", and where an untrusted value comes from" : ""}`;
|
|
118
130
|
options.log(`\`trust explain <file>:<line>\` shows which origin a call resolves to${alsoShows}.`);
|
|
119
131
|
return 1;
|
|
@@ -234,7 +246,7 @@ function nativeEngine(options = {}) {
|
|
|
234
246
|
}
|
|
235
247
|
|
|
236
248
|
// src/cli/native-check.ts
|
|
237
|
-
var NATIVE_PROTOCOL_VERSION =
|
|
249
|
+
var NATIVE_PROTOCOL_VERSION = 4;
|
|
238
250
|
var WASM_STACK_SIZE_MB = 256;
|
|
239
251
|
var OPT_IN_RULES = [];
|
|
240
252
|
function runBinary(binary, request, cwd) {
|
|
@@ -322,7 +334,8 @@ async function checkNative(options) {
|
|
|
322
334
|
config: {
|
|
323
335
|
levels: config.levels.map((level) => ({ source: level.source, trust: level.trust, distrust: level.distrust, typeTrust: level.typeTrust, typeDistrust: level.typeDistrust })),
|
|
324
336
|
passthrough: config.passthrough.map((group) => ({ source: group.source, baseDir: group.baseDir, patterns: group.patterns })),
|
|
325
|
-
ignore: config.ignore.map((group) => ({ source: group.source, baseDir: group.baseDir, patterns: group.patterns }))
|
|
337
|
+
ignore: config.ignore.map((group) => ({ source: group.source, baseDir: group.baseDir, patterns: group.patterns })),
|
|
338
|
+
boundaries: config.boundaries.map((group) => ({ source: group.source, baseDir: group.baseDir, patterns: group.patterns, index: group.index, exclude: group.exclude }))
|
|
326
339
|
},
|
|
327
340
|
strictFiles: options.strictFiles.map((file) => svelte.generated(file))
|
|
328
341
|
});
|
|
@@ -504,8 +517,34 @@ function explain(options) {
|
|
|
504
517
|
const directiveLine = svelteFor(checker)?.position(source.fileName, directivePosition)?.line ?? directivePosition.line;
|
|
505
518
|
return [{ ...position, text: clipText(entry.text), rule: finding.rule, origin: finding.origin, why: finding.message, reason: acceptance.reason, directiveLine }];
|
|
506
519
|
});
|
|
520
|
+
const boundaries = [];
|
|
521
|
+
if (config.boundaries.length > 0) {
|
|
522
|
+
const found2 = fileBoundaries(source, boundaryContext(ts, checker, program, policy, config));
|
|
523
|
+
if (found2.kind === "boundary") {
|
|
524
|
+
const strict = isStrictByConfig(config, source.fileName);
|
|
525
|
+
for (const boundary of found2.boundaries) {
|
|
526
|
+
const position = here(positionAt(ts, source, boundary.start));
|
|
527
|
+
if (!position) continue;
|
|
528
|
+
const excludedBy = found2.item.exclude.find((entry) => excludeMatches(entry, boundary)) ?? null;
|
|
529
|
+
const reported = excludedBy || boundary.verdict.kind === "plain" ? null : boundary.verdict.kind === "result" || strict ? "error" : "warning";
|
|
530
|
+
boundaries.push({ ...position, member: boundaryName(boundary), item: itemLabel(found2.item), excludedBy, verdict: boundary.verdict, reported });
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
507
534
|
const unique = (items) => [...new Map(items.map((item) => [JSON.stringify(item), item])).values()];
|
|
508
|
-
return {
|
|
535
|
+
return {
|
|
536
|
+
kind: "explained",
|
|
537
|
+
explanation: { file, zone: policy.zones.zoneOf(file), calls: unique(calls), claims: unique(claims), values: unique(values), accepted: unique(accepted), boundaries: unique(boundaries), off }
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
function describeBoundary(boundary) {
|
|
541
|
+
const lines = [` boundary: ${boundary.member} (${boundary.item}, rule ${BOUNDARY_RULE})`];
|
|
542
|
+
const { verdict } = boundary;
|
|
543
|
+
const returns = verdict.kind === "plain" ? "plain data: nothing reported" : verdict.kind === "result" ? `a Result that can fail with ${formatFailureKinds(verdict.kinds, ANY_KIND)}` : `\`${verdict.type}\`, which may hold a Result`;
|
|
544
|
+
if (boundary.excludedBy) lines.push(` returns: ${returns}`, ` excluded: by "${boundary.excludedBy}" in the item's "exclude": nothing reported`);
|
|
545
|
+
else if (boundary.reported) lines.push(` returns: ${returns}: reported as ${boundary.reported === "warning" ? "a warning (an error where strict applies)" : "an error"}`);
|
|
546
|
+
else lines.push(` returns: ${returns}`);
|
|
547
|
+
return lines;
|
|
509
548
|
}
|
|
510
549
|
function describe(verdict) {
|
|
511
550
|
switch (verdict.kind) {
|
|
@@ -583,8 +622,12 @@ function formatExplanation(explanation) {
|
|
|
583
622
|
for (const rule of explanation.off) {
|
|
584
623
|
lines.push(`note: ${rule} is off in this config, so it is not explained; turn it on with "rules": { "${rule}": "on" } in trust.config.json`);
|
|
585
624
|
}
|
|
586
|
-
if (explanation.calls.length === 0 && explanation.claims.length === 0 && explanation.values.length === 0 && explanation.accepted.length === 0) {
|
|
587
|
-
lines.push("no call, `new` expression, type claim
|
|
625
|
+
if (explanation.calls.length === 0 && explanation.claims.length === 0 && explanation.values.length === 0 && explanation.accepted.length === 0 && explanation.boundaries.length === 0) {
|
|
626
|
+
lines.push("no call, `new` expression, type claim, untrusted value or boundary starts at that location");
|
|
627
|
+
}
|
|
628
|
+
for (const boundary of explanation.boundaries) {
|
|
629
|
+
lines.push("", `${boundary.line}:${boundary.column} ${boundary.member}`);
|
|
630
|
+
lines.push(...describeBoundary(boundary));
|
|
588
631
|
}
|
|
589
632
|
for (const accepted of explanation.accepted) {
|
|
590
633
|
lines.push("", `${accepted.line}:${accepted.column} ${accepted.text}`);
|