Skip to content

Commit d04569e

Browse files
vanceingallsclaude
andcommitted
fix(core): redact any path in telemetry, not an allowlist of roots
redactTelemetryString enumerated roots — /Users, /home, /opt, /tmp and a handful more — so a project on /data, /Volumes, an NFS mount or any root a user invented reached telemetry verbatim. Relative paths and bare basenames were never redacted at all, and audioPadTrim routes raw ffprobe stderr through this on every probe failure. Now redacts by shape: absolute paths under any root (two or more segments, so N/A and a 24/1 frame rate are not mistaken for one), relative paths including dash-prefixed ones, and bare basenames with an asset extension. URLs still keep their host and drop only the query. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 91a7cb1 commit d04569e

2 files changed

Lines changed: 112 additions & 6 deletions

File tree

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,53 @@ describe("redactTelemetryString", () => {
1616
),
1717
).toBe("[path] [path] [path] [path] [file-url] https://example.com/video.mp4?…");
1818
});
19+
20+
// The redactor used to enumerate roots (/Users, /home, /opt, /tmp, …). Any
21+
// root outside that list reached telemetry verbatim, which is most of them.
22+
it.each([
23+
"/data/media/interview.mov",
24+
"/mnt2/nfs/share/take3.wav",
25+
"/srv2/renders/2026/final.mp4",
26+
"/nix/store/abc123/asset.png",
27+
])("redacts the non-allowlisted absolute root in %s", (path) => {
28+
const out = redactTelemetryString(`ffprobe failed reading ${path}`);
29+
expect(out).not.toContain("/");
30+
expect(out).toContain("[path]");
31+
});
32+
33+
it("redacts relative paths, including a dash-prefixed one", () => {
34+
expect(redactTelemetryString("could not open ./assets/-weird-name.mp3")).toBe(
35+
"could not open [path]",
36+
);
37+
expect(redactTelemetryString("could not open ../-out.wav")).toBe("could not open [path]");
38+
expect(redactTelemetryString("could not open .\\tmp\\-x.aac")).toBe("could not open [path]");
39+
});
40+
41+
it("redacts a bare basename — a caller may pass one instead of a path", () => {
42+
expect(redactTelemetryString("Invalid data found in my-client-cut.mp4")).toBe(
43+
"Invalid data found in [file]",
44+
);
45+
});
46+
47+
// Over-redaction is cheap; these are ordinary in ffprobe stderr and turning
48+
// them into [path] would make a diagnostic string useless.
49+
it.each(["N/A", "24/1", "Stream #0:0", "moov atom not found", "48000/1001"])(
50+
"leaves %s alone",
51+
(text) => {
52+
expect(redactTelemetryString(`ffprobe: ${text}`)).toBe(`ffprobe: ${text}`);
53+
},
54+
);
55+
56+
// A `?` is illegal in a Windows filename, so this is not a query string —
57+
// the whole token is path, and must not survive by hiding behind a `?`.
58+
it("consumes the rest of the token once a path is established", () => {
59+
expect(redactTelemetryString("Navigation failed for C:\\Users\\A\\v.mov?not-a-query")).toBe(
60+
"Navigation failed for [path]",
61+
);
62+
});
63+
64+
it("truncates after redacting, so a long path cannot survive by being cut", () => {
65+
const out = redactTelemetryString(`/data/${"x".repeat(500)}/a.mp4`, 40);
66+
expect(out).not.toContain("xxx");
67+
});
1968
});

‎packages/core/src/telemetryRedaction.ts‎

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,70 @@ function redactUrlQueryStrings(value: string): string {
99
return value.replace(/\b(https?:\/\/[^\s?]+)\?[^\s]*/g, "$1?…");
1010
}
1111

12+
/**
13+
* Path characters we treat as part of a single segment. Space is deliberately
14+
* excluded: including it would let a match run past the path and swallow the
15+
* prose after it, and a path with a space still gets its remaining segments
16+
* redacted, which is the part that carries the identifying information.
17+
*/
18+
const SEGMENT = String.raw`[\w.\-@+()~]+`;
19+
20+
/**
21+
* Once a match is established as a path, consume the rest of the token.
22+
* Windows forbids `?` in a filename, so `video.mov?not-a-query` is not a real
23+
* query string — but stopping at the `?` would emit the remainder verbatim.
24+
* Redacting to the next delimiter cannot leak; stopping early can.
25+
*/
26+
const TOKEN_TAIL = String.raw`[^\s'")]*`;
27+
28+
/**
29+
* Absolute path, any root — NOT an allowlist of roots.
30+
*
31+
* The previous version enumerated `/Users`, `/home`, `/opt`, `/tmp`… which
32+
* meant a project on `/data`, `/Volumes/External`, an NFS mount or any root a
33+
* user invented reached telemetry verbatim. Two or more segments are required
34+
* so `N/A` and a `24/1` frame rate — both ordinary in ffprobe stderr — are not
35+
* mistaken for paths.
36+
*
37+
* The lookbehind keeps this off URLs: after `https:` the slash is preceded by
38+
* `:`, the second by `/`, and the path segment by a word character, so no
39+
* position inside a URL can start a match. URLs are handled above, where the
40+
* host is kept and only the query is dropped.
41+
*/
42+
const ABSOLUTE_PATH = new RegExp(
43+
String.raw`(?<![:\w/\\])(?:[A-Za-z]:)?(?:[\\/]${SEGMENT}){2,}${TOKEN_TAIL}`,
44+
"g",
45+
);
46+
47+
/** `./assets/bgm.mp3`, `../out.wav`, `.\tmp\x` — relative paths leak the same
48+
* project structure absolute ones do, and were previously untouched. */
49+
const RELATIVE_PATH = new RegExp(
50+
String.raw`(?<![\w/\\.])\.{1,2}(?:[\\/]${SEGMENT})+${TOKEN_TAIL}`,
51+
"g",
52+
);
53+
54+
/**
55+
* A bare basename with an asset extension. ffprobe reports the input by the
56+
* name it was given, so a caller that passes a basename (or a path this
57+
* flattened to its last segment) still names the user's file.
58+
*
59+
* The lookbehind excludes a slash so this cannot re-redact the tail of a URL
60+
* whose host we deliberately keep.
61+
*/
62+
const ASSET_BASENAME =
63+
/(?<![\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;
64+
1265
function redactFilePaths(value: string): string {
13-
return value
14-
.replace(/file:\/\/[^\s'")]+/g, "[file-url]")
15-
.replace(/\/Users\/[^\s'")]+/g, "[path]")
16-
.replace(/\/(?:home|root|opt|app|workspace|srv|mnt)\/[^\s'")]+/g, "[path]")
17-
.replace(/\/(?:private\/)?(?:var|tmp)\/[^\s'")]+/g, "[path]")
18-
.replace(/[A-Za-z]:\\[^\s'")]+/g, "[path]");
66+
return (
67+
value
68+
.replace(/file:\/\/[^\s'")]+/g, "[file-url]")
69+
// Relative BEFORE absolute: `./assets/x.mp3` has an absolute-looking tail
70+
// (`/assets/x.mp3`), so the absolute rule would consume it and leave the
71+
// leading `.` stranded outside the redaction.
72+
.replace(RELATIVE_PATH, "[path]")
73+
.replace(ABSOLUTE_PATH, "[path]")
74+
.replace(ASSET_BASENAME, "[file]")
75+
);
1976
}
2077

2178
export function redactTelemetryString(

0 commit comments

Comments
 (0)