-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
38 lines (35 loc) · 932 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env node
import { checkIfPrivKey } from './utils/crypto';
import {
getAllFiles,
getIgnoreListFromGitignore,
getTokensFromFile,
Token,
} from './utils/files';
import chalk from 'chalk';
const run = () => {
const ignoreList = getIgnoreListFromGitignore();
const files = getAllFiles('./', [...ignoreList]);
const tokens: Token[] = [];
files.forEach((file) => {
tokens.push(...getTokensFromFile(file));
});
const vulnFiles: string[] = [];
tokens.forEach((token) => {
if (checkIfPrivKey(token.content)) {
vulnFiles.push(token.fileName);
}
});
if (vulnFiles.length > 0) {
console.log(
chalk.red(
`🚨 Found ${vulnFiles.length} instance(s) of private keys. Aborting commit.`
)
);
vulnFiles.forEach((file) => console.log(chalk(`=> ${file}`)));
process.exit(1);
} else {
console.log(chalk.green('✅ No private keys found'));
}
};
run();