A desktop coding agent with free access to frontier models.
TypeScript
fix: harden workspace collector privacy
Samrat Talukdar49e28e8ab695
diff --git a/apps/server/src/workspace-collector.test.ts b/apps/server/src/workspace-collector.test.tsindex 3b2c99d1..7ea465d0 100644--- a/apps/server/src/workspace-collector.test.ts+++ b/apps/server/src/workspace-collector.test.ts@@ -1,6 +1,6 @@import { afterEach, describe, expect, test } from "bun:test";import { execFile } from "node:child_process";-import { mkdtemp, rm, writeFile } from "node:fs/promises";+import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";import { promisify } from "node:util";@@ -35,15 +35,25 @@ describe("workspace collector privacy", () => {expect(result.count).toBeGreaterThanOrEqual(3);});+ test("scrubs common personal identifiers before upload", () => {+ const result = redactCollectorText("[email protected] +1 (415) 555-0132");+ expect(result.text).not.toContain("[email protected]");+ expect(result.text).not.toContain("415");+ expect(result.count).toBe(2);+ });+test("uploads correlated start, trace, and end artifacts without ignored or binary files", async () => {const root = await mkdtemp(join(tmpdir(), "omnirush-collector-"));roots.push(root);await execFileAsync("git", ["init", "-q", root]);await writeFile(join(root, ".gitignore"), "ignored.txt\n");+ await mkdir(join(root, "nested"));+ await writeFile(join(root, "nested", ".gitignore"), "ignored-nested.txt\n");await writeFile(join(root, "app.txt"), "hello sk-1234567890abcdefghijklmnop\n");await writeFile(join(root, "ignored.txt"), "do not upload\n");await writeFile(join(root, ".env.local"), "PASSWORD=secret-value\n");await writeFile(join(root, "binary.dat"), Buffer.from([0, 1, 2, 3]));+ await writeFile(join(root, "nested", "ignored-nested.txt"), "do not upload\n");const uploads: Array<{ sessionId: string; envelope: Record<string, unknown> }> = [];const collector = new WorkspaceCollector({@@ -68,9 +78,9 @@ describe("workspace collector privacy", () => {const paths = uploads.flatMap((upload) => (upload.envelope.files as Array<{ path: string }>).map((file) => file.path));expect(paths).toContain("app.txt");expect(paths).not.toContain("ignored.txt");+ expect(paths).not.toContain("nested/ignored-nested.txt");expect(paths).not.toContain(".env.local");expect(paths).not.toContain("binary.dat");expect(JSON.stringify(uploads)).not.toContain("sk-1234567890abcdefghijklmnop");});});-diff --git a/apps/server/src/workspace-collector.ts b/apps/server/src/workspace-collector.tsindex e1a90672..bc8ca78c 100644--- a/apps/server/src/workspace-collector.ts+++ b/apps/server/src/workspace-collector.ts@@ -80,6 +80,11 @@ const SECRET_PATTERNS: Array<[RegExp, string]> = [[/\b(?:sk|rk|pk)-(?:proj-)?[A-Za-z0-9_-]{16,}\b/g, "[REDACTED]"],[/^([A-Z][A-Z0-9_]*(?:TOKEN|SECRET|PASSWORD|API_KEY)\s*=\s*)([^\s#]{6,})$/gim, "$1[REDACTED]"],];+const PII_PATTERNS: Array<[RegExp, string]> = [+ [/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi, "[REDACTED_PII]"],+ [/(?<!\w)(?:\+\d{1,3}[\s.-]?)?(?:\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4})(?!\w)/g, "[REDACTED_PII]"],+ [/(?<!\w)\d{3}-\d{2}-\d{4}(?!\w)/g, "[REDACTED_PII]"],+];function resolveCollectUrl(rawGatewayUrl: string | undefined): string | null {const value = rawGatewayUrl?.trim();@@ -123,6 +128,13 @@ export function redactCollectorText(input: string): { text: string; count: numbepattern.lastIndex = 0;text = text.replace(pattern, replacement);}+ for (const [pattern, replacement] of PII_PATTERNS) {+ pattern.lastIndex = 0;+ const matches = text.match(pattern);+ count += matches?.length ?? 0;+ pattern.lastIndex = 0;+ text = text.replace(pattern, replacement);+ }return { text, count };}@@ -136,9 +148,9 @@ function isBinary(buffer: Buffer): boolean {return sample.length > 0 && suspicious / sample.length > 0.1;}-async function readRootGitignore(root: string): Promise<string[]> {+async function readGitignoreFile(directory: string): Promise<string[]> {try {- return (await readFile(resolve(root, ".gitignore"), "utf8"))+ return (await readFile(resolve(directory, ".gitignore"), "utf8")).split(/\r?\n/).map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));@@ -158,8 +170,15 @@ function ignoredByRules(path: string, rules: string[]): boolean {return ignored;}-async function walkFallback(root: string, directory = root, rules?: string[], output: string[] = []): Promise<string[]> {- const ignoreRules = rules ?? await readRootGitignore(root);+async function walkFallback(root: string, directory = root, rules: string[] = [], output: string[] = []): Promise<string[]> {+ const localRules = await readGitignoreFile(directory);+ const prefix = portablePath(root, directory);+ const ignoreRules = [...rules, ...localRules.map((rule) => {+ const negated = rule.startsWith("!");+ const body = negated ? rule.slice(1) : rule;+ const scoped = prefix ? `${prefix}/${body}` : body;+ return negated ? `!${scoped}` : scoped;+ })];let entries;try {entries = await readdir(directory, { withFileTypes: true });