diff --git a/tests/desktop-d2.test.ts b/tests/desktop-d2.test.ts index 66758b76..b93ce054 100644 --- a/tests/desktop-d2.test.ts +++ b/tests/desktop-d2.test.ts @@ -12,7 +12,7 @@ import { draftMarkdown, draftName, parseDraft } from '../cli/lib/reviews'; import { findIcon, iconCandidates, iconDataUrl, listingCompleteness, readReplyDrafts, setApproved } from '../cli/lib/project-files'; import { TEMPLATE_TEXT } from '../cli/lib/template-files'; import { installCommands } from '../cli/lib/tools'; -import { NEUTRAL_ROOT, neutralize } from '../tools/build-sidecars'; +import { NEUTRAL_ROOT, neutralize, privateStrings } from '../tools/build-sidecars'; const ROOT = join(import.meta.dir, '..'); const tmp = () => mkdtempSync(join(tmpdir(), 'sb-d2-')); @@ -145,6 +145,11 @@ describe('doctor and playwright', () => { const js = 'var a = __require.resolve("/work/sb/node_modules/x/package.json"); var __dirname = "/work/sb/node_modules/x/lib";'; expect(neutralize(js, '/work/sb')).toBe(`var a = "${NEUTRAL_ROOT}/node_modules/x/package.json"; var __dirname = "${NEUTRAL_ROOT}/node_modules/x/lib";`); }); + test('sidecar leak check: a person\'s home and the checkout, not a CI container\'s /root', () => { + expect(privateStrings('/Users/you', '/work/sb')).toEqual(['/Users/you', '/work/sb']); + expect(privateStrings('/root', '/workspace/o/sb')).toEqual(['/workspace/o/sb']); + expect(privateStrings('/home/runner', '/home/runner/work/sb')).toEqual(['/home/runner/work/sb']); + }); test('install commands per OS, never empty for the tools that have a package', () => { expect(installCommands('ffmpeg', 'darwin')).toEqual(['brew install ffmpeg']); expect(installCommands('ffmpeg', 'win32')[0]).toContain('winget'); diff --git a/tools/build-sidecars.ts b/tools/build-sidecars.ts index aa0dd629..238dc841 100644 --- a/tools/build-sidecars.ts +++ b/tools/build-sidecars.ts @@ -32,9 +32,13 @@ export function hostTarget(): string { export const outName = (target: string): string => `storebound-${TARGETS[target]}${target.includes('windows') ? '.exe' : ''}`; +/** Home folders of build accounts that name nobody (a CI container runs as root). They are not searched for: "/root" + * is a substring of the bun runtime itself (root_certs.cpp, ICU's root.res). privacy-scan still checks every home. */ +export const GENERIC_HOME = /^(\/root|\/home\/(runner|ubuntu|build|builder|ci|docker|node|user))\/?$/; + /** Paths of this machine that must not appear in a shipped binary. */ -export function privateStrings(): string[] { - return [...new Set([homedir(), ROOT].filter(s => s.length > 4))]; +export function privateStrings(home = homedir(), root = ROOT): string[] { + return [...new Set([GENERIC_HOME.test(home) ? '' : home, root].filter(s => s.length > 4))]; } export function leaks(file: string, needles = privateStrings()): string[] {