Skip to content

Commit 649ca03

Browse files
committed
To many false positives for private key scanning
1 parent efd9d4e commit 649ca03

File tree

12 files changed

+68
-15
lines changed

12 files changed

+68
-15
lines changed

src/package.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,10 @@ enum FileExclusionType {
21232123
}
21242124

21252125
export async function scanFilesForSecrets(files: IFile[], fileExclusion: FileExclusionType, options: IPackageOptions): Promise<void> {
2126+
if (options.allowPackageAllSecrets && options.allowPackageEnvFile) {
2127+
return; // No need to scan
2128+
}
2129+
21262130
const onDiskFiles: ILocalFile[] = files.filter(file => !isInMemoryFile(file)) as ILocalFile[];
21272131
const inMemoryFiles: IInMemoryFile[] = files.filter(file => isInMemoryFile(file)) as IInMemoryFile[];
21282132

src/secretLint.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,18 @@ const lintConfig = {
1717
id: "@secretlint/secretlint-rule-preset-recommend",
1818
rules: [
1919
{
20-
"id": "@secretlint/secretlint-rule-basicauth",
21-
"allowMessageIds": ["BasicAuth"]
20+
id: "@secretlint/secretlint-rule-basicauth",
21+
allowMessageIds: ["BasicAuth"]
22+
},
23+
{
24+
id: "@secretlint/secretlint-rule-privatekey",
25+
options: {
26+
allows: [
27+
// Allow all keys which do not start and end with the BEGIN/END PRIVATE KEY and has at least 50 characters in between
28+
// https://github.com/microsoft/vscode-vsce/issues/1147
29+
"/^(?![\\s\\S]*-----BEGIN .*PRIVATE KEY-----[A-Za-z0-9+/=\\r\\n]{50,}-----END .*PRIVATE KEY-----)[\\s\\S]*$/"
30+
]
31+
}
2232
}
2333
]
2434
}, {
File renamed without changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**secret**
2+
!noSecret1.ts
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// https://github.com/microsoft/vscode-vsce/issues/1147
2+
let privateB64 = '-----BEGIN PRIVATE KEY-----\n';
3+
privateB64 += 'ABC\n';
4+
privateB64 += '-----END PRIVATE KEY-----\n';
5+
6+
const description = ` This is some description test
7+
8+
\`\`\`ini
9+
key="-----BEGIN PRIVATE KEY-----\\nXXXX\\nXXXX\\n-----END PRIVATE KEY-----"
10+
\`\`\`
11+
12+
some other text.
13+
`;
14+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**secret**
2+
!noSecret2.ts

src/test/fixtures/secret/package.json renamed to src/test/fixtures/secrets/package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,5 @@
44
"version": "1.0.0",
55
"engines": {
66
"vscode": "*"
7-
},
8-
"files": [
9-
"main.ts",
10-
"package.json",
11-
"LICENSE",
12-
"README.md"
13-
]
7+
}
148
}

src/test/fixtures/secrets/secret1.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const k = `
2+
-----BEGIN OPENSSH PRIVATE KEY-----
3+
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAaAAAABNlY2RzYS
4+
1zaGEyLW5pc3RwMjU2A564CG5pc3RwMjU2AAAAQQR+598gRY+O8LM7Jk80+etTh+Hi4zUW
5+
Pj7jrQoOPbvvkLKhPMHPXaVsXScxbFe87++o9Qn0h9AKtp+Rvf4mHSqwAAAAoKDtkvGg7Z
6+
LxAAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAA123bmlzdHAyNTYAAABBBH7n3yBFj47wszsm
7+
TzT561OH4eLjNRY+PuOtCg49u++QsqE8wc9dpWxdJzFsV7zv76j1CfSH0Aq2n5G9/iYdKr
8+
AAAAAgNbbtcAGWxT7sR5Rbth6D/4MPQd+LO5ljjbjHQlu9KdUAAAAGbm9uYW1lAQI=
9+
-----END OPENSSH PRIVATE KEY-----
10+
`
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**secret**
2+
!secret1.ts

src/test/package.test.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,18 +395,33 @@ describe('collect', function () {
395395
});
396396

397397
it('should not package file which has a private key', async function () {
398-
const cwd = fixture('secret');
399-
await processExitExpected(() => pack({ cwd, packagePath: getVisxOutputPath() }), 'Expected package to throw: file which has a private key should not be packaged');
398+
const cwd = fixture('secrets');
399+
const ignoreFile = path.join(cwd, 'secret1Ignore');
400+
await processExitExpected(() => pack({ cwd, packagePath: getVisxOutputPath(), ignoreFile }), 'Expected package to throw: file which has a private key should not be packaged');
400401
});
401402

402403
it('allow packaging file which has a private key with --allow-package-secrets', async function () {
403-
const cwd = fixture('secret');
404-
await pack({ cwd, allowPackageSecrets: ['privatekey'], packagePath: getVisxOutputPath() });
404+
const cwd = fixture('secrets');
405+
const ignoreFile = path.join(cwd, 'secret1Ignore');
406+
await pack({ cwd, allowPackageSecrets: ['privatekey'], packagePath: getVisxOutputPath(), ignoreFile });
405407
});
406408

407409
it('allow packaging file which has a private key with --allow-package-all-secrets', async function () {
408-
const cwd = fixture('secret');
409-
await pack({ cwd, allowPackageAllSecrets: true, packagePath: getVisxOutputPath() });
410+
const cwd = fixture('secrets');
411+
const ignoreFile = path.join(cwd, 'secret1Ignore');
412+
await pack({ cwd, allowPackageAllSecrets: true, packagePath: getVisxOutputPath(), ignoreFile });
413+
});
414+
415+
it('private key false positive 1', async function () {
416+
const cwd = fixture('secrets');
417+
const ignoreFile = path.join(cwd, 'noSecret1Ignore');
418+
await pack({ cwd, allowPackageAllSecrets: true, packagePath: getVisxOutputPath(), ignoreFile });
419+
});
420+
421+
it('private key false positive 2', async function () {
422+
const cwd = fixture('secrets');
423+
const ignoreFile = path.join(cwd, 'noSecret2Ignore');
424+
await pack({ cwd, allowPackageAllSecrets: true, packagePath: getVisxOutputPath(), ignoreFile });
410425
});
411426
});
412427

0 commit comments

Comments
 (0)