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
This commit is contained in:
Rohit Ghumare
2026-04-12 10:56:35 +01:00
parent 49fcc532d2
commit 9e50c8abe1
8 changed files with 66 additions and 30 deletions
+28 -7
View File
@@ -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
+1 -1
View File
@@ -58,7 +58,7 @@ export class CheckCommand extends Command {
async execute(): Promise<number> {
const searchDirs = getSearchDirs();
const s = spinner();
const s = this.json ? { start: () => {}, stop: () => {}, message: () => {} } : spinner();
if (!this.quiet && !this.json) {
header('Check Updates');
+10 -3
View File
@@ -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');
+1 -1
View File
@@ -70,7 +70,7 @@ export class FindCommand extends Command {
});
async execute(): Promise<number> {
const s = spinner();
const s = this.json ? { start: () => {}, stop: () => {}, message: () => {} } : spinner();
const limit = parseInt(this.limit, 10) || 10;
if (!this.quiet && !this.json) {
+1 -1
View File
@@ -140,7 +140,7 @@ export class InstallCommand extends Command {
async execute(): Promise<number> {
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<ReturnType<typeof this.resolveSource>>["cloneResult"] = null;
try {
+13 -11
View File
@@ -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;
+10 -4
View File
@@ -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');
+2 -2
View File
@@ -28,7 +28,7 @@ export class UpdateCommand extends Command {
});
async execute(): Promise<number> {
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;