Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scan.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function secretPattern(line) {
];
for (const [name, regex] of patterns) if (regex.test(line)) return name;

const assignment = line.match(/(?:password|passwd|secret|api[_-]?key|access[_-]?token|client[_-]?secret)\s*[:=]\s*["']?([^\s"',;]{8,})/i);
const assignment = line.match(/(?:password|passwd|secret|aws[_-]?secret[_-]?access[_-]?key|api[_-]?key|access[_-]?token|client[_-]?secret)\s*[:=]\s*["']?([^\s"',;]{8,})/i);
if (assignment && !isPlaceholder(assignment[1]) && !/^\$\{\{|^\$[A-Z_][A-Z0-9_]*$/i.test(assignment[1])) {
return 'Credential-like assignment';
}
Expand Down
9 changes: 9 additions & 0 deletions test/scan.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ test('credential detection reports line without copying secret value into logs',
assert.doesNotMatch(f.result.stdout + f.result.stderr, /123456789012345678901234567890123456/);
});

test('AWS secret access key assignments are detected without exposing the value', t => {
const fake = 'A'.repeat(40);
const variable = ['AWS', 'SECRET', 'ACCESS', 'KEY'].join('_');
const f = fixture({ '.env': `${variable}=${fake}\n` }); t.after(() => rmSync(f.dir, { recursive: true, force: true }));
assert.notEqual(f.result.status, 0);
assert.ok(f.report.findings.some(x => x.category === 'Possible secret' && x.message.includes('Credential-like assignment')));
assert.doesNotMatch(f.result.stdout + f.result.stderr + JSON.stringify(f.report), new RegExp(fake));
});

test('workflow issues are grouped and fail at the configured threshold', t => {
const workflow = 'name: test\non: pull_request\njobs:\n scan:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v4\n - run: |\n echo ${{ github.event.pull_request.title }}\n';
const f = fixture({ '.github/workflows/ci.yml': workflow }, { failOn: 'medium' }); t.after(() => rmSync(f.dir, { recursive: true, force: true }));
Expand Down
Loading