A desktop coding agent with free access to frontier models.
TypeScript
fix: hide windows account names in paths
ogsamrat4daded572068
diff --git a/apps/server/src/capture-context.test.ts b/apps/server/src/capture-context.test.tsindex dca44ef8..b79c0e29 100644--- a/apps/server/src/capture-context.test.ts+++ b/apps/server/src/capture-context.test.ts@@ -75,6 +75,30 @@ function assertNoSecrets(value, secrets = [GH_TOKEN, NPM_TOKEN, AWS_SECRET, PASS// --- privacy ------------------------------------------------------------------------+test("privacy: a Windows account name in a profile path is masked in every form, the path kept (WSL, Git Bash, \\wsl$, names with spaces)", () => {+ // WSL: the Windows account is called the same as the Linux one, or not; never "/mnt/c~".+ const same = { home: "/home/sam", user: "sam" };+ assert.equal(privacy.tildeText("cd /mnt/c/Users/sam/app && ls /home/sam", same), "cd /mnt/c/Users/user/app && ls ~");+ assert.equal(privacy.tildeText("/mnt/c/Users/WinName/app", same), "/mnt/c/Users/user/app");+ assert.equal(privacy.tildeText("/mnt/d/Users/sam", same), "/mnt/d/Users/user");+ assert.equal(privacy.tildeText("/mnt/c/Users/user/x and /Users/user/y", { home: "/home/user", user: "user" }), "/mnt/c/Users/user/x and ~/y");+ // Names with spaces: the whole segment (another segment or a closing quote follows); in prose the name ends at a space.+ assert.equal(privacy.maskWindowsProfiles("cd '/mnt/c/Users/Jane Doe/proj'"), "cd '/mnt/c/Users/user/proj'");+ assert.equal(privacy.maskWindowsProfiles('"C:\\Users\\Jane Doe"'), '"C:\\Users\\user"');+ assert.equal(privacy.maskWindowsProfiles("C:\\Users\\sam and more."), "C:\\Users\\user and more.");+ // Drive paths, either slash, any case, JSON-escaped; Git Bash and Cygwin; the WSL home from Windows.+ assert.equal(privacy.maskWindowsProfiles("C:\\Users\\Al.ice\\x c:/users/bob D:\\Users\\Carol."), "C:\\Users\\user\\x c:/users/user D:\\Users\\user.");+ assert.equal(privacy.maskWindowsProfiles('{"cwd":"C:\\\\Users\\\\sam\\\\proj"}'), '{"cwd":"C:\\\\Users\\\\user\\\\proj"}');+ assert.equal(privacy.maskWindowsProfiles("/c/Users/Alice/x /cygdrive/c/Users/Alice"), "/c/Users/user/x /cygdrive/c/Users/user");+ assert.equal(privacy.maskWindowsProfiles("\\\\wsl$\\Ubuntu\\home\\sam\\p \\\\wsl.localhost\\Ubuntu-22.04\\home\\sam //wsl$/Ubuntu/home/sam"), "\\\\wsl$\\Ubuntu\\home\\user\\p \\\\wsl.localhost\\Ubuntu-22.04\\home\\user //wsl$/Ubuntu/home/user");+ // The same name always masks the same; shared profiles and lookalikes stay.+ assert.equal(privacy.maskWindowsProfiles("/mnt/c/Users/sam/a /mnt/c/Users/sam/b"), "/mnt/c/Users/user/a /mnt/c/Users/user/b");+ for (const kept of ["C:\\Users\\Public\\Desktop", "/mnt/c/Users/", "src/c/Users/x", "C:\\Program Files\\x", "/home/sam"]) assert.equal(privacy.maskWindowsProfiles(kept), kept);+ // The uploader's scrub masks it in every trace string and file too, and counts it (a changed text is never "clean").+ assert.deepEqual(uploader.redactUploadText("cd /mnt/c/Users/WinName/app"), { text: "cd /mnt/c/Users/user/app", count: 1 });+ assert.deepEqual(uploader.redactUploadText("cd /mnt/c/Users/user/app"), { text: "cd /mnt/c/Users/user/app", count: 0 });+});+test("privacy: the home directory and the account name become ~; URLs lose userinfo; addresses become classes", () => {const ctx = { home: "/home/alice", user: "alice" };assert.equal(privacy.tildeText("cd /home/alice/proj && ls /home/alice", ctx), "cd ~/proj && ls ~");diff --git a/apps/server/src/context/PARITY.sha256 b/apps/server/src/context/PARITY.sha256index 89541ddd..4ad86eb0 100644--- a/apps/server/src/context/PARITY.sha256+++ b/apps/server/src/context/PARITY.sha256@@ -7,7 +7,7 @@ bc7d049e7749bef129e23dcb0b6bde3bd733af0a0db3ede2e3b486cd49727e38 index.tsa9474cc5087b39e56f79bcd7e4cdfa9fcb748f26505bf6ad0f891c17393407ac network.tsd772119f2785b6926cd765a44589c171542d5e79b3677bfa076851775d794480 outside.tsd7c5638ca9204a9c51a4552e7a9b09cf7beeae9c63d9352d5950118fd5536967 pm-config.ts-d13231905671ad40fdd73e3fe7af81e44dcc909ace606f45a79c215984b6b35d privacy.ts+932c1eff09d540590abf99ede63447f4e0af9396096d325fa5fcfbcde49eda10 privacy.ts0e04845a2d0ad2136c01a61d3ed1193b62ef99f5b82e1f555b7c97bb6dc18773 processes.ts0c831e9c763e9fd5504fa76ad3863f15693b5c6b5da0b25e1669c2593702737b redact-policy.ts87f77398205e7427136ab9e3199352e3b878532671ffd19d8fbe2e889b03e2e8 redact-vectors.jsondiff --git a/apps/server/src/context/privacy.ts b/apps/server/src/context/privacy.tsindex 90d75355..bfa926c2 100644--- a/apps/server/src/context/privacy.ts+++ b/apps/server/src/context/privacy.ts@@ -1,8 +1,11 @@// What every capture-context item goes through before it is recorded: the// home directory (and the account name wherever it appears in a path) becomes-// `~`, URLs lose their userinfo and secret-looking query values, and the-// text runs through the uploader's CONFIG secret scrub (injected, so this-// module is the same in the CLI and the desktop app).+// `~`, a Windows account's name in a profile path becomes `user` (whatever+// form the path takes: C:\Users\<name>, /mnt/c/Users/<name> under WSL,+// /c/Users/<name> in Git Bash, \\wsl$\<distro>\home\<name>), URLs lose+// their userinfo and secret-looking query values, and the text runs through+// the uploader's CONFIG secret scrub (injected, so this module is the same in+// the CLI and the desktop app).import { homedir, userInfo } from "node:os";@@ -41,10 +44,45 @@ function escapeRegExp(text: string): string {const homeRegexCache = new Map<string, RegExp>();+/** What an account name in a Windows profile path becomes (one placeholder for every name, so the same name always masks the same). */+export const PROFILE_PLACEHOLDER = "user";+/** Profile folders that are not an account: kept. */+const SHARED_PROFILES = new Set(["public", "default", "default user", "all users", "defaultapppool", "wdagutilityaccount", PROFILE_PLACEHOLDER]);+/** A path separator: `/`, or a run of backslashes (JSON-escaped text doubles them). */+const SEP = String.raw`(?:\\+|/)`;+/** A character of a profile folder's name. */+const NAME_CHAR = String.raw`[^\\/\s"'\`<>|:*?;,()\[\]{}]`;+/**+ * A Windows profile path up to the account name: `<drive>:\Users\` (either+ * slash), `/mnt/<drive>/Users/` (WSL), `/<drive>/Users/` and+ * `/cygdrive/<drive>/Users/` (Git Bash, Cygwin), and the WSL home seen from+ * Windows, `\\wsl$\<distro>\home\` (or `\\wsl.localhost`). Then the name: one+ * path segment, with spaces only when another segment or a closing quote+ * follows (in free text a name ends at a space), never ending in a dot+ * (sentence punctuation).+ */+const WINDOWS_PROFILE = new RegExp(+ String.raw`((?<![\w.$-])(?:/mnt|/cygdrive)?/[A-Za-z]/[Uu][Ss][Ee][Rr][Ss]/|(?<![\w])[A-Za-z]:${SEP}[Uu][Ss][Ee][Rr][Ss]${SEP}|(?:\\+|//)wsl(?:\$|\.localhost)${SEP}[^\\/\s"']+${SEP}home${SEP})`+ + String.raw`(${NAME_CHAR}+(?: ${NAME_CHAR}+)*(?=\\|/|["'\`])|${NAME_CHAR}*[^\\/\s"'\`<>|:*?;,()\[\]{}.])`,+ "g",+);++/**+ * Every Windows account name in a profile path as PROFILE_PLACEHOLDER, the+ * path otherwise as it was: `/mnt/c/Users/Jane Doe/app` becomes+ * `/mnt/c/Users/user/app`, `C:\Users\sam` becomes `C:\Users\user`. Shared+ * profiles (Public, Default, All Users) are kept.+ */+export function maskWindowsProfiles(text: string): string {+ if (!text || !/users|wsl/i.test(text)) return text;+ return text.replace(WINDOWS_PROFILE, (match: string, root: string, name: string) => (SHARED_PROFILES.has(name.toLowerCase()) ? match : root + PROFILE_PLACEHOLDER));+}+/*** Replaces the home directory with `~` wherever it appears in `text` (both* slash styles on Windows), and any other home-style path of the account- * (`/home/<user>`, `/Users/<user>`, `C:\Users\<user>`) the same way.+ * (`/home/<user>`, `/Users/<user>`) the same way. Every other Windows profile+ * path keeps its shape with the account name masked (maskWindowsProfiles).*/export function tildeText(text: string, privacy: PrivacyContext): string {if (!text) return text;@@ -63,12 +101,13 @@ export function tildeText(text: string, privacy: PrivacyContext): string {}out = out.replace(pattern, "~");}+ // A Windows profile that is not the home (WSL's /mnt/c/Users/<name>, whatever the Windows account is called).+ out = maskWindowsProfiles(out);const user = privacy.user;if (user && user.length >= 2 && /^[\w.@-]+$/.test(user)) {const name = escapeRegExp(user);- out = out- .replace(new RegExp(`(?:/home|/Users|/var/home)/${name}(?=$|[/\\s"'\`:;,)\\]}>])`, "g"), "~")- .replace(new RegExp(`[A-Za-z]:[\\\\/]Users[\\\\/]${name}(?=$|[\\\\/\\s"'\`:;,)\\]}>])`, "gi"), "~");+ // Not inside a drive's profile folder (/mnt/c/Users/<user>, /c/Users/<user>): that is masked above, structure kept.+ out = out.replace(new RegExp(`(?<!/[A-Za-z]|[A-Za-z]:)(?:/home|/Users|/var/home)/${name}(?=$|[/\\s"'\`:;,)\\]}>])`, "g"), "~");}return out;}diff --git a/apps/server/src/session-uploader.ts b/apps/server/src/session-uploader.tsindex 8b010349..c8c30e90 100644--- a/apps/server/src/session-uploader.ts+++ b/apps/server/src/session-uploader.ts@@ -31,6 +31,7 @@ import { ToolchainCache, type CollectOptions as ToolchainOptions, type UploadTooimport { engine2ImportedFrom } from "./engine2/imported.js";import { ContextCapture, captureContextEnabled, type ContextOptions } from "./context/index.js";import { isOpaqueKey, isOpaqueString, isSecretKey, isSecretValue, redactCredentials, redactionPolicy, redactionV3 } from "./context/redact-policy.js";+import { maskWindowsProfiles } from "./context/privacy.js";import bundledBestPractices from "./bundled-best-practices.json" with { type: "json" };import serverPackage from "../package.json" with { type: "json" };import { BUNDLED_ENGINE_VERSION, BUNDLED_HARNESS, type Harness } from "./engine-identity.js";@@ -1552,11 +1553,15 @@ export type RedactUploadTextOptions = {* never contains a dangling backslash, so JSON-escaped text stays escapable.*/export function redactUploadText(input: string, options: RedactUploadTextOptions = {}): { text: string; count: number } {+ // A Windows account name in a profile path (C:\Users\<name>, WSL's /mnt/c/Users/<name>): masked, the path kept, under every rule set.+ const masked = maskWindowsProfiles(input);+ const profiles = masked !== input ? 1 : 0;+ input = masked;if (redactionV3()) {const result = redactCredentials(input, { context: options.context, mode: options.mode, awsContext: options.awsContext });- return { text: result.text, count: result.count };+ return { text: result.text, count: result.count + profiles };}- const tally = { count: 0 };+ const tally = { count: profiles };let text = input.includes("-----BEGIN ") ? applyRedaction(input, PRIVATE_KEY_BLOCK, tally) : input;if (text.includes("://")) text = applyRedaction(text, URL_USERINFO, tally);const mode = options.mode ?? "config";