Evidence subject local_path and analysis-snapshot subject path accepted any string, so a caller-supplied inline Evidence record could carry a NUL byte into the observation and bundle output even though every other selected-path boundary already refuses it. Both fields now use the shared NUL-free local-path schema: the snapshot path keeps its nonempty rule, and the Evidence local_path stays free to be empty because network capture Evidence uses an empty path as a deliberate sentinel. localPath.ts now exports the NUL-free base schema separately so the nonempty rule is composed rather than duplicated; the advertised pattern and minLength for existing localPathStringSchema consumers are unchanged. Validation: new unit cases reject a NUL local_path and snapshot path while admitting an empty Evidence path and an ordinary path; domain suite 126 files / 1704 tests pass, evidence bundle and retained-evidence MCP boundaries pass, localToolContracts NUL harness passes, toolSchemaValidity passes with a regenerated catalog, typecheck, oxlint, oxfmt.
30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
import { isAbsolute, relative, sep } from "node:path";
|
|
import { z } from "zod";
|
|
|
|
/**
|
|
* Reject OS-invalid NUL bytes in a local filesystem name. This is not a path
|
|
* shape check: an empty or relative value is admitted here and narrowed by the
|
|
* callers that need a nonempty or absolute path.
|
|
*
|
|
* The pattern spells NUL as `\x00` rather than `\u0000`. Both accept exactly the
|
|
* same strings. The hex form also avoids the short `\0` spelling rejected by
|
|
* strict schema consumers. A client can reject its entire tool request when
|
|
* one advertised pattern cannot compile. See `offsetDateTimeSchema` for the
|
|
* same hex-escape convention.
|
|
*/
|
|
export const nulFreeStringSchema = z
|
|
.string()
|
|
.regex(/^[^\x00]*$/u, "Local filesystem paths cannot contain NUL");
|
|
|
|
/** A selected local filesystem path: nonempty and free of NUL bytes. */
|
|
export const localPathStringSchema = nulFreeStringSchema.min(1);
|
|
|
|
/** Test lexical containment on the host platform; callers must resolve symlinks first. */
|
|
export const isPathWithinRoot = (root: string, path: string): boolean => {
|
|
const value = relative(root, path);
|
|
return (
|
|
value === "" ||
|
|
(value !== ".." && !value.startsWith(`..${sep}`) && !isAbsolute(value))
|
|
);
|
|
};
|