From 9e50c8abe1efeefb978db0c71a5753d4a1aae435 Mon Sep 17 00:00:00 2001 From: Rohit Ghumare <48523873+rohitg00@users.noreply.github.com> Date: Sun, 12 Apr 2026 10:56:35 +0100 Subject: [PATCH] fix: prevent shell injection in action, suppress stdout in --json mode - action.yml: pass inputs via env vars, whitelist allowed commands - All --json commands: use no-op spinner to prevent stdout pollution - remove: run AGENTS.md update before JSON output (was skipped) - eval: gate spinner on json format, wrap in try/catch for cleanup - scan: wrap spinner in try/catch for cleanup on failure --- .github/actions/skillkit/action.yml | 35 ++++++++++++++++++++++------ packages/cli/src/commands/check.ts | 2 +- packages/cli/src/commands/eval.ts | 13 ++++++++--- packages/cli/src/commands/find.ts | 2 +- packages/cli/src/commands/install.ts | 2 +- packages/cli/src/commands/remove.ts | 24 ++++++++++--------- packages/cli/src/commands/scan.ts | 14 +++++++---- packages/cli/src/commands/update.ts | 4 ++-- 8 files changed, 66 insertions(+), 30 deletions(-) diff --git a/.github/actions/skillkit/action.yml b/.github/actions/skillkit/action.yml index 8b8fc95f..284de521 100644 --- a/.github/actions/skillkit/action.yml +++ b/.github/actions/skillkit/action.yml @@ -34,11 +34,32 @@ runs: - name: Run SkillKit shell: bash + env: + SK_COMMAND: ${{ inputs.command }} + SK_SOURCE: ${{ inputs.source }} + SK_AGENT: ${{ inputs.agent }} + SK_ARGS: ${{ inputs.args }} run: | - if [ "${{ inputs.command }}" = "install" ] && [ -n "${{ inputs.source }}" ]; then - skillkit install "${{ inputs.source }}" --agent "${{ inputs.agent }}" --yes --json ${{ inputs.args }} - elif [ "${{ inputs.command }}" = "scan" ] && [ -n "${{ inputs.source }}" ]; then - skillkit scan "${{ inputs.source }}" --json ${{ inputs.args }} - else - skillkit ${{ inputs.command }} ${{ inputs.args }} - fi + case "${SK_COMMAND}" in + install) + if [ -n "${SK_SOURCE}" ]; then + skillkit install "${SK_SOURCE}" --agent "${SK_AGENT}" --yes --json ${SK_ARGS} + else + echo "Error: source is required for install" >&2; exit 1 + fi + ;; + scan) + if [ -n "${SK_SOURCE}" ]; then + skillkit scan "${SK_SOURCE}" --json ${SK_ARGS} + else + echo "Error: source is required for scan" >&2; exit 1 + fi + ;; + check|sync|list|update) + skillkit "${SK_COMMAND}" ${SK_ARGS} + ;; + *) + echo "Error: unsupported command '${SK_COMMAND}'. Use: install, scan, check, sync, list, update" >&2 + exit 1 + ;; + esac diff --git a/packages/cli/src/commands/check.ts b/packages/cli/src/commands/check.ts index 35977d71..814b8827 100644 --- a/packages/cli/src/commands/check.ts +++ b/packages/cli/src/commands/check.ts @@ -58,7 +58,7 @@ export class CheckCommand extends Command { async execute(): Promise { const searchDirs = getSearchDirs(); - const s = spinner(); + const s = this.json ? { start: () => {}, stop: () => {}, message: () => {} } : spinner(); if (!this.quiet && !this.json) { header('Check Updates'); diff --git a/packages/cli/src/commands/eval.ts b/packages/cli/src/commands/eval.ts index 4e74c0e2..4a002aac 100644 --- a/packages/cli/src/commands/eval.ts +++ b/packages/cli/src/commands/eval.ts @@ -133,10 +133,17 @@ export class EvalCommand extends Command { engine.registerEvaluator(new DynamicBenchmarkEvaluator()); engine.registerEvaluator(new CommunitySignalsEvaluator()); - const s = spinner(); + const isJson = this.format === 'json'; + const s = isJson ? { start: () => {}, stop: () => {} } : spinner(); s.start('Evaluating skill...'); - const result = await engine.evaluate(targetPath, options); - s.stop(`Evaluation complete (score: ${result.overallScore})`); + let result; + try { + result = await engine.evaluate(targetPath, options); + s.stop(`Evaluation complete (score: ${result.overallScore})`); + } catch (err) { + s.stop('Evaluation failed'); + throw err; + } this.context.stdout.write(formatEvalResult(result, this.format) + '\n'); diff --git a/packages/cli/src/commands/find.ts b/packages/cli/src/commands/find.ts index 9f9aa663..8cb99f1a 100644 --- a/packages/cli/src/commands/find.ts +++ b/packages/cli/src/commands/find.ts @@ -70,7 +70,7 @@ export class FindCommand extends Command { }); async execute(): Promise { - const s = spinner(); + const s = this.json ? { start: () => {}, stop: () => {}, message: () => {} } : spinner(); const limit = parseInt(this.limit, 10) || 10; if (!this.quiet && !this.json) { diff --git a/packages/cli/src/commands/install.ts b/packages/cli/src/commands/install.ts index 7092261a..9e53c679 100644 --- a/packages/cli/src/commands/install.ts +++ b/packages/cli/src/commands/install.ts @@ -140,7 +140,7 @@ export class InstallCommand extends Command { async execute(): Promise { const isInteractive = process.stdin.isTTY && !this.skills && !this.all && !this.yes && !this.json; - const s = spinner(); + const s = this.json ? { start: () => {}, stop: () => {}, message: () => {} } : spinner(); let cloneResult: Awaited>["cloneResult"] = null; try { diff --git a/packages/cli/src/commands/remove.ts b/packages/cli/src/commands/remove.ts index e84590ea..27cf849c 100644 --- a/packages/cli/src/commands/remove.ts +++ b/packages/cli/src/commands/remove.ts @@ -108,16 +108,6 @@ export class RemoveCommand extends Command { } } - if (this.json) { - console.log(JSON.stringify({ - success: failed === 0, - removed: removedNames, - failed: failedNames, - total: removed + failed, - })); - return failed > 0 ? 1 : 0; - } - if (removed > 0) { try { const agentsMdPath = join(process.cwd(), 'AGENTS.md'); @@ -135,7 +125,19 @@ export class RemoveCommand extends Command { warn('Warning: Failed to update AGENTS.md'); console.error(colors.muted(err instanceof Error ? err.message : String(err))); } - console.log(colors.muted('\nRun `skillkit sync` to update your agent config')); + if (!this.json) { + console.log(colors.muted('\nRun `skillkit sync` to update your agent config')); + } + } + + if (this.json) { + console.log(JSON.stringify({ + success: failed === 0, + removed: removedNames, + failed: failedNames, + total: removed + failed, + })); + return failed > 0 ? 1 : 0; } return failed > 0 ? 1 : 0; diff --git a/packages/cli/src/commands/scan.ts b/packages/cli/src/commands/scan.ts index 363b811c..755818fe 100644 --- a/packages/cli/src/commands/scan.ts +++ b/packages/cli/src/commands/scan.ts @@ -81,10 +81,16 @@ export class ScanCommand extends Command { skipRules, }); - const s = spinner(); - if (!this.json) s.start('Scanning for vulnerabilities...'); - const result = await scanner.scan(targetPath); - if (!this.json) s.stop(`Scan complete (${result.findings.length} finding(s))`); + const s = this.json ? { start: () => {}, stop: () => {} } : spinner(); + s.start('Scanning for vulnerabilities...'); + let result; + try { + result = await scanner.scan(targetPath); + s.stop(`Scan complete (${result.findings.length} finding(s))`); + } catch (err) { + s.stop('Scan failed'); + throw err; + } if (this.json) { this.context.stdout.write(formatResult(result, 'json') + '\n'); diff --git a/packages/cli/src/commands/update.ts b/packages/cli/src/commands/update.ts index 7271641a..1de3b1fa 100644 --- a/packages/cli/src/commands/update.ts +++ b/packages/cli/src/commands/update.ts @@ -28,7 +28,7 @@ export class UpdateCommand extends Command { }); async execute(): Promise { - const s = spinner(); + const s = this.json ? { start: () => {}, stop: () => {}, message: () => {} } : spinner(); const searchDirs = getSearchDirs(); let skillsToUpdate; @@ -51,7 +51,7 @@ export class UpdateCommand extends Command { return 0; } - step(`Updating ${skillsToUpdate.length} skill(s)...`); + if (!this.json) step(`Updating ${skillsToUpdate.length} skill(s)...`); let updated = 0; let skipped = 0;