Files
skillshare/internal/audit/analyzers.go
T
Willie ebf2aaf822 feat(audit): add metadata analyzer for supply-chain trust verification
Add metadataAnalyzer (skill scope) that cross-references SKILL.md
metadata against the actual git source from .skillshare-meta.json:

- publisher-mismatch (HIGH): description claims an org but repo owner
  differs (e.g. "from Acme Corp" but sourced from evil-fork)
- authority-language (MEDIUM): uses "official"/"verified" language but
  source is not a well-known organization

Both rules are disable-able via audit-rules.yaml. The analyzer reads
meta from disk (zero API signature changes) and avoids import cycles
by defining its own minimal metaJSON struct.
2026-03-05 02:13:21 +08:00

55 lines
1.9 KiB
Go

package audit
// AnalyzerScope defines when an analyzer runs in the pipeline.
type AnalyzerScope string
const (
// ScopeFile analyzers run once per scannable file during the Walk phase.
ScopeFile AnalyzerScope = "file"
// ScopeSkill analyzers run once per skill after all files are walked.
ScopeSkill AnalyzerScope = "skill"
// ScopeBundle analyzers run once after all skills are scanned.
ScopeBundle AnalyzerScope = "bundle"
)
// Analyzer is the pluggable analysis unit for the audit pipeline.
// Each analyzer encapsulates one detection strategy (regex, dataflow, etc.)
// and declares its scope so the runner knows when to invoke it.
type Analyzer interface {
// ID returns the stable identifier (matches AnalyzerStatic, etc.).
ID() string
// Scope returns when this analyzer runs: file, skill, or bundle.
Scope() AnalyzerScope
// Analyze runs the analysis and returns findings.
// The context carries all inputs relevant to the declared scope.
Analyze(ctx *AnalyzeContext) ([]Finding, error)
}
// AnalyzeContext carries all data needed by analyzers at different scopes.
// Only fields relevant to the analyzer's scope will be populated.
type AnalyzeContext struct {
// --- File-scope fields (populated per-file during Walk) ---
FileName string // relative path within the skill
Content []byte
IsMarkdown bool
IsShell bool
// --- Skill-scope fields (populated after Walk completes) ---
SkillPath string
SourceURL string // git clone URL from .skillshare-meta.json (empty for local)
MDFiles []mdFileInfo
FileCache map[string][]byte
TierProfile TierProfile
MDLinks map[string][]markdownLink // pre-extracted links per md relPath
AllFiles map[string]bool // all walked file relPaths (for integrity)
// --- Bundle-scope fields (populated after all skills scanned) ---
Results []*Result
// --- Shared across all scopes ---
Rules []rule
MDContentRules []rule
MDLinkRules []rule
DisabledIDs map[string]bool
}