Skip to content

Commit e79ab3a

Browse files
vanceingallsclaude
andcommitted
fix(core,producer): redact bare relative paths and the known input path
The generic scrub still missed a relative path with no `./` prefix: `customer/acme-secret/video.mp4` and `assets/bgm.mp3` reached telemetry completely unredacted, because the absolute rule needs a leading slash and the `./` rule needs the dot. Adds a rule for them that still leaves `N/A`, `24/1` and `48000/1001` alone. Shape matching is a net with holes by construction, so audioPadTrim now also redacts the exact path it put in the argv, plus its basename, before the generic scrub runs. It built the argv, so it does not have to guess. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent d04569e commit e79ab3a

4 files changed

Lines changed: 110 additions & 6 deletions

File tree

‎packages/core/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export {
252252
quantizeTimeToFrame,
253253
type MediaVisualStyleProperty,
254254
} from "./inline-scripts/parityContract";
255-
export { redactTelemetryString } from "./telemetryRedaction";
255+
export { redactKnownPaths, redactTelemetryString } from "./telemetryRedaction";
256256
export { isSafePath, resolveWithinProject } from "./safePath";
257257
export type {
258258
HyperframePickerApi,

‎packages/core/src/telemetryRedaction.test.ts‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from "vitest";
2-
import { redactTelemetryString } from "./telemetryRedaction.js";
2+
import { redactKnownPaths, redactTelemetryString } from "./telemetryRedaction.js";
33

44
describe("redactTelemetryString", () => {
55
it("redacts macOS, Linux, Windows, file URLs, and URL query strings", () => {
@@ -65,4 +65,52 @@ describe("redactTelemetryString", () => {
6565
const out = redactTelemetryString(`/data/${"x".repeat(500)}/a.mp4`, 40);
6666
expect(out).not.toContain("xxx");
6767
});
68+
69+
// Named explicitly in review: a relative path with NO `./` prefix was
70+
// missed by both the absolute rule (needs a leading slash) and the `./`
71+
// rule (needs the dot), so it reached telemetry completely unredacted.
72+
it.each([
73+
"customer/acme-secret/video.mp4",
74+
"assets/bgm.mp3",
75+
"projects/client-name/cut/final.mov",
76+
"a\\b\\c.wav",
77+
])("redacts the bare relative path %s", (path) => {
78+
const out = redactTelemetryString(`Invalid data found when processing ${path}`);
79+
expect(out).toBe("Invalid data found when processing [path]");
80+
});
81+
82+
it("redacts a dash-prefixed bare basename", () => {
83+
expect(redactTelemetryString("could not open -customer-secret-intro.mp4")).toBe(
84+
"could not open [file]",
85+
);
86+
});
87+
});
88+
89+
describe("redactKnownPaths", () => {
90+
// Shape matching has holes by construction. A caller that built the argv
91+
// knows the exact path, so it can name it instead of hoping a regex does.
92+
it("redacts an exact path a regex would not recognise as one", () => {
93+
const weird = "acme_secret_project";
94+
expect(redactKnownPaths(`ffprobe: ${weird}: Invalid data`, [weird])).toBe(
95+
"ffprobe: [path]: Invalid data",
96+
);
97+
});
98+
99+
it("redacts the basename too — ffprobe often reports only that", () => {
100+
const out = redactKnownPaths("moov atom not found in secret-cut.mp4", [
101+
"/data/x/secret-cut.mp4",
102+
]);
103+
expect(out).toContain("[path]");
104+
expect(out).not.toContain("secret-cut");
105+
});
106+
107+
it("leaves the message alone when no path was supplied", () => {
108+
expect(redactKnownPaths("moov atom not found", [])).toBe("moov atom not found");
109+
});
110+
111+
// Guards against a one/two-character basename turning every occurrence of
112+
// that letter into [path].
113+
it("ignores paths too short to be distinctive", () => {
114+
expect(redactKnownPaths("a stream at a rate", ["a"])).toBe("a stream at a rate");
115+
});
68116
});

‎packages/core/src/telemetryRedaction.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ function redactUrlQueryStrings(value: string): string {
1717
*/
1818
const SEGMENT = String.raw`[\w.\-@+()~]+`;
1919

20+
/** Same, minus the dot, so a trailing `.ext` can be matched separately. */
21+
const SEGMENT_NODOT = String.raw`[\w\-@+()~]+`;
22+
2023
/**
2124
* Once a match is established as a path, consume the rest of the token.
2225
* Windows forbids `?` in a filename, so `video.mov?not-a-query` is not a real
@@ -62,6 +65,53 @@ const RELATIVE_PATH = new RegExp(
6265
const ASSET_BASENAME =
6366
/(?<![\w/\\])[\w.\-@+()~]+\.(?:mp4|mov|mkv|webm|avi|m4v|mpe?g|ts|mp3|wav|aac|m4a|flac|ogg|opus|png|jpe?g|gif|webp|svg|html?|json|srt|vtt|ass)\b/gi;
6467

68+
/**
69+
* A relative path with NO `./` prefix — `assets/bgm.mp3`,
70+
* `customer/acme-secret/video.mp4`. These leak exactly as much as an absolute
71+
* path and were missed by both rules above: the absolute rule requires a
72+
* leading slash, and the `./` rule requires the dot.
73+
*
74+
* Qualifying needs either two separators or one plus a file extension, so the
75+
* ordinary non-paths in ffprobe stderr — `N/A`, a `24/1` frame rate,
76+
* `48000/1001` — do not match. The lookbehind keeps it off URL paths, whose
77+
* host is deliberately kept.
78+
*/
79+
const BARE_RELATIVE_PATH = new RegExp(
80+
[
81+
// Two or more separators: `customer/acme/video.mp4`. No extension needed —
82+
// that much structure is already a path.
83+
String.raw`(?<![\w/\\.:@-])(?:${SEGMENT}[\\/]){2,}${SEGMENT}${TOKEN_TAIL}`,
84+
// One separator, but the last segment carries a file extension:
85+
// `assets/bgm.mp3`. That segment is dot-free on purpose — SEGMENT includes
86+
// `.`, so a greedy one swallows the extension this rule needs.
87+
String.raw`(?<![\w/\\.:@-])${SEGMENT}[\\/]${SEGMENT_NODOT}\.\w{1,8}\b${TOKEN_TAIL}`,
88+
].join("|"),
89+
"g",
90+
);
91+
92+
/**
93+
* Redact literal strings — the exact paths a caller KNOWS it passed — before
94+
* any shape-based rule runs.
95+
*
96+
* Shape matching is a net with holes by construction; this is not. When the
97+
* caller has the path in hand (it built the argv), spell it out rather than
98+
* hoping a regex recognises it, and take the basename too since ffprobe often
99+
* reports only that.
100+
*/
101+
export function redactKnownPaths(value: string, paths: readonly string[]): string {
102+
let out = value;
103+
for (const path of paths) {
104+
if (typeof path !== "string" || path.length === 0) continue;
105+
// Longest first: replacing the basename before the full path would leave
106+
// the directory prefix stranded.
107+
const basename = path.split(/[\\/]/).pop() ?? "";
108+
for (const literal of [path, basename].filter((v) => v.length > 2)) {
109+
out = out.split(literal).join("[path]");
110+
}
111+
}
112+
return out;
113+
}
114+
65115
function redactFilePaths(value: string): string {
66116
return (
67117
value
@@ -71,6 +121,7 @@ function redactFilePaths(value: string): string {
71121
// leading `.` stranded outside the redaction.
72122
.replace(RELATIVE_PATH, "[path]")
73123
.replace(ABSOLUTE_PATH, "[path]")
124+
.replace(BARE_RELATIVE_PATH, "[path]")
74125
.replace(ASSET_BASENAME, "[file]")
75126
);
76127
}

‎packages/producer/src/services/render/audioPadTrim.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
trackChildProcess,
3131
type AudioMetadata,
3232
} from "@hyperframes/engine";
33-
import { redactTelemetryString } from "@hyperframes/core";
33+
import { redactKnownPaths, redactTelemetryString } from "@hyperframes/core";
3434

3535
/**
3636
* Tolerance used to decide whether an audio file is already short enough to
@@ -461,9 +461,14 @@ async function runFfprobeJson<T>(args: string[], signal?: AbortSignal): Promise<
461461
throw outcome.error ?? new Error(outcome.stderr);
462462
}
463463
if (outcome.reason !== "exit" || outcome.exitCode !== 0) {
464-
// Redacted: raw ffprobe stderr echoes the input path, and this message
465-
// reaches logs and telemetry.
466-
throw new Error(`ffprobe ${outcome.reason}: ${redactTelemetryString(outcome.stderr, 2000)}`);
464+
// Redacted twice, deliberately. The shape-based scrub is a net with
465+
// holes — it cannot know that `customer/acme-secret/video.mp4` is a path
466+
// and `48000/1001` is not — but THIS caller knows the exact path it put
467+
// in the argv, so it names it literally first. The message reaches logs,
468+
// telemetry, and `PadTrimAudioResult.error`.
469+
const probed = args[args.length - 1];
470+
const scrubbed = redactKnownPaths(outcome.stderr, probed === undefined ? [] : [probed]);
471+
throw new Error(`ffprobe ${outcome.reason}: ${redactTelemetryString(scrubbed, 2000)}`);
467472
}
468473
try {
469474
return JSON.parse(stdout) as T;

0 commit comments

Comments
 (0)