fix(entropy)!: own selected Windows path spelling at admission (#9393)

* fix(evidence)!: keep one Evidence identity across Windows path case

On Windows, an existing caller path now takes its filesystem spelling when
that spelling differs from the resolved path by letter case alone. One file
spelled `C:\Temp\x.bin`, `c:\temp\x.bin` or `C:\TEMP\X.BIN` produces one
`parameters.path`, `normalized_result` path and `evidence_id`, matching the
existing separator and `.` folding. `caller_input_path` keeps the input.

Links, junctions, `subst` drives, 8.3 short names and paths that do not
exist yet keep the caller spelling, so no link is followed and requested
output names keep their case.

BREAKING CHANGE: Windows Evidence produced from a path spelled in a case
other than its filesystem spelling now gets a different `evidence_id`.

Fixes #9373

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(entropy): keep Windows casing lookup optional

* ci(entropy): select Windows identity verification

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-09 20:16:13 +08:00
1 parent bf271ba3fb
commit ab1b9e35d0
8 files changed
+168 -19

No files matched your search

@@ -1,6 +1,7 @@
import { absoluteCallerPath } from "../../filesystem/callerPath.js";
import { createHash } from "node:crypto";
import { constants } from "node:fs";
import { open, stat } from "node:fs/promises";
import { open, realpath, stat } from "node:fs/promises";
import type { ExecutionOptions } from "../AnalysisProvider.js";
import { BYTE_ENTROPY_PROVIDER } from "../../domain/investigationProviders.js";
import { AnalysisError } from "../../domain/analysisErrorBase.js";
@@ -12,7 +13,11 @@ import {
AnalysisInputError,
AnalysisResourceConstraintError,
} from "../../domain/analysisErrorCore.js";
import { createEvidence, type Evidence } from "../../domain/evidence.js";
import {
createEvidence,
withEvidenceCallerInputPath,
type Evidence,
} from "../../domain/evidence.js";
import {
byteEntropySchema,
computeBlockEntropy,
@@ -103,25 +108,30 @@ export class ByteEntropyService {
options?.signal,
);
if (!parsed.ok) return parsed;
const input = parsed.value;
let input = parsed.value;
const callerInputPath = input.path;
input = { ...input, path: absoluteCallerPath(input.path) };
const evidenceFromReport = (report: ByteEntropy): Evidence =>
createEvidence(
{ path: input.path, format: "file", sha256: report.artifact.sha256 },
BYTE_ENTROPY_PROVIDER,
{
operation: OPERATION,
parameters: {
path: input.path,
block_size: input.block_size,
offset: input.offset,
...(input.length === undefined ? {} : { length: input.length }),
withEvidenceCallerInputPath(
createEvidence(
{ path: input.path, format: "file", sha256: report.artifact.sha256 },
BYTE_ENTROPY_PROVIDER,
{
operation: OPERATION,
parameters: {
path: input.path,
block_size: input.block_size,
offset: input.offset,
...(input.length === undefined ? {} : { length: input.length }),
},
result: report,
rawResult: null,
confidence: "observed",
limitations: report.limitations,
locations: [{ kind: "artifact-path", path: input.path }],
},
result: report,
rawResult: null,
confidence: "observed",
limitations: report.limitations,
locations: [{ kind: "artifact-path", path: input.path }],
},
),
callerInputPath,
);
// Cleanup errors erase the callback's generic type. Validate their completed
// value before publishing it as this operation's observation.
@@ -176,6 +186,14 @@ export class ByteEntropyService {
const before = await this.files.stat(input.path, { bigint: true });
if (!before.isFile()) throw invalid("path", "Expected a regular file.");
admitted = true;
// Only an admitted selected file may consult filesystem spelling. Do not
// replace symlink/junction/8.3 aliases or touch source-derived paths.
if (process.platform === "win32") {
const canonical = await realpath(input.path).catch(() => undefined);
assertArtifactReadActive(options?.signal);
if (canonical?.toLowerCase() === input.path.toLowerCase())
input = { ...input, path: canonical };
}
const file = await this.files.open(
input.path,
constants.O_RDONLY | constants.O_NONBLOCK,