From 7814f834fb5366402a6efaaf6c62a3282feff912 Mon Sep 17 00:00:00 2001 From: Studio Date: Fri, 27 Nov 2026 12:03:37 -0500 Subject: [PATCH 1/2] T-11: audit-secrets skips any match containing `${`, so a hardcoded user:pass with an interpolated host is missed --- scripts/audit-secrets.ts | 6 +++-- scripts/test/security.test.ts | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/scripts/audit-secrets.ts b/scripts/audit-secrets.ts index c57435f8..ff757830 100644 --- a/scripts/audit-secrets.ts +++ b/scripts/audit-secrets.ts @@ -43,11 +43,13 @@ export function findEmbeddedHttpCredentials(content: string): number[] { for (let index = 0; index < lines.length; index++) { const line = lines[index] ?? ''; for (const match of line.matchAll(httpCredentialPattern)) { - const fullMatch = match[0] ?? ''; + const user = match[1] ?? ''; + const password = match[2] ?? ''; const host = match[3] ?? ''; const normalizedHost = host.replace(/\.$/, ''); if ( - fullMatch.includes('${') || + user.includes('${') || + password.includes('${') || !normalizedHost || normalizedHost.startsWith('.') || isPlaceholderHost(normalizedHost) diff --git a/scripts/test/security.test.ts b/scripts/test/security.test.ts index 9b5f9756..26061c44 100644 --- a/scripts/test/security.test.ts +++ b/scripts/test/security.test.ts @@ -425,6 +425,49 @@ test('embedded HTTP(S) credential audit catches real credentials with line numbe expect(serialized).not.toContain('proxy-user'); }); +test('embedded HTTP(S) credential audit reports hardcoded credentials with interpolated hosts and skips interpolated credentials', () => { + const buildUrl = (scheme: string, user: string, pass: string, host: string) => + `${scheme}://${user}:${pass}@${host}`; + + const interpHost = buildUrl('http', 'realuser', 'realpass', '${proxyHost}:80'); + const partialInterpHost = buildUrl('https', 'realuser', 'realpass', 'sub.${domain}/v1'); + const ipv6InterpHost = buildUrl('http', 'realuser', 'realpass', '[${ipv6Host}]:80'); + const placeholderSubInterp = buildUrl('http', 'realuser', 'realpass', '${sub}.example.com:80'); + + const lines = [ + 'const bothInterpDocHost = `http://${user}:${pass}@host:80`;', + 'const bothInterpRealHost = `http://${user}:${pass}@proxy.vendor.io:80`;', + 'const allInterp = `http://${user}:${pass}@${proxyHost}:80`;', + 'const userOnlyInterp = `http://${user}:realpass@proxy.vendor.io:80`;', + 'const userOnlyInterpHost = `http://${user}:realpass@${proxyHost}:80`;', + 'const passOnlyInterp = `http://realuser:${pass}@proxy.vendor.io:80`;', + 'const passOnlyInterpHost = `http://realuser:${pass}@${proxyHost}:80`;', + `const placeholderSub = \`${placeholderSubInterp}\`;`, + `const leakedInterpHost = \`${interpHost}\`;`, + `const leakedPartialInterpHost = \`${partialInterpHost}\`;`, + `const leakedIpv6InterpHost = \`${ipv6InterpHost}\`;`, + `const mixedSameLine = [\`http://\${user}:\${pass}@proxy.vendor.io:80\`, \`${interpHost}\`];`, + ].join('\n'); + + expect(findEmbeddedHttpCredentials(lines)).toEqual([9, 10, 11, 12]); + + const files = new Map([ + ['apps/stock/proxy.ts', Buffer.from(`const url = \`${interpHost}\`;\n`)], + ]); + const findings = scanTrackedFilesForHttpCredentials( + ['apps/stock/proxy.ts'], + path => files.get(path) ?? null + ); + expect(findings).toEqual([{ path: 'apps/stock/proxy.ts', line: 1 }]); + const serialized = JSON.stringify(findings); + expect(serialized).not.toContain('realuser'); + expect(serialized).not.toContain('realpass'); + + expect( + scanTrackedFilesForHttpCredentials(['scripts/audit-secrets.ts', 'scripts/test/security.test.ts']) + ).toEqual([]); +}); + function isolatedGitEnv(baseEnv: NodeJS.ProcessEnv = process.env): Record { const env: Record = {}; for (const [key, value] of Object.entries(baseEnv)) { From dfb43ef5d03a877ea2d4bc6d522869b8265db8bf Mon Sep 17 00:00:00 2001 From: Studio Date: Fri, 27 Nov 2026 12:10:01 -0500 Subject: [PATCH 2/2] T-11: tests --- scripts/test/security.test.ts | 64 +++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/scripts/test/security.test.ts b/scripts/test/security.test.ts index 26061c44..8e8a99fe 100644 --- a/scripts/test/security.test.ts +++ b/scripts/test/security.test.ts @@ -468,6 +468,52 @@ test('embedded HTTP(S) credential audit reports hardcoded credentials with inter ).toEqual([]); }); +test('embedded HTTP(S) credential audit handles interpolated-host edge cases per line', () => { + const buildUrl = (scheme: string, user: string, pass: string, host: string) => + `${scheme}://${user}:${pass}@${host}`; + + const interpHost = buildUrl('http', 'edgeuser', 'edgepass', '${proxyHost}:80'); + const interpHostNoPort = buildUrl('https', 'edgeuser', 'edgepass', '${proxyHost}/v1'); + const upperScheme = buildUrl('HTTPS', 'edgeuser', 'edgepass', '${proxyHost}'); + const interpFqdnDot = buildUrl('https', 'edgeuser', 'edgepass', '${region}.vendor.io.:8443'); + const interpTestTld = buildUrl('http', 'edgeuser', 'edgepass', '${sub}.proxy.test:80'); + const interpLocalhost = buildUrl('http', 'edgeuser', 'edgepass', 'localhost'); + + const lines = [ + `const reportedFirst = [\`${interpHost}\`, \`http://\${user}:\${pass}@proxy.vendor.io:80\`];`, + `const twoLeaks = [\`${interpHost}\`, \`${interpHostNoPort}\`];`, + 'const partialUser = `http://real${suffix}:realpass@proxy.vendor.io:80`;', + 'const partialPass = `http://realuser:pre${secret}post@${proxyHost}:80`;', + `const upper = \`${upperScheme}\`;`, + `const fqdnDot = \`${interpFqdnDot}\`;`, + `const testTld = \`${interpTestTld}\`;`, + `const local = \`${interpLocalhost}\`;`, + ].join('\r\n'); + + // Line 2 holds two leaks but is reported once; CRLF must not shift line numbers. + expect(findEmbeddedHttpCredentials(lines)).toEqual([1, 2, 5, 6]); +}); + +test('embedded HTTP(S) credential audit self-scan reads both edited sources regardless of cwd', () => { + const sources = new Map([ + ['scripts/audit-secrets.ts', fileURLToPath(new URL('../audit-secrets.ts', import.meta.url))], + ['scripts/test/security.test.ts', fileURLToPath(import.meta.url)], + ]); + const read: string[] = []; + + const findings = scanTrackedFilesForHttpCredentials([...sources.keys()], path => { + const absolute = sources.get(path); + if (!absolute) throw new Error(`unexpected path ${path}`); + const content = readFileSync(absolute); + expect(content.length).toBeGreaterThan(0); + read.push(path); + return content; + }); + + expect(read).toEqual([...sources.keys()]); + expect(findings).toEqual([]); +}); + function isolatedGitEnv(baseEnv: NodeJS.ProcessEnv = process.env): Record { const env: Record = {}; for (const [key, value] of Object.entries(baseEnv)) { @@ -478,12 +524,15 @@ function isolatedGitEnv(baseEnv: NodeJS.ProcessEnv = process.env): Record { + const result = runAuditSecretsCliFixture(process.env, '${proxyHost}:80'); + + expect(result.exitCode).toBe(1); + expect(result.stderr).toContain('leaked.ts:2'); + expect(result.stdout).not.toContain(result.fakeUser); + expect(result.stdout).not.toContain(result.fakePass); + expect(result.stderr).not.toContain(result.fakeUser); + expect(result.stderr).not.toContain(result.fakePass); +}); + test('audit-secrets CLI fixture ignores inherited Git repository and index env vars', () => { const callerDir = mkdtempSync(join(tmpdir(), 'audit-secrets-caller-')); const cleanEnv = isolatedGitEnv();