@noego/trust 0.5.1-dev.1 → 0.5.1-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 +155 -0
- package/dist/{baseline-D0Ok-NGU.d.ts → baseline-DMNO7IAl.d.ts} +20 -2
- package/dist/{chunk-V4FYZG5Q.js → chunk-2MSSO67W.js} +2 -2
- package/dist/{chunk-P4VFMA2A.js → chunk-3IIEQHH2.js} +382 -12
- package/dist/chunk-3IIEQHH2.js.map +1 -0
- package/dist/{chunk-RVTPDLEW.js → chunk-VJGGEY4G.js} +3481 -3456
- package/dist/chunk-VJGGEY4G.js.map +1 -0
- package/dist/cli/index.js +82 -85
- 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 +5 -2
- package/dist/eslint/index.js +49 -12
- package/dist/eslint/index.js.map +1 -1
- package/dist/index.cjs +33 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -5
- package/dist/index.d.ts +66 -5
- package/dist/index.js +31 -5
- package/dist/index.js.map +1 -1
- package/dist/native/trust_native_wasm.wasm +0 -0
- package/package.json +4 -4
- package/dist/chunk-P4VFMA2A.js.map +0 -1
- package/dist/chunk-RVTPDLEW.js.map +0 -1
- /package/dist/{chunk-V4FYZG5Q.js.map → chunk-2MSSO67W.js.map} +0 -0
package/dist/cli/index.js
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
untrustedValueContext,
|
|
25
25
|
untrustedValueMessage,
|
|
26
26
|
untrustedValuesIn
|
|
27
|
-
} from "../chunk-
|
|
27
|
+
} from "../chunk-3IIEQHH2.js";
|
|
28
28
|
import {
|
|
29
29
|
compareFindings,
|
|
30
30
|
forEachSourceFile,
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
logWalkFailure,
|
|
35
35
|
relativeTo,
|
|
36
36
|
resolveFiles
|
|
37
|
-
} from "../chunk-
|
|
37
|
+
} from "../chunk-2MSSO67W.js";
|
|
38
38
|
import {
|
|
39
39
|
BOUNDARY_RULE,
|
|
40
40
|
DROPPED_RESULT_RULE,
|
|
@@ -62,89 +62,22 @@ import {
|
|
|
62
62
|
svelteFor,
|
|
63
63
|
svelteForSource,
|
|
64
64
|
updateBaseline
|
|
65
|
-
} from "../chunk-
|
|
65
|
+
} from "../chunk-VJGGEY4G.js";
|
|
66
66
|
|
|
67
67
|
// src/cli/baseline-command.ts
|
|
68
68
|
import { existsSync, writeFileSync } from "fs";
|
|
69
|
-
import { join, resolve } from "path";
|
|
70
|
-
async function runBaselineCommand(options) {
|
|
71
|
-
const resolved = resolveFiles(options.cwd, options.paths.length > 0 ? options.paths : ["."]);
|
|
72
|
-
if ("missing" in resolved) {
|
|
73
|
-
options.log(`trust baseline: no such file or directory: ${resolved.missing}`);
|
|
74
|
-
return 2;
|
|
75
|
-
}
|
|
76
|
-
const configPath = resolve(options.cwd, options.configFile);
|
|
77
|
-
const rootDir = options.root === void 0 ? void 0 : resolve(options.cwd, options.root);
|
|
78
|
-
const config = existsSync(configPath) ? loadTrustConfig(configPath, { rootDir }) : emptyTrustConfig(rootDir ?? options.cwd);
|
|
79
|
-
logUnmatchedGlobs(options.log, "baseline", config);
|
|
80
|
-
const baselineFile = resolve(options.cwd, options.baselineFile ?? join(config.rootDir, "trust-baseline.json"));
|
|
81
|
-
const zones = new Zones(config.rootDir, config.passthrough, config.ignore);
|
|
82
|
-
const files = resolved.files.filter((file) => zones.zoneOf(file) !== "ignore");
|
|
83
|
-
const scope = options.paths.length === 0 ? WHOLE_BASELINE : { kind: "files", files: new Set(files.map((file) => relativeTo(config.rootDir, file))) };
|
|
84
|
-
const findings = [];
|
|
85
|
-
const programs = { tsconfig: options.tsconfig, mappings: config.tsconfig };
|
|
86
|
-
const walk = forEachSourceFile(options.cwd, files, programs, ({ ts, program, sourceFile }) => {
|
|
87
|
-
findings.push(...checkSourceFile({ ts, program, config, sourceFile }));
|
|
88
|
-
});
|
|
89
|
-
if (walk.status !== "ok") {
|
|
90
|
-
logWalkFailure(options.log, "baseline", walk);
|
|
91
|
-
return 2;
|
|
92
|
-
}
|
|
93
|
-
const baseline = options.update && scope.kind === "all" ? { counts: {} } : readBaseline(baselineFile);
|
|
94
|
-
if ("error" in baseline) {
|
|
95
|
-
options.log(`trust baseline: could not read the baseline: ${baseline.error}`);
|
|
96
|
-
return 2;
|
|
97
|
-
}
|
|
98
|
-
if (options.update) {
|
|
99
|
-
const updated = updateBaseline(baseline.counts, findings, scope);
|
|
100
|
-
writeFileSync(baselineFile, serializeBaseline(updated.counts));
|
|
101
|
-
const kept = updated.kept > 0 ? ` Kept the entries of ${updated.kept} unchecked file(s).` : "";
|
|
102
|
-
options.log(`Wrote ${baselineFile}: ${findings.length} finding(s) in ${files.length} checked file(s).${kept}`);
|
|
103
|
-
return 0;
|
|
104
|
-
}
|
|
105
|
-
const { added, stale } = compareToBaseline(findings, baseline.counts, scope);
|
|
106
|
-
if (stale.length > 0) {
|
|
107
|
-
options.log(`${stale.length} baseline entr${stale.length === 1 ? "y has" : "ies have"} fewer findings now; run with --update to shrink the baseline.`);
|
|
108
|
-
}
|
|
109
|
-
if (added.length === 0) {
|
|
110
|
-
options.log(`No new @noego/trust violations (${findings.length} baselined finding(s), ${files.length} file(s)).`);
|
|
111
|
-
return 0;
|
|
112
|
-
}
|
|
113
|
-
const count = added.reduce((sum, delta) => sum + delta.found - delta.allowed, 0);
|
|
114
|
-
options.log(`${count} new @noego/trust violation(s) not in ${baselineFile}:`);
|
|
115
|
-
for (const delta of added) for (const line of describeBaselineDelta(delta)) options.log(` ${line}`);
|
|
116
|
-
options.log("Guard each call (try/catch returning Result.err, or Trust.try), or trust its origin in trust.config.json.");
|
|
117
|
-
const hasTypeClaims = added.some((delta) => delta.rule === TYPE_CLAIM_RULE);
|
|
118
|
-
if (hasTypeClaims) options.log("Prove each claimed type (narrow or validate the value) instead of asserting it.");
|
|
119
|
-
const hasUntrustedValues = added.some((delta) => delta.rule === UNTRUSTED_VALUE_RULE);
|
|
120
|
-
if (hasUntrustedValues) {
|
|
121
|
-
options.log('Validate each untrusted value (or keep it as `unknown` and narrow it), or add its origin to "trust_type" in trust.config.json.');
|
|
122
|
-
}
|
|
123
|
-
if (added.some((delta) => delta.rule === DROPPED_RESULT_RULE)) {
|
|
124
|
-
options.log("Return each dropped failure (`if (!r.ok) return r;`) or handle it with Trust.decide.");
|
|
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
|
-
}
|
|
129
|
-
const alsoShows = `${hasTypeClaims ? ", and why a line is a type claim" : ""}${hasUntrustedValues ? ", and where an untrusted value comes from" : ""}`;
|
|
130
|
-
options.log(`\`trust explain <file>:<line>\` shows which origin a call resolves to${alsoShows}.`);
|
|
131
|
-
return 1;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// src/cli/check-command.ts
|
|
135
|
-
import { existsSync as existsSync2 } from "fs";
|
|
136
|
-
import { resolve as resolve4 } from "path";
|
|
69
|
+
import { join as join2, resolve as resolve3 } from "path";
|
|
137
70
|
|
|
138
71
|
// src/cli/native-check.ts
|
|
139
72
|
import { readFileSync as readFileSync2 } from "fs";
|
|
140
|
-
import { resolve as
|
|
73
|
+
import { resolve as resolve2 } from "path";
|
|
141
74
|
import { spawnSync } from "child_process";
|
|
142
75
|
import { Worker } from "worker_threads";
|
|
143
76
|
|
|
144
77
|
// src/cli/native-engine.ts
|
|
145
78
|
import { accessSync, constants, readFileSync, statSync } from "fs";
|
|
146
79
|
import { createRequire } from "module";
|
|
147
|
-
import { dirname, join
|
|
80
|
+
import { dirname, join, resolve } from "path";
|
|
148
81
|
import { fileURLToPath } from "url";
|
|
149
82
|
function nativePlatformPackage(platform, arch, libc = null) {
|
|
150
83
|
if (platform === "darwin" && arch === "arm64") return "@noego/trust-darwin-arm64";
|
|
@@ -174,7 +107,7 @@ function runtimeLinux(platform) {
|
|
|
174
107
|
var requireFromHere = createRequire(import.meta.url);
|
|
175
108
|
function packageRoots() {
|
|
176
109
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
177
|
-
const roots = [
|
|
110
|
+
const roots = [resolve(here, "..", "..")];
|
|
178
111
|
try {
|
|
179
112
|
roots.unshift(dirname(requireFromHere.resolve("@noego/trust/package.json")));
|
|
180
113
|
} catch {
|
|
@@ -193,7 +126,7 @@ function isFile(path, executable = false, platform = process.platform) {
|
|
|
193
126
|
function packageVersion(roots, name) {
|
|
194
127
|
for (const root of roots) {
|
|
195
128
|
try {
|
|
196
|
-
const manifest = JSON.parse(readFileSync(
|
|
129
|
+
const manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
197
130
|
const version = manifest.optionalDependencies?.[name];
|
|
198
131
|
if (manifest.name === "@noego/trust" && typeof version === "string" && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version)) return version;
|
|
199
132
|
} catch {
|
|
@@ -217,20 +150,20 @@ function nativeBinary(options = {}) {
|
|
|
217
150
|
try {
|
|
218
151
|
const manifestPath = (options.resolvePackage ?? requireFromHere.resolve)(`${name}/package.json`);
|
|
219
152
|
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
220
|
-
const candidate =
|
|
153
|
+
const candidate = join(dirname(manifestPath), "bin", executable);
|
|
221
154
|
if (manifest.name === name && manifest.version === version && isFile(candidate, true, platform)) return candidate;
|
|
222
155
|
} catch {
|
|
223
156
|
}
|
|
224
157
|
}
|
|
225
|
-
return roots.map((root) =>
|
|
158
|
+
return roots.map((root) => join(root, "native", "target", "release", executable)).find((candidate) => isFile(candidate, true, platform)) ?? null;
|
|
226
159
|
}
|
|
227
160
|
function nativeWasm(options = {}) {
|
|
228
161
|
const env = options.env ?? process.env;
|
|
229
162
|
if (env.TRUST_NATIVE_WASM) return env.TRUST_NATIVE_WASM;
|
|
230
163
|
const candidates = (options.roots ?? packageRoots()).flatMap((root) => [
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
164
|
+
join(root, "dist", "native", "trust_native_wasm.wasm"),
|
|
165
|
+
join(root, "native", "target", "wasm32-wasip1", "wasm", "trust_native_wasm.wasm"),
|
|
166
|
+
join(root, "native", "target", "wasm32-wasip1", "release", "trust_native_wasm.wasm")
|
|
234
167
|
]);
|
|
235
168
|
return candidates.find((candidate) => isFile(candidate)) ?? null;
|
|
236
169
|
}
|
|
@@ -246,7 +179,7 @@ function nativeEngine(options = {}) {
|
|
|
246
179
|
}
|
|
247
180
|
|
|
248
181
|
// src/cli/native-check.ts
|
|
249
|
-
var NATIVE_PROTOCOL_VERSION =
|
|
182
|
+
var NATIVE_PROTOCOL_VERSION = 5;
|
|
250
183
|
var WASM_STACK_SIZE_MB = 256;
|
|
251
184
|
var OPT_IN_RULES = [];
|
|
252
185
|
function runBinary(binary, request, cwd) {
|
|
@@ -281,7 +214,7 @@ function validResponse(value) {
|
|
|
281
214
|
if (response.version !== NATIVE_PROTOCOL_VERSION || !Array.isArray(response.findings) || !Array.isArray(response.errors)) return false;
|
|
282
215
|
if (response.setupError !== null && typeof response.setupError !== "string") return false;
|
|
283
216
|
if (!response.errors.every((error) => typeof error === "string")) return false;
|
|
284
|
-
if (!response.findings.every((finding) => finding && typeof finding === "object" && ["file", "rule", "message"].every((key) => typeof finding[key] === "string") && Number.isInteger(finding.line) && finding.line > 0 && Number.isInteger(finding.column) && finding.column > 0 && (finding.severity === "error" || finding.severity === "warning"))) return false;
|
|
217
|
+
if (!response.findings.every((finding) => finding && typeof finding === "object" && ["file", "rule", "origin", "message"].every((key) => typeof finding[key] === "string") && Number.isInteger(finding.line) && finding.line > 0 && Number.isInteger(finding.column) && finding.column > 0 && (finding.severity === "error" || finding.severity === "warning"))) return false;
|
|
285
218
|
const stats = response.stats;
|
|
286
219
|
return !!stats && ["loadSeconds", "checkSeconds", "checkedFiles"].every((key) => typeof stats[key] === "number" && Number.isFinite(stats[key]) && stats[key] >= 0);
|
|
287
220
|
}
|
|
@@ -330,7 +263,7 @@ async function checkNative(options) {
|
|
|
330
263
|
extraRoots,
|
|
331
264
|
programs: options.programs,
|
|
332
265
|
perf: options.perf ?? false,
|
|
333
|
-
rules: { typeClaim: isRuleEnabled(config, "type-claim"), untrustedValue: isRuleEnabled(config, "untrusted-value"), untrustedCallbacks: config.rules.untrustedCallbacks, droppedResult: isRuleEnabled(config, "dropped-result"), redundantGuard: isRuleEnabled(config, "redundant-guard"), resultLookalike: config.rules["result-lookalike"] },
|
|
266
|
+
rules: { trustedState: isRuleEnabled(config, "trusted-state"), typeClaim: isRuleEnabled(config, "type-claim"), untrustedValue: isRuleEnabled(config, "untrusted-value"), untrustedCallbacks: config.rules.untrustedCallbacks, droppedResult: isRuleEnabled(config, "dropped-result"), redundantGuard: isRuleEnabled(config, "redundant-guard"), resultLookalike: config.rules["result-lookalike"] },
|
|
334
267
|
config: {
|
|
335
268
|
levels: config.levels.map((level) => ({ source: level.source, trust: level.trust, distrust: level.distrust, typeTrust: level.typeTrust, typeDistrust: level.typeDistrust })),
|
|
336
269
|
passthrough: config.passthrough.map((group) => ({ source: group.source, baseDir: group.baseDir, patterns: group.patterns })),
|
|
@@ -362,14 +295,78 @@ async function checkNative(options) {
|
|
|
362
295
|
if (response.errors.length > 0) return { findings: [], walk: { status: "file-errors", errors: response.errors.map((error) => svelte.error(error)) } };
|
|
363
296
|
const snippetTrusted = decide(config.levels, (level) => level, "svelte.__renderSnippet", "svelte").trusted && !("distrustedBy" in decide(config.levels, (level) => level, "svelte.Snippet", "svelte"));
|
|
364
297
|
const findings = response.findings.flatMap((finding) => {
|
|
365
|
-
const file =
|
|
298
|
+
const file = resolve2(config.rootDir, finding.file);
|
|
366
299
|
const mapped = svelte.finding(file, finding, snippetTrusted);
|
|
367
300
|
return mapped ? [{ ...mapped, file: svelte.paths.has(file) ? relativeTo(config.rootDir, svelte.original(file)) : finding.file }] : [];
|
|
368
301
|
});
|
|
369
302
|
return { findings, walk: { status: "ok" } };
|
|
370
303
|
}
|
|
371
304
|
|
|
305
|
+
// src/cli/baseline-command.ts
|
|
306
|
+
async function runBaselineCommand(options) {
|
|
307
|
+
const resolved = resolveFiles(options.cwd, options.paths.length > 0 ? options.paths : ["."]);
|
|
308
|
+
if ("missing" in resolved) {
|
|
309
|
+
options.log(`trust baseline: no such file or directory: ${resolved.missing}`);
|
|
310
|
+
return 2;
|
|
311
|
+
}
|
|
312
|
+
const configPath = resolve3(options.cwd, options.configFile);
|
|
313
|
+
const rootDir = options.root === void 0 ? void 0 : resolve3(options.cwd, options.root);
|
|
314
|
+
const config = existsSync(configPath) ? loadTrustConfig(configPath, { rootDir }) : emptyTrustConfig(rootDir ?? options.cwd);
|
|
315
|
+
logUnmatchedGlobs(options.log, "baseline", config);
|
|
316
|
+
const baselineFile = resolve3(options.cwd, options.baselineFile ?? join2(config.rootDir, "trust-baseline.json"));
|
|
317
|
+
const zones = new Zones(config.rootDir, config.passthrough, config.ignore);
|
|
318
|
+
const files = resolved.files.filter((file) => zones.zoneOf(file) !== "ignore");
|
|
319
|
+
const scope = options.paths.length === 0 ? WHOLE_BASELINE : { kind: "files", files: new Set(files.map((file) => relativeTo(config.rootDir, file))) };
|
|
320
|
+
const programs = { tsconfig: options.tsconfig, mappings: config.tsconfig };
|
|
321
|
+
const { findings, walk } = await checkNative({ cwd: options.cwd, files, config, programs, strictFiles: [], log: options.log });
|
|
322
|
+
if (walk.status !== "ok") {
|
|
323
|
+
logWalkFailure(options.log, "baseline", walk);
|
|
324
|
+
return 2;
|
|
325
|
+
}
|
|
326
|
+
const baseline = options.update && scope.kind === "all" ? { counts: {} } : readBaseline(baselineFile);
|
|
327
|
+
if ("error" in baseline) {
|
|
328
|
+
options.log(`trust baseline: could not read the baseline: ${baseline.error}`);
|
|
329
|
+
return 2;
|
|
330
|
+
}
|
|
331
|
+
if (options.update) {
|
|
332
|
+
const updated = updateBaseline(baseline.counts, findings, scope);
|
|
333
|
+
writeFileSync(baselineFile, serializeBaseline(updated.counts));
|
|
334
|
+
const kept = updated.kept > 0 ? ` Kept the entries of ${updated.kept} unchecked file(s).` : "";
|
|
335
|
+
options.log(`Wrote ${baselineFile}: ${findings.length} finding(s) in ${files.length} checked file(s).${kept}`);
|
|
336
|
+
return 0;
|
|
337
|
+
}
|
|
338
|
+
const { added, stale } = compareToBaseline(findings, baseline.counts, scope);
|
|
339
|
+
if (stale.length > 0) {
|
|
340
|
+
options.log(`${stale.length} baseline entr${stale.length === 1 ? "y has" : "ies have"} fewer findings now; run with --update to shrink the baseline.`);
|
|
341
|
+
}
|
|
342
|
+
if (added.length === 0) {
|
|
343
|
+
options.log(`No new @noego/trust violations (${findings.length} baselined finding(s), ${files.length} file(s)).`);
|
|
344
|
+
return 0;
|
|
345
|
+
}
|
|
346
|
+
const count = added.reduce((sum, delta) => sum + delta.found - delta.allowed, 0);
|
|
347
|
+
options.log(`${count} new @noego/trust violation(s) not in ${baselineFile}:`);
|
|
348
|
+
for (const delta of added) for (const line of describeBaselineDelta(delta)) options.log(` ${line}`);
|
|
349
|
+
options.log("Guard each call (try/catch returning Result.err, or Trust.try), or trust its origin in trust.config.json.");
|
|
350
|
+
const hasTypeClaims = added.some((delta) => delta.rule === TYPE_CLAIM_RULE);
|
|
351
|
+
if (hasTypeClaims) options.log("Prove each claimed type (narrow or validate the value) instead of asserting it.");
|
|
352
|
+
const hasUntrustedValues = added.some((delta) => delta.rule === UNTRUSTED_VALUE_RULE);
|
|
353
|
+
if (hasUntrustedValues) {
|
|
354
|
+
options.log('Validate each untrusted value (or keep it as `unknown` and narrow it), or add its origin to "trust_type" in trust.config.json.');
|
|
355
|
+
}
|
|
356
|
+
if (added.some((delta) => delta.rule === DROPPED_RESULT_RULE)) {
|
|
357
|
+
options.log("Return each dropped failure (`if (!r.ok) return r;`) or handle it with Trust.decide.");
|
|
358
|
+
}
|
|
359
|
+
if (added.some((delta) => delta.rule === BOUNDARY_RULE)) {
|
|
360
|
+
options.log('Decide every kind at each boundary (an exhaustive `switch`) and return plain data, or exclude it under "boundaries" in trust.config.json.');
|
|
361
|
+
}
|
|
362
|
+
const alsoShows = `${hasTypeClaims ? ", and why a line is a type claim" : ""}${hasUntrustedValues ? ", and where an untrusted value comes from" : ""}`;
|
|
363
|
+
options.log(`\`trust explain <file>:<line>\` shows which origin a call resolves to${alsoShows}.`);
|
|
364
|
+
return 1;
|
|
365
|
+
}
|
|
366
|
+
|
|
372
367
|
// src/cli/check-command.ts
|
|
368
|
+
import { existsSync as existsSync2 } from "fs";
|
|
369
|
+
import { resolve as resolve4 } from "path";
|
|
373
370
|
async function runCheckCommand(options) {
|
|
374
371
|
const fail = (errors) => {
|
|
375
372
|
if (options.json) options.log(JSON.stringify({ findings: [], errors, warnings: [] }));
|
|
@@ -650,7 +647,7 @@ function explain(options) {
|
|
|
650
647
|
function describeBoundary(boundary) {
|
|
651
648
|
const lines = [` boundary: ${boundary.member} (${boundary.item}, rule ${BOUNDARY_RULE})`];
|
|
652
649
|
const { verdict } = boundary;
|
|
653
|
-
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`;
|
|
650
|
+
const returns = verdict.kind === "plain" ? "plain data: nothing reported" : verdict.kind === "result" ? verdict.kinds.length === 0 ? "a Result object that cannot fail" : `a Result that can fail with ${formatFailureKinds(verdict.kinds, ANY_KIND)}` : `\`${verdict.type}\`, which may hold a Result`;
|
|
654
651
|
if (boundary.excludedBy) lines.push(` returns: ${returns}`, ` excluded: by "${boundary.excludedBy}" in the item's "exclude": nothing reported`);
|
|
655
652
|
else if (boundary.reported) lines.push(` returns: ${returns}: reported as ${boundary.reported === "warning" ? "a warning (an error where strict applies)" : "an error"}`);
|
|
656
653
|
else lines.push(` returns: ${returns}`);
|