Help us shape the future of Go! Take the 2026 Go Developer Survey

sast

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 13 Imported by: 1

Documentation

Overview

Package sast 确定性 SAST 前置扫描(收编自 argus internal/sastscan,v0.10.39, 对标 CodeRabbit 的 Semgrep/Snyk 集成):在工作副本上执行 gitleaks / semgrep, 产出归一为结构化 Finding——全程零 LLM,作为独立信号注入嵌入方的合并/裁决层。

安全纪律(供应链):二进制路径只来自部署方信任源(服务级配置),仓库级配置 不可启用/替换;gitleaks 全程 --redact 且 Secret/Commit 字段绝不进 Finding (密钥原文不进任何下游分发面);子进程环境走白名单(EnvAllow,叠加在 procx 基础集之上),不继承宿主密钥。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FocusPaths

func FocusPaths(paths []string) []string

FocusPaths 聚焦文件清单整形(存在性不做校验——以 diff 清单为准,缺失文件 semgrep 自行忽略;>semgrepMaxPaths 回退 nil = 全仓;含 ".." 的路径剔除防 路径穿越出工作副本)。

func GitleaksArgs

func GitleaksArgs(dir, logOpts string) []string

GitleaksArgs 命令行构造(logOpts 非空走提交范围扫描——--no-git 与 --log-opts 互斥,真机 gitleaks 以 --log-opts 优先)。

func SemgrepSeverity

func SemgrepSeverity(s string) string

SemgrepSeverity semgrep 三档(ERROR/WARNING/其余)→ reportutil 词表。

Types

type Config

type Config struct {
	GitleaksBin   string        // gitleaks 绝对路径
	SemgrepBin    string        // semgrep 绝对路径
	SemgrepConfig string        // semgrep --config 值(路径/registry 名)
	Timeout       time.Duration // 单工具超时(0 = 120s)
	EnvAllow      []string      // 子进程环境白名单(按名透传当前进程变量;nil = 仅 procx 基础集)
}

Config SAST 工具配置(bin 路径来自部署方信任源;全空 = 功能关闭)。

func (Config) Enabled

func (c Config) Enabled() bool

Enabled 任一工具 bin 已配置即启用。

func (Config) TimeoutResolved

func (c Config) TimeoutResolved() time.Duration

TimeoutResolved 生效超时。

type Finding

type Finding struct {
	Tool     string // gitleaks | semgrep
	File     string
	Line     int
	RuleID   string // gitleaks 规则 ID / semgrep check_id
	Severity string
	Comment  string // 人读评语(已含工具名前缀)
}

Finding SAST 单条产出(与嵌入方 finding 契约解耦,嵌入方自行映射)。 Severity 为 reportutil 词表(high/medium/low)。

type Logger

type Logger interface {
	Info(msg string, kv ...any)
	Warn(msg string, kv ...any)
}

Logger 最小日志口(logx.Logger 满足)。

type ToolResult

type ToolResult struct {
	Tool     string
	Findings []Finding
	Notes    string // 截断等非致命告警
	Err      error
}

ToolResult 单工具扫描结果(失败置 Err 不中断其它工具)。

func Scan

func Scan(ctx context.Context, cfg Config, dir, baseRef string, paths []string, log Logger) []ToolResult

Scan 执行全部已配置工具,每工具产出一个 ToolResult。dir 为工作副本根; baseRef 非空时 gitleaks 按 origin/<base>..HEAD 提交范围扫描(工作副本已 deepen 到 merge-base),为空退化为全仓 --no-git 扫描。paths 为本次审查实际 覆盖的变更文件清单(diff 聚焦——全仓扫描在大仓上既慢又淹没信噪比;nil/空 = 全仓)。未配置 config 的 semgrep 不产结果(不算覆盖缺口,只告警)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL