diff --git a/src/scan.mjs b/src/scan.mjs index 1b3e58c..d4bcd8f 100644 --- a/src/scan.mjs +++ b/src/scan.mjs @@ -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'; } diff --git a/test/scan.test.mjs b/test/scan.test.mjs index 545a98a..36f5d25 100644 --- a/test/scan.test.mjs +++ b/test/scan.test.mjs @@ -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 }));