fix(evidence): reject NUL bytes in subject and snapshot paths (#1873)

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.
This commit is contained in:
Dery Ferdika
2026-10-11 23:45:37 +08:00
committed by GitHub
parent efbc25fbea
commit fa9a7e5ec0
5 changed files with 58 additions and 5 deletions
+16
View File
@@ -291,6 +291,22 @@ describe("analysis evidence identity", () => {
});
});
it("rejects a subject local path containing NUL while admitting an empty path", () => {
const evidence = createEvidence(TARGET, PROVIDER, {
operation: "health",
parameters: {},
result: true,
});
expect(evidence.subject).not.toBeNull();
const withPath = (path: string) => ({
...evidence,
subject: { ...evidence.subject, local_path: path },
});
expect(evidenceSchema.safeParse(withPath("/tmp/fixture")).success).toBe(true);
expect(evidenceSchema.safeParse(withPath("")).success).toBe(true);
expect(evidenceSchema.safeParse(withPath("a\u0000b")).success).toBe(false);
});
it("binds an explicit unknown-subject reason into the semantic Evidence identity", () => {
const reason = "Caller excluded the observed digest.";
const observation = { operation: "health", parameters: {}, result: true };