mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
fix(audit): report audit-rules load errors and block installs whose audit cannot run (#882)
* fix(audit): report audit-rules load errors in global scans The global scan entry points (ScanSkill, ScanSkillWithFollow, ScanSkillFiltered, ScanFile) dropped the error from Rules() and scanned with no pattern rules. One bad regex in the global audit-rules.yaml turned every pattern check off with no warning, so audits reported fewer findings than they should have (#879). Project mode already returned the error. Return the error from the global path as well, and name the failing file in it: parse errors from loadUserRules and compile errors from Rules() and RulesWithProject now carry the path. When a project scan fails to compile, the global file is blamed only if it fails on its own, so a project file that disables a broken global rule still loads. The cached markdown split now takes the rules its caller already loaded instead of loading them again and dropping the error. * fix(install): block installs whose audit cannot run Once global scans return rule-load errors, install treated the error as a warning and installed the skill with no audit at all. update already fails closed on a scan error, and --force there accepts findings, not an install nobody could check. A scan error now blocks skill, agent and tracked-repo installs and removes what was installed. --force does not override it; --skip-audit still bypasses scanning. The error wraps the new install.ErrAuditScanFailed rather than audit.ErrBlocked, so install output and the dashboard do not offer a --force retry that cannot help. upgrade reinstalls the built-in skill with --force, which deleted the old copy before the audit ran. A typo in audit-rules.yaml would have left users without the skill, so upgrade now stages the download through the update path and keeps the installed copy when the audit fails. update --all counted the new error as a silent skip. It is now listed under "Blocked by security audit" with its reason and makes the run exit non-zero. The install warning summary that counted "audit scan error" warnings is removed, since nothing emits them any more. Fixes #879
This commit is contained in:
@@ -663,7 +663,7 @@ func printInstallHelp() {
|
||||
{"--name <name>", "Override installed name when exactly one skill is installed"},
|
||||
{"--kind <kind>", "Restrict discovery/install to skill or agent"},
|
||||
{"--into <dir>", "Install into subdirectory (e.g. \"frontend\" or \"frontend/react\")"},
|
||||
{"-f, --force", "Overwrite existing skill; also continue if audit would block"},
|
||||
{"-f, --force", "Overwrite existing skill; also continue if audit findings would block"},
|
||||
{"-u, --update", "Update existing (git pull if possible, else reinstall)"},
|
||||
{"-b, --branch <ref>", "Git branch, tag, or commit SHA to install from (default: remote default)"},
|
||||
{"-t, --track", "Keep a Git checkout for updates; no selection prompt.\nCannot combine with --all, --yes, --skill, or --agent"},
|
||||
|
||||
@@ -50,7 +50,6 @@ type batchInstallWarningDigest struct {
|
||||
skillsWithFindings int
|
||||
belowThresholdSkillCount int
|
||||
aboveThresholdSkillCount int
|
||||
scanErrorSkillCount int
|
||||
skippedAuditSkillCount int
|
||||
highCriticalBySkill map[string]int
|
||||
nonAuditLines []string
|
||||
@@ -128,7 +127,7 @@ func digestInstallWarnings(warnings []string) installWarningDigest {
|
||||
switch {
|
||||
case strings.HasPrefix(warning, "audit findings "):
|
||||
digest.statusLines = append(digest.statusLines, firstWarningLine(warning))
|
||||
case strings.HasPrefix(warning, "audit scan error"), strings.HasPrefix(warning, "audit skipped"), strings.HasPrefix(warning, "audit "):
|
||||
case strings.HasPrefix(warning, "audit skipped"), strings.HasPrefix(warning, "audit "):
|
||||
digest.otherAuditLines = append(digest.otherAuditLines, firstWarningLine(warning))
|
||||
default:
|
||||
digest.nonAuditLines = append(digest.nonAuditLines, warning)
|
||||
@@ -516,8 +515,6 @@ func summarizeBatchInstallWarnings(results []skillInstallResult) batchInstallWar
|
||||
|
||||
for _, line := range digest.otherAuditLines {
|
||||
switch {
|
||||
case strings.HasPrefix(line, "audit scan error"):
|
||||
summary.scanErrorSkillCount++
|
||||
case strings.HasPrefix(line, "audit skipped"):
|
||||
summary.skippedAuditSkillCount++
|
||||
default:
|
||||
@@ -607,9 +604,6 @@ func renderBatchInstallWarningsCompact(results []skillInstallResult, totalWarnin
|
||||
if summary.aboveThresholdSkillCount > 0 {
|
||||
ui.Warning("%s had findings at/above threshold and continued due to --force", plural(summary.aboveThresholdSkillCount, "skill"))
|
||||
}
|
||||
if summary.scanErrorSkillCount > 0 {
|
||||
ui.Warning("%s had audit scan errors", plural(summary.scanErrorSkillCount, "skill"))
|
||||
}
|
||||
if summary.skippedAuditSkillCount > 0 {
|
||||
ui.Warning("%s skipped audit (--skip-audit)", plural(summary.skippedAuditSkillCount, "skill"))
|
||||
}
|
||||
@@ -661,9 +655,6 @@ func renderUltraCompactAuditSummary(results []skillInstallResult, _ int) {
|
||||
if summary.aboveThresholdSkillCount > 0 {
|
||||
statusParts = append(statusParts, fmt.Sprintf("%d above threshold (--force)", summary.aboveThresholdSkillCount))
|
||||
}
|
||||
if summary.scanErrorSkillCount > 0 {
|
||||
statusParts = append(statusParts, fmt.Sprintf("%d scan errors", summary.scanErrorSkillCount))
|
||||
}
|
||||
if len(statusParts) > 0 {
|
||||
ui.Warning("%s", strings.Join(statusParts, ", "))
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestDigestInstallWarnings_ClassifiesAuditAndNonAudit(t *testing.T) {
|
||||
"audit HIGH: Python shell execution detected (SKILL.md:10)\n \"subprocess.run(\"",
|
||||
"audit LOW: External URL in markdown link (README.md:4)",
|
||||
"audit findings detected, but none at/above block threshold (CRITICAL)",
|
||||
"audit scan error: timeout",
|
||||
"audit skipped (--skip-audit)",
|
||||
"some non-audit warning",
|
||||
}
|
||||
|
||||
@@ -79,7 +79,6 @@ func TestSummarizeBatchInstallWarnings_AggregatesAcrossSkills(t *testing.T) {
|
||||
warnings: []string{
|
||||
"audit HIGH: finding-3 (b.md:1)",
|
||||
"audit HIGH: finding-4 (b.md:2)",
|
||||
"audit scan error: timeout",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -108,9 +107,6 @@ func TestSummarizeBatchInstallWarnings_AggregatesAcrossSkills(t *testing.T) {
|
||||
if summary.belowThresholdSkillCount != 1 {
|
||||
t.Fatalf("expected belowThresholdSkillCount=1, got %d", summary.belowThresholdSkillCount)
|
||||
}
|
||||
if summary.scanErrorSkillCount != 1 {
|
||||
t.Fatalf("expected scanErrorSkillCount=1, got %d", summary.scanErrorSkillCount)
|
||||
}
|
||||
if summary.skippedAuditSkillCount != 1 {
|
||||
t.Fatalf("expected skippedAuditSkillCount=1, got %d", summary.skippedAuditSkillCount)
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ func displayUpdateBlockedSection(blocked []batchBlockedEntry) {
|
||||
label := blockedSkillLabel(b.name, digest.threshold)
|
||||
ui.StepFail(label, compactBlockedUpdateMessage(b.errMsg))
|
||||
}
|
||||
ui.Note("Use --force or --skip-audit to bypass")
|
||||
ui.Note("Use --force to override findings or --skip-audit to bypass scanning")
|
||||
}
|
||||
|
||||
// compactBlockedUpdateMessage extracts a compact message from a blocked update error.
|
||||
@@ -199,6 +199,9 @@ func compactBlockedUpdateMessage(errMsg string) string {
|
||||
parts = append(parts, fmt.Sprintf("(%s, %d %s)", digest.threshold, digest.findingCount, suffix))
|
||||
} else if digest.threshold != "" {
|
||||
parts = append(parts, "("+digest.threshold+")")
|
||||
} else {
|
||||
// No findings: the audit itself failed, so show why.
|
||||
return firstWarningLine(errMsg)
|
||||
}
|
||||
return strings.Join(parts, " ")
|
||||
}
|
||||
|
||||
@@ -436,9 +436,10 @@ func printUpdateRow(mark, name, detail string, took time.Duration) {
|
||||
}
|
||||
|
||||
// isSecurityError returns true if the error originated from the audit gate.
|
||||
// All security-related errors wrap audit.ErrBlocked as a sentinel.
|
||||
// Security-related errors wrap audit.ErrBlocked, or install.ErrAuditScanFailed
|
||||
// when a reinstall's audit could not run.
|
||||
func isSecurityError(err error) bool {
|
||||
return errors.Is(err, audit.ErrBlocked)
|
||||
return errors.Is(err, audit.ErrBlocked) || errors.Is(err, install.ErrAuditScanFailed)
|
||||
}
|
||||
|
||||
func truncateString(s string, maxLen int) string { return truncateStr(s, maxLen) }
|
||||
|
||||
@@ -81,6 +81,9 @@ func TestIsSecurityError(t *testing.T) {
|
||||
// Wrapped sentinel
|
||||
{fmt.Errorf("outer: %w", fmt.Errorf("inner: %w", audit.ErrBlocked)), true},
|
||||
|
||||
// An install audit that could not run blocks the update too
|
||||
{fmt.Errorf("outer: %w", install.ErrAuditScanFailed), true},
|
||||
|
||||
// Non-sentinel errors with similar text should NOT match
|
||||
{fmt.Errorf("security audit something"), false},
|
||||
{fmt.Errorf("was rolled back successfully"), false},
|
||||
@@ -269,3 +272,10 @@ func TestIsGroupDir_UnprefixedCheckoutIsGroup(t *testing.T) {
|
||||
t.Error("a _-prefixed checkout is a tracked repo, not a group")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompactBlockedUpdateMessage_ShowsScanFailure(t *testing.T) {
|
||||
msg := "audit scan failed: load rules: bad regex\n\nFix the cause or use --skip-audit to bypass scanning"
|
||||
if got := compactBlockedUpdateMessage(msg); got != "audit scan failed: load rules: bad regex" {
|
||||
t.Fatalf("compactBlockedUpdateMessage() = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,8 +364,10 @@ func doSkillDownload(skillshareSkillDir, sourceDir, fromVersion string) error {
|
||||
}
|
||||
source.Name = "skillshare"
|
||||
|
||||
// Update stages the download, so a failed audit keeps the installed skill.
|
||||
_, err = install.Install(source, skillshareSkillDir, install.InstallOptions{
|
||||
Force: true,
|
||||
Update: true,
|
||||
DryRun: false,
|
||||
})
|
||||
spinner.Stop()
|
||||
|
||||
Reference in New Issue
Block a user