normalizeFilePath() leaks the username whenever the viewing OS differs from the machine the path came from

Author: sxh313Created Sep 23, 2026Updated Sep 23, 2026

Version

main @ c2ad42e3; multimodal/tarko/ui/package.json is version 0.3.0.

Issue Description

normalizeFilePath() picks which user-directory patterns to apply based on the browser's platform, but the paths it is shown come from the agent server. When the two differ, no pattern matches, the function returns the input unchanged, and the username is displayed — even though this module's own header calls itself

 * Path normalization utilities for privacy and display optimization
 *
 * Features:
 * - Hide username information in file paths
 * - Cross-platform compatibility (Windows, macOS, Linux)

and its JSDoc documents a macOS, a Windows and a Linux example as though one call handled all three.

multimodal/tarko/ui/src/utils/pathNormalizer.ts:13-25

typescript
const USER_DIR_PATTERNS = {
  windows: [
    /^([A-Z]:[/\\])Users[/\\][^/\\]+([/\\].*)?$/i,
    /^([A-Z]:[/\\])Documents and Settings[/\\][^/\\]+([/\\].*)?$/i,
  ],
  unix: [/^\/Users\/[^/]+(\/.*)?\/?$/, /^\/home\/[^/]+(\/.*)?\/?$/],
} as const;

function detectPlatform(): 'windows' | 'unix' {
  return typeof navigator !== 'undefined' && navigator.platform.toLowerCase().includes('win')
    ? 'windows'
    : 'unix';
}

detectPlatform() result selects exactly one of the two sets (:48-49), so on any given browser the function can recognise path shapes from one OS family only. The two sets are mutually exclusive by construction — the Windows patterns require a drive letter, the POSIX patterns require a leading / — so nothing is ever matched "by accident" from the other set, which is what makes the miss total rather than partial.

Measured

pathNormalizer.ts has no dependency on anything but navigator, so I ran the real module (Node 24, --experimental-strip-types, globalThis.navigator replaced before the import, one fresh process per platform so the module's normalizedPathCache cannot carry state across runs) over 16 paths × 3 platforms = 48 calls. 16 of the 48 return the input unchanged with the username still in it. Every one of those 16 is a browser/OS-family mismatch:

navigator.platform input normalizeFilePath() output
Win32 /home/john/project/a.ts /home/john/project/a.ts
Win32 /Users/john/project/a.ts /Users/john/project/a.ts
Win32 /home/alice/.agent-tars-workspace/report.html /home/alice/.agent-tars-workspace/report.html
Win32 /home/john /home/john
Win32 /Users/john/ /Users/john/
Win32 /home/john/a/b/c/d.ts /home/john/a/b/c/d.ts
Linux C:\Users\john\project\a.ts C:\Users\john\project\a.ts
Linux C:/Users/john/project/a.ts C:/Users/john/project/a.ts
Linux C:\Users\john C:\Users\john
Linux C:\Users\john\ C:\Users\john\
Linux D:\Documents and Settings\bob\\\x\y.txt D:\Documents and Settings\bob\\\x\y.txt
MacIntel the same five Windows paths, unchanged

For contrast, all matching-platform calls already work: Win32 gives C:\Users\john\project\a.ts → ~\project\a.ts, Linux/MacIntel give /home/john/project/a.ts → ~/project/a.ts. Non-user paths are correctly left alone in every combination (/var/lib/notes/x.md, src/index.ts, ./relative/dir.ts, \\server\share\f.ts, '').

Why the mismatch is the normal case, not a corner

navigator.platform is read in a browser tab; absolutePath is a path on whatever machine runs the agent. tarko serve is documented as a "headless API server for system integration" (multimodal/tarko/agent-cli/README.md:27-28, 64-69, --port, default 8888 per src/core/options.ts:12), i.e. the server and the browser are separate processes and, for a remote or containerised server, separate operating systems. Nothing in the module assumes otherwise except detectPlatform() itself.

Where the result is displayed

All 12 in-repo call sites render the return value as user-visible text — multimodal/tarko/agent-ui/src/:

  • standalone/workspace/components/WorkspaceFileManager.tsx:219 and :222 — the file list's title attribute and its visible label, over file.path from the server's workspace listing;
  • standalone/chat/Message/components/ToolCalls.tsx:133 and :143 — path: … lines in chat tool-call summaries;
  • standalone/workspace/components/WorkspaceHeader.tsx:46 and :94;
  • standalone/workspace/components/FullscreenModal.tsx:69;
  • standalone/workspace/WorkspaceContent.tsx:29 — feeds the normalised workspace path into component state;

and multimodal/tarko/ui/src/components/code-editor/DiffViewer.tsx:46, :86, :97.

Expected vs. Actual

Expected: /home/john/project/a.ts → ~/project/a.ts regardless of which OS the tab is open on. Actual: returned verbatim when the browser reports Win32.

Suggested fix

Choose the pattern set by the shape of the path, not by the viewer: try all four patterns and take the remainder group of whichever matches. Windows patterns capture the drive root in group 1 and the remainder in group 2; POSIX patterns capture only the remainder, in group 1, so each entry needs its group index recorded (match[2] ?? match[1] would corrupt C:\Users\john, whose group 2 is undefined and whose group 1 is C:\). detectPlatform() then has no caller left.

This is strictly additive: I measured the same 48 calls after that change and 0 keep a username, while every call that already produced a ~-prefixed result produces the byte-identical string it did before (16 rows change, 32 do not).

Additional context

  • No existing issue or pull request mentions normalizeFilePath, pathNormalizer or USER_DIR_PATTERNS. A per-file scan of the changed paths of every open pull request (132 at the time of scanning) finds two that touch anything under multimodal/tarko/ui/ (#1821 src/components/markdown-renderer/MarkdownRenderer.tsx, #1547 src/components/basic/Dialog.tsx and src/components/markdown-renderer/components/Links.tsx) and none that touches src/utils/, so src/utils/pathNormalizer.ts itself is unclaimed.
  • multimodal/tarko/ui has no test runner (its only scripts are build and dev; no vitest dependency and no *.test.ts* file in the package), so a regression test here would mean adding one — I would rather ask than smuggle dev-dependency and pnpm-lock.yaml churn into a path fix. The measurements above are reproducible from the module alone.
  • navigator.platform is deprecated in browsers, which is a second reason not to key behaviour on it.

Source: bytedance/UI-TARS-desktop