safety
This commit is contained in:
parent
879e9b4228
commit
c3cb36c8d6
51 changed files with 2290 additions and 1467 deletions
32
scripts/audit-secrets.ts
Normal file
32
scripts/audit-secrets.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// Explicit private local-development exceptions, not a general permission to track secrets.
|
||||
const localDevelopmentEnvironmentFiles = new Set(['.env', 'apps/stock/web-app/.env']);
|
||||
|
||||
/** Refuse unexpected tracked environment files without printing contents or values. */
|
||||
export function unexpectedTrackedEnvironmentFiles(paths: readonly string[]): string[] {
|
||||
return paths.filter(path => {
|
||||
if (path.startsWith('apps/wcag-ada/') || localDevelopmentEnvironmentFiles.has(path))
|
||||
return false;
|
||||
const name = path.split('/').at(-1) ?? '';
|
||||
return (
|
||||
(name === '.env' || name.startsWith('.env.')) &&
|
||||
name !== '.env.example' &&
|
||||
!name.endsWith('.example')
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
const result = Bun.spawnSync(['git', 'ls-files', '-z']);
|
||||
if (result.exitCode !== 0) throw new Error('Cannot inspect tracked files for the secret audit');
|
||||
const files = unexpectedTrackedEnvironmentFiles(
|
||||
new TextDecoder().decode(result.stdout).split('\0')
|
||||
);
|
||||
if (files.length) {
|
||||
process.stderr.write(`Unexpected tracked environment files: ${files.join(', ')}\n`);
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
process.stdout.write(
|
||||
'Tracked environment-file audit passed (two local-development exceptions; WCAG excluded).\n'
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue