MoonshotAI / MoonshotAI/kimi-code

Telemetry path redaction fails for non-ASCII home directories, UNC paths, and `C:/` spellings

Open
#2,418 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

What happens

cleanTelemetryString in packages/agent-core-v2/src/app/telemetry/privacy.ts is the last step before an event leaves the process — CloudAppender.track cleans properties, buffers the EnrichedCloudEvent, and CloudTransport POSTs it (cloudAppender.ts:115). Its job is to turn absolute file paths into <REDACTED: user-file-path>.

It does that for C:\Users\alice\proj\x.txt and /home/alice/proj/x.txt. It does not do it for a home directory whose name is not ASCII, nor for a UNC path, nor for a drive-letter path written with forward slashes. In those cases the user name — and usually the rest of the path — goes out verbatim.

Both patterns are built from \w:

const POSIX_PATH = /(?:\/[\w.~+-]+){2,}\/?/g;
const WINDOWS_PATH = /\b[A-Za-z]:\\(?:[\w.~ -]+\\?){2,}/g;

\w is [A-Za-z0-9_]. Without the u flag there is no Unicode property escape, so the match ends at the first non-ASCII byte.

Measured, on main
case input main produces leaked
POSIX, CJK home dir /home/李明/proj/secret.txt /home/李明<REDACTED: user-file-path> 李明
Windows, CJK home dir C:\Users\李明\proj\secret.txt <REDACTED: user-file-path>李明\proj\secret.txt 李明, secret.txt
POSIX, Cyrillic home dir /home/иван/proj/secret.txt /home/иван<REDACTED: user-file-path> иван
POSIX, accented home dir /home/josé/proj/secret.txt <REDACTED: user-file-path>é<REDACTED: user-file-path> (name split, é emitted)
Windows, accented home dir C:\Users\josé\proj\secret.txt <REDACTED: user-file-path>é\proj\secret.txt secret.txt
Windows, apostrophe in name C:\Users\O'Brien\proj\secret.txt <REDACTED: user-file-path>'Brien\proj\secret.txt Brien, secret.txt
UNC share \\fileserver\home\alice.chen\proj\secret.txt (unchanged) the whole path
Windows, forward slashes C:/Users/alice.chen/proj/secret.txt C:<REDACTED: user-file-path> drive letter

Three separate root causes:

  1. \w is ASCII-only. Any non-ASCII character in any segment truncates the match there. A CJK, Cyrillic, or accented home directory name is the common case; so is O'Brien, since ' is not in \w either.
  2. UNC and \\?\ long-path forms are not matched at all. WINDOWS_PATH requires [A-Za-z]:\, and \b before it does not help — \\server\share\... has no drive letter, so nothing matches and the value is emitted as-is.
  3. C:/a/b is only half-handled. WINDOWS_PATH requires a backslash, so the drive letter is left behind and the POSIX pattern redacts only the tail, yielding C:<REDACTED: ...>. Node normalizes to forward slashes in plenty of places, so this spelling reaches telemetry in practice.
Two smaller behaviour bugs in the same function
  • The node_modules/ tail is discarded on Windows. The marker is spelled with a forward slash and the Windows branch does not look for it at all, so C:\...\node_modules\pkg\index.js becomes a bare placeholder. The module docstring says these tails are kept "because they carry diagnostic value without user data" — that only holds on POSIX today.
  • WINDOWS_PATH allows a bare space inside a segment with no separator required after it, so C:\Program Files\a.txt could not be read redacts to <REDACTED: user-file-path> — the message text is swallowed. Not a privacy leak, but it destroys the diagnostic.
Why it matters

This is the final hop before a remote POST, and the redaction is silent: nothing logs or errors when a pattern fails to match, so a leak looks identical to a clean event. agent-core-v2 is consumed by apps/kimi-code and several other packages, so it applies to shipped builds.

Non-ASCII home directory names are not an edge case for this project's user base in particular. On a Chinese-locale Windows install, C:\Users\<name> with a CJK name is ordinary.

There is currently no test file for privacy.ts, so none of this is covered.

Expected

Every absolute path is redacted regardless of the script its segments are written in, and regardless of which Windows spelling it uses; the node_modules/ tail is preserved on both platforms; text that is not an absolute path is left alone.

Environment

main, packages/agent-core-v2. Reproducible by calling cleanTelemetryString directly with the inputs above.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/agent-core-v2/src/app/telemetry/privacy.ts at cleanTelemetryString and its POSIX_PATH and WINDOWS_PATH patterns; reproduce the listed inputs directly before changing behavior. Add coverage for Unicode names, UNC and long-path forms, forward-slash drive paths, node_modules tails, and message text, then verify absolute paths are fully redacted while non-path text remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
observability, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.