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 @@ -79,7 +79,7 @@ function inspectWorkflow(file, text) {
for (let i = 0; i < lines.length; i++) {
const indentation = lines[i].match(/^\s*/)[0].length;
const run = lines[i].match(/^(\s*)(?:-\s*)?run\s*:\s*(.*)$/i);
if (run) runBlockIndent = !run[2] || /^[|>][+-]?$/.test(run[2].trim()) ? run[1].length : null;
if (run) runBlockIndent = !run[2] || /^[|>](?:(?:[1-9][+-]?)|(?:[+-][1-9]?))?$/.test(run[2].trim()) ? run[1].length : null;
else if (runBlockIndent !== null && lines[i].trim() && indentation <= runBlockIndent) runBlockIndent = null;
const isRunCommand = Boolean(run) || runBlockIndent !== null;
if (isRunCommand && /\$\{\{\s*github\.event\.(?:pull_request\.(?:title|body)|issue\.title|comment\.body)/i.test(lines[i])) {
Expand Down
10 changes: 10 additions & 0 deletions test/scan.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ test('workflow issues are grouped and fail at the configured threshold', t => {
assert.ok(f.report.findings.some(x => x.category === 'Workflow permissions'));
});

test('workflow script injection is detected with YAML block indentation indicators', t => {
for (const marker of ['|2-', '>+2']) {
const workflow = `name: test\non: pull_request\npermissions:\n contents: read\njobs:\n build:\n runs-on: ubuntu-latest\n steps:\n - run: ${marker}\n echo \${{ github.event.pull_request.title }}\n`;
const f = fixture({ '.github/workflows/ci.yml': workflow });
t.after(() => rmSync(f.dir, { recursive: true, force: true }));
assert.notEqual(f.result.status, 0, `${marker} should fail at the default high threshold`);
assert.ok(f.report.findings.some(x => x.category === 'Workflow script injection'), `${marker} must inspect the shell block`);
}
});

test('documented placeholders do not trigger credential assignment heuristic', t => {
const f = fixture({ '.env.example': 'API_KEY=YOUR_API_KEY_HERE\n', 'app.js': 'const password = "change_me_now";\n' }); t.after(() => rmSync(f.dir, { recursive: true, force: true }));
assert.equal(f.report.findings.filter(x => x.category === 'Possible secret' || x.category === 'Sensitive file').length, 0);
Expand Down
Loading