T-3: M0.4 Purge hardcoded proxy credential + fix IB collection typo

This commit is contained in:
Studio 2026-11-27 10:51:13 -05:00
parent 39f6f1fdfe
commit 36489a1e91
9 changed files with 415 additions and 20 deletions

View file

@ -11,7 +11,11 @@ import { createWebSocketRoute } from '../../apps/stock/web-api/src/routes/websoc
import { createHttpSecurity, getVerifiedHttpPrincipal, type HttpSecurityOptions } from '../../libs/core/di/src/http/security';
import { redactLogValue } from '../../libs/core/logger/src/redact';
import { parseReferenceDataResetRequest } from '../../libs/core/types/src/reference-data';
import { unexpectedTrackedEnvironmentFiles } from '../audit-secrets';
import {
findEmbeddedHttpCredentials,
scanTrackedFilesForHttpCredentials,
unexpectedTrackedEnvironmentFiles,
} from '../audit-secrets';
import { checks } from '../check';
const options: HttpSecurityOptions = {
@ -357,3 +361,59 @@ test('native tests and credential-file audit remain mandatory repository gates',
expect(compose).not.toMatch(/^\s*-\s*["']?(?:0\.0\.0\.0:)?\d+:\d+/m);
}
});
test('embedded HTTP(S) credential audit catches real credentials with line numbers and ignores placeholders or binaries', () => {
const buildUrl = (scheme: string, user: string, pass: string, host: string) =>
`${scheme}://${user}:${pass}@${host}`;
const httpCred = buildUrl('http', 'proxy-user', 's3cr3t-pass', 'proxy.vendor.io:8080');
const httpsCred = buildUrl('https', 'api-user', 'tok3n-val', 'gateway.vendor.io/v1');
const sample = [
'const safe = "https://public.vendor.io/api";',
`const leakedHttp = "${httpCred}";`,
'const rfc2606 = "https://user:pass@example.test/api";',
'const exampleCom = "http://user:pass@example.com:80";',
'const exampleSub = "https://user:pass@sub.example.org/path";',
'const invalidTld = "http://user:pass@proxy.invalid:80";',
'const dotExample = "http://user:pass@service.example:80";',
'const loopback = "http://user:pass@127.0.0.1:8080";',
'const loopbackV6 = "http://user:pass@[::1]:8080";',
'const local = "http://user:pass@localhost:3000";',
'const docHost = "http://user:pass@host:80";',
'const template = `http://${user}:${pass}@proxy.vendor.io:80`;',
'const angle = "http://<user>:<pass>@proxy.vendor.io:80";',
'const angleHost = "http://user:pass@<host>:80";',
'const mongo = "mongodb://admin:secret@prod-db.internal:27017/stock";',
`const leakedHttps = '${httpsCred}';`,
].join('\n');
expect(findEmbeddedHttpCredentials(sample)).toEqual([2, 16]);
const files = new Map<string, Buffer>([
['apps/stock/data-ingestion/src/clean.ts', Buffer.from('export const ok = true;\n')],
['apps/stock/data-ingestion/src/leaked.ts', Buffer.from(`line1\nconst p = "${httpCred}";\n`)],
['apps/wcag-ada/src/ignored.ts', Buffer.from(`const p = "${httpCred}";\n`)],
['.env', Buffer.from(`IB_PROXY_URL=${httpCred}\n`)],
['apps/stock/web-app/.env', Buffer.from(`PROXY=${httpsCred}\n`)],
['assets/binary.dat', Buffer.concat([Buffer.from([0x00, 0x01]), Buffer.from(httpCred)])],
]);
const findings = scanTrackedFilesForHttpCredentials(
[
'apps/stock/data-ingestion/src/clean.ts',
'apps/stock/data-ingestion/src/leaked.ts',
'apps/wcag-ada/src/ignored.ts',
'.env',
'apps/stock/web-app/.env',
'assets/binary.dat',
'missing/file.ts',
],
path => files.get(path) ?? null
);
expect(findings).toEqual([{ path: 'apps/stock/data-ingestion/src/leaked.ts', line: 2 }]);
const serialized = JSON.stringify(findings);
expect(serialized).not.toContain('s3cr3t-pass');
expect(serialized).not.toContain('proxy-user');
});