From 684a48098d407e135881d06ee98738f2ac76bfe7 Mon Sep 17 00:00:00 2001 From: GhosTnever <286396892+GhosTnever-lkm@users.noreply.github.com> Date: Tue, 20 Oct 2026 03:14:03 +0400 Subject: [PATCH] Fix workflow block scalar indicator parsing --- src/scan.mjs | 2 +- test/scan.test.mjs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/scan.mjs b/src/scan.mjs index 44adeb8..1b3e58c 100644 --- a/src/scan.mjs +++ b/src/scan.mjs @@ -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])) { diff --git a/test/scan.test.mjs b/test/scan.test.mjs index 82bb5ac..545a98a 100644 --- a/test/scan.test.mjs +++ b/test/scan.test.mjs @@ -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);