fix(tools)!: simplify direct invocation and harden boundary contracts (#555)
Remove REA permission grants, scope ceilings, approval confirmations, and inert settings. Preserve selected local evidence, accept caller-chosen commands and paths, and report actual runtime failures. Harden provider results, schema serialization, snapshot evidence binding, archive paths, source maps, native screenshots, managed EH parsing, and cancellation cleanup. Regenerate tool metadata and document direct invocation. BREAKING CHANGE: Removed permission configuration and policy commands, approval fields, filesystem scope inputs, and fixed confirmation options. Process capture inherits the host environment and accepts command names; callers must refresh tool schemas and migrate removed fields.
This commit is contained in:
@@ -30,15 +30,8 @@ export const normalizeArtifactPath = (input: string): string => {
|
||||
/** Reject exact, Unicode-normalized, case-folded, and prefix collisions. */
|
||||
export class ArtifactPathRegistry {
|
||||
readonly #root: PathTrieNode = { kind: undefined, children: new Map() };
|
||||
readonly #folded = new Set<string>();
|
||||
|
||||
add(path: string, kind: "file" | "directory" | "symlink" | "slice"): void {
|
||||
const folded = path.toLocaleLowerCase("en-US");
|
||||
if (this.#folded.has(folded))
|
||||
throw new ArtifactReaderFailure(
|
||||
"path",
|
||||
`Artifact path collision: ${path}`,
|
||||
);
|
||||
const parts = path.split("/");
|
||||
let node = this.#root;
|
||||
for (const [index, part] of parts.entries()) {
|
||||
@@ -47,10 +40,16 @@ export class ArtifactPathRegistry {
|
||||
"path",
|
||||
`Artifact prefix conflict: ${path}`,
|
||||
);
|
||||
let child = node.children.get(part);
|
||||
const foldedPart = part.toLocaleLowerCase("en-US");
|
||||
let child = node.children.get(foldedPart);
|
||||
if (child !== undefined && child.spelling !== part)
|
||||
throw new ArtifactReaderFailure(
|
||||
"path",
|
||||
`Artifact path collision: ${path}`,
|
||||
);
|
||||
if (child === undefined) {
|
||||
child = { kind: undefined, children: new Map() };
|
||||
node.children.set(part, child);
|
||||
child = { spelling: part, kind: undefined, children: new Map() };
|
||||
node.children.set(foldedPart, child);
|
||||
}
|
||||
node = child;
|
||||
if (index === parts.length - 1) {
|
||||
@@ -67,11 +66,11 @@ export class ArtifactPathRegistry {
|
||||
}
|
||||
}
|
||||
node.kind = kind;
|
||||
this.#folded.add(folded);
|
||||
}
|
||||
}
|
||||
|
||||
interface PathTrieNode {
|
||||
readonly spelling?: string;
|
||||
kind: "file" | "directory" | "symlink" | "slice" | undefined;
|
||||
readonly children: Map<string, PathTrieNode>;
|
||||
}
|
||||
|
||||
@@ -32,10 +32,7 @@ import { ArtifactReaderFailure } from "./ArtifactReader.js";
|
||||
import { ARTIFACT_GRAPH_PROVIDER } from "../application/InvestigationProviders.js";
|
||||
import { createEvidence } from "../domain/evidence.js";
|
||||
import { createArtifactInspection } from "../domain/artifactInspection.js";
|
||||
import {
|
||||
resolveArtifactIntegrityPolicy,
|
||||
resolveNativeMountPolicy,
|
||||
} from "../application/ArtifactInventory/policy.js";
|
||||
import { resolveArtifactIntegrityPolicy } from "../application/ArtifactInventory/policy.js";
|
||||
|
||||
const IDENTITY: ProviderIdentity = Object.freeze(ARTIFACT_GRAPH_PROVIDER);
|
||||
|
||||
@@ -43,11 +40,7 @@ const IDENTITY: ProviderIdentity = Object.freeze(ARTIFACT_GRAPH_PROVIDER);
|
||||
export class ArtifactProvider implements AnalysisProvider {
|
||||
readonly #capabilities: readonly CapabilityDescriptor[];
|
||||
|
||||
constructor(
|
||||
private readonly nativeMountEnabled = false,
|
||||
private readonly integrityContinueEnabled = false,
|
||||
platform: NodeJS.Platform = process.platform,
|
||||
) {
|
||||
constructor(platform: NodeJS.Platform = process.platform) {
|
||||
this.#capabilities = Object.freeze(
|
||||
ARTIFACT_ANALYSIS_OPERATIONS.map((operation) => {
|
||||
const common = {
|
||||
@@ -65,7 +58,7 @@ export class ArtifactProvider implements AnalysisProvider {
|
||||
requiresRoot: false,
|
||||
}),
|
||||
limitations: Object.freeze([
|
||||
"DMG child inventory is macOS-only and requires per-call approval plus operator policy; PKG remains root-hash-only.",
|
||||
"DMG child inventory automatically uses a read-only native macOS mount; PKG remains root-hash-only.",
|
||||
"ASAR files discovered in filesystem-backed inventories are expanded without bulk extraction; other nested containers remain recorded only.",
|
||||
]),
|
||||
};
|
||||
@@ -92,20 +85,12 @@ export class ArtifactProvider implements AnalysisProvider {
|
||||
}
|
||||
|
||||
createClient(target: BinaryTarget): AnalysisClient {
|
||||
return new ArtifactClient(
|
||||
target,
|
||||
this.nativeMountEnabled,
|
||||
this.integrityContinueEnabled,
|
||||
);
|
||||
return new ArtifactClient(target);
|
||||
}
|
||||
}
|
||||
|
||||
class ArtifactClient implements AnalysisClient {
|
||||
constructor(
|
||||
private readonly target: BinaryTarget,
|
||||
private readonly nativeMountEnabled: boolean,
|
||||
private readonly integrityContinueEnabled: boolean,
|
||||
) {}
|
||||
constructor(private readonly target: BinaryTarget) {}
|
||||
|
||||
async execute(
|
||||
operation: AnalysisOperation,
|
||||
@@ -287,11 +272,9 @@ class ArtifactClient implements AnalysisClient {
|
||||
options?: ExecutionOptions,
|
||||
) {
|
||||
const parsed = artifactInventoryInputSchema.parse(parameters);
|
||||
const inventoryParameters = artifactInventoryInputSchema.parse({
|
||||
native_mount_approved: parsed.native_mount_approved,
|
||||
const inventoryParameters = {
|
||||
integrity_policy: parsed.integrity_policy,
|
||||
integrity_continue_approved: parsed.integrity_continue_approved,
|
||||
});
|
||||
};
|
||||
await options?.progress?.report({
|
||||
phase: "inspect_artifact.inventory",
|
||||
completed: 0,
|
||||
@@ -334,26 +317,15 @@ class ArtifactClient implements AnalysisClient {
|
||||
|
||||
private inventory(
|
||||
parsed: {
|
||||
readonly native_mount_approved: boolean;
|
||||
readonly integrity_policy: "fail" | "record-and-continue";
|
||||
readonly integrity_continue_approved: boolean;
|
||||
},
|
||||
options?: ExecutionOptions,
|
||||
) {
|
||||
return inventoryArtifact(this.target.sourcePath ?? this.target.path, {
|
||||
...(options?.signal === undefined ? {} : { signal: options.signal }),
|
||||
nativeMount: resolveNativeMountPolicy(
|
||||
parsed.native_mount_approved === true,
|
||||
this.nativeMountEnabled,
|
||||
),
|
||||
integrity: resolveArtifactIntegrityPolicy(
|
||||
parsed.integrity_policy === "fail"
|
||||
? { mode: "fail" }
|
||||
: {
|
||||
mode: parsed.integrity_policy,
|
||||
},
|
||||
this.integrityContinueEnabled,
|
||||
),
|
||||
integrity: resolveArtifactIntegrityPolicy({
|
||||
mode: parsed.integrity_policy,
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ export class ArtifactReaderFailure extends Error {
|
||||
| "io"
|
||||
| "limit"
|
||||
| "path"
|
||||
| "policy"
|
||||
| "unavailable",
|
||||
message: string,
|
||||
options?: ErrorOptions,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createReadStream } from "node:fs";
|
||||
import type { Readable } from "node:stream";
|
||||
import { stat } from "node:fs/promises";
|
||||
import { Readable } from "node:stream";
|
||||
|
||||
import type { ArtifactCommand } from "../domain/artifactGraph.js";
|
||||
import {
|
||||
@@ -12,6 +13,7 @@ import {
|
||||
type ArtifactEntry,
|
||||
type ArtifactReader,
|
||||
} from "./ArtifactReader.js";
|
||||
import { streamChunkToBuffer } from "./StreamBytes.js";
|
||||
|
||||
/** Read-only universal Mach-O slice reader backed by native lipo metadata. */
|
||||
export class MachOSliceArtifactReader implements ArtifactReader {
|
||||
@@ -43,12 +45,25 @@ export class MachOSliceArtifactReader implements ArtifactReader {
|
||||
exit_code: captured.value.exitCode,
|
||||
effects: ["read"],
|
||||
};
|
||||
const fileSize = (await stat(this.path)).size;
|
||||
for (const architecture of parseLipoArchitectures(captured.value.stdout)) {
|
||||
if (architecture.file_offset === null || architecture.size === null)
|
||||
throw new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
"lipo omitted a universal slice byte range",
|
||||
);
|
||||
if (
|
||||
!Number.isSafeInteger(architecture.file_offset) ||
|
||||
!Number.isSafeInteger(architecture.size) ||
|
||||
architecture.file_offset < 0 ||
|
||||
architecture.size <= 0 ||
|
||||
!Number.isSafeInteger(architecture.file_offset + architecture.size) ||
|
||||
architecture.file_offset + architecture.size > fileSize
|
||||
)
|
||||
throw new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
`lipo reported an out-of-bounds Mach-O slice: ${architecture.name}`,
|
||||
);
|
||||
yield {
|
||||
path: `slices/${architecture.name}`,
|
||||
kind: "slice",
|
||||
@@ -65,7 +80,7 @@ export class MachOSliceArtifactReader implements ArtifactReader {
|
||||
}
|
||||
}
|
||||
|
||||
open(entry: ArtifactEntry, signal?: AbortSignal): Promise<Readable> {
|
||||
async open(entry: ArtifactEntry, signal?: AbortSignal): Promise<Readable> {
|
||||
if (signal?.aborted === true)
|
||||
return Promise.reject(
|
||||
new ArtifactReaderFailure("cancelled", "Mach-O slice read cancelled"),
|
||||
@@ -76,16 +91,58 @@ export class MachOSliceArtifactReader implements ArtifactReader {
|
||||
if (
|
||||
!Number.isSafeInteger(offset) ||
|
||||
!Number.isSafeInteger(size) ||
|
||||
offset < 0 ||
|
||||
size <= 0
|
||||
)
|
||||
return Promise.reject(
|
||||
new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
"Invalid Mach-O slice byte range",
|
||||
),
|
||||
throw new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
"Invalid Mach-O slice byte range",
|
||||
);
|
||||
return Promise.resolve(
|
||||
createReadStream(this.path, { start: offset, end: offset + size - 1 }),
|
||||
const fileSize = (await stat(this.path)).size;
|
||||
if (!Number.isSafeInteger(offset + size) || offset + size > fileSize)
|
||||
throw new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
`Mach-O slice range is outside the artifact: ${entry.path}`,
|
||||
);
|
||||
const source = createReadStream(this.path, {
|
||||
start: offset,
|
||||
end: offset + size - 1,
|
||||
...(signal === undefined ? {} : { signal }),
|
||||
});
|
||||
return Readable.from(
|
||||
(async function* () {
|
||||
let observedBytes = 0;
|
||||
try {
|
||||
for await (const raw of source) {
|
||||
const chunk = streamChunkToBuffer(raw);
|
||||
observedBytes += chunk.byteLength;
|
||||
if (observedBytes > size)
|
||||
throw new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
`Mach-O slice exceeded its reported size: ${entry.path}`,
|
||||
);
|
||||
yield chunk;
|
||||
}
|
||||
} catch (cause: unknown) {
|
||||
if (cause instanceof ArtifactReaderFailure) throw cause;
|
||||
if (signal?.aborted === true)
|
||||
throw new ArtifactReaderFailure(
|
||||
"cancelled",
|
||||
"Mach-O slice read cancelled",
|
||||
{ cause },
|
||||
);
|
||||
throw new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
`Could not read Mach-O slice range: ${entry.path}`,
|
||||
{ cause },
|
||||
);
|
||||
}
|
||||
if (observedBytes !== size)
|
||||
throw new ArtifactReaderFailure(
|
||||
"integrity",
|
||||
`Mach-O slice size disagrees with lipo metadata: ${entry.path}`,
|
||||
);
|
||||
})(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user