syntaxflow_scan

package
v1.4.4-alpha1202-diff-... Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Exports = map[string]any{
	"StartScan":     StartScan,
	"ResumeScan":    ResumeScan,
	"GetScanStatus": GetScanStatus,

	"withProcessCallback": WithProcessCallback,
}
View Source
var WithErrorCallback = ssaconfig.SetOption(errorCallbackKey, func(c *Config, callback errorCallback) {
	c.errorCallback = callback
})
View Source
var WithPauseFunc = ssaconfig.SetOption(pauseFuncKey, func(c *Config, pause func() bool) {
	c.pauseCheck = pause
})
View Source
var WithProcessCallback = ssaconfig.SetOption(processCallbackKey, func(c *Config, callback ProcessCallback) {
	c.ProcessCallback = callback
})
View Source
var WithProcessRuleDetail = ssaconfig.SetOption("syntaxflow-scan/processRuleDetail", func(c *Config, withDetail bool) {
	c.ProcessWithRule = withDetail
})
View Source
var WithReporter = ssaconfig.SetOption(reporterKey, func(c *Config, reporter sfreport.IReport) {
	c.Reporter = reporter
})
View Source
var WithRulePerformanceLog = ssaconfig.SetOption("syntaxflow-scan/enableRulePerformanceLog", func(c *Config, enable bool) {
	c.EnableRulePerformanceLog = enable
})
View Source
var WithScanResultCallback = ssaconfig.SetOption(resultCallbackKey, func(c *Config, callback ScanResultCallback) {
	c.resultCallback = callback
})

Functions

func GetScanStatus

func GetScanStatus(ctx context.Context, taskId string, callback ProcessCallback) error

GetScanStatus 查询扫描任务的当前状态

参数:

  • ctx: 上下文,用于控制查询的生命周期
  • taskId: 要查询的任务ID
  • callback: 回调函数,用于处理状态查询结果

返回值:

  • error: 如果查询失败则返回错误信息

Example: ``` // 查询扫描任务状态 taskId := "running-task-67890"

err := syntaxflowscan.GetScanStatus(context.New(), taskId, func(result) {
    println("任务状态查询:")
    println("  任务ID:", result.TaskID)
    println("  当前状态:", result.Status)
    if result.ExecResult {
        println("  执行信息:", result.ExecResult.Message)
    }
    return nil
})

die(err) ```

func LoadSyntaxflowTaskFromDB

func LoadSyntaxflowTaskFromDB(ctx context.Context, runningID string, config *Config) (*scanManager, error)

func RemoveSyntaxFlowTaskByID

func RemoveSyntaxFlowTaskByID(id string)

func ResumeScan

func ResumeScan(ctx context.Context, taskId string, opts ...ssaconfig.Option) error

ResumeScan 恢复之前暂停的扫描任务

参数:

  • ctx: 上下文,用于控制扫描任务的生命周期
  • taskId: 要恢复的任务ID
  • callback: 回调函数,用于处理扫描结果

返回值:

  • error: 如果恢复失败则返回错误信息

Example: ``` // 恢复之前暂停的扫描任务 taskId := "previous-task-12345"

err := syntaxflowscan.ResumeScan(context.New(), taskId, func(result) {
    println("恢复扫描 - 任务ID:", result.TaskID)
    println("当前状态:", result.Status)
    if result.Status == "done" {
        println("扫描已完成!")
    }
    return nil
})

die(err) ```

func Scan

func Scan(ctx context.Context, option ...ssaconfig.Option) error

func StartScan

func StartScan(ctx context.Context, opts ...ssaconfig.Option) error

StartScan 启动新的SyntaxFlow扫描任务,使用options模式配置扫描参数

参数:

  • ctx: 上下文,用于控制扫描任务的生命周期
  • callback: 回调函数,用于处理扫描结果
  • opts: 可变数量的选项函数,用于配置扫描参数

返回值:

  • error: 如果启动失败则返回错误信息

Example: ``` // 基础扫描示例

err := syntaxflowscan.StartScan(context.New(), func(result) {
    println("任务ID:", result.TaskID)
    println("状态:", result.Status)
    if result.Risks && len(result.Risks) > 0 {
        for _, risk := range result.Risks {
            println("发现风险:", risk.Title)
        }
    }
    return nil
},

syntaxflowscan.withProgramNames("my-java-project"),
syntaxflowscan.withRuleNames("sql-injection", "xss"),
syntaxflowscan.withSeverity("high", "critical"),
syntaxflowscan.withConcurrency(10),

) die(err)

// 多程序扫描示例

err := syntaxflowscan.StartScan(context.New(), func(result) {
    yakit.Info("扫描进度: %s", result.Status)
    return nil
},

syntaxflowscan.withProgramNames("frontend", "backend", "api"),
syntaxflowscan.withLanguages("javascript", "java", "go"),
syntaxflowscan.withKeyword("security"),
syntaxflowscan.withMemory(true),

) ```

Types

type Config

type Config struct {
	*ssaconfig.Config
	*ScanTaskCallback `json:"-"`
}

func NewConfig

func NewConfig(opts ...ssaconfig.Option) (*Config, error)

type ProcessCallback

type ProcessCallback func(taskID, status string, progress float64, info *RuleProcessInfoList)

type RuleProcessCallback

type RuleProcessCallback func(progress float64, info *RuleProcessInfoList)

type RuleProcessInfo

type RuleProcessInfo struct {
	// rule running identity
	RuleName    string `json:"rule_name"`
	ProgramName string `json:"program_name"`

	// time info `json:"rule_name"`
	StartTime  int64 `json:"start_time"`
	UpdateTime int64 `json:"update_time"`
	EndTime    int64 `json:"end_time"`

	// rule Progress `json:""`
	Progress float64 `json:"progress"`
	Info     string  `json:"info"`

	// running status `json:""`
	Finished  bool  `json:"finished"`
	Error     error `json:"error"`
	RiskCount int64 `json:"risk_count"`

	Report bool `json:"-"`
}

func (*RuleProcessInfo) Key

func (r *RuleProcessInfo) Key() string

func (*RuleProcessInfo) String

func (r *RuleProcessInfo) String() string

type RuleProcessInfoList

type RuleProcessInfoList struct {
	Progress      float64            `json:"progress"`
	Time          int64              `json:"time"`
	Rules         []*RuleProcessInfo `json:"rules"`
	FailedQuery   int64              `json:"failed_query"`
	SkippedQuery  int64              `json:"skipped_query"`
	SuccessQuery  int64              `json:"success_query"`
	FinishedQuery int64              `json:"finished_query"`
	TotalQuery    int64              `json:"total_query"`
	RiskCount     int64              `json:"risk_count"`
}

func (RuleProcessInfoList) String

func (r RuleProcessInfoList) String() string

type RuleResultCallback

type RuleResultCallback func(*ssaapi.SyntaxFlowResult)

type ScanResult

type ScanResult struct {
	TaskID string                   // 任务ID,用于唯一标识扫描任务
	Status string                   // 任务状态:"executing"执行中, "done"完成, "paused"暂停, "error"错误
	Result *ssaapi.SyntaxFlowResult // SyntaxFlow扫描结果,包含规则匹配的详细信息
}

ScanResult 扫描结果结构体,包含扫描任务的所有结果信息

type ScanResultCallback

type ScanResultCallback func(*ScanResult)

ScanResultCallback 扫描回调函数类型,用于处理扫描过程中产生的结果 回调函数会在扫描过程中被多次调用,每当有新的结果产生时都会触发 返回非nil错误将中止扫描过程

type ScanTaskCallback

type ScanTaskCallback struct {
	ProcessCallback ProcessCallback `json:"-"`

	Reporter       sfreport.IReport `json:"-"`
	ReporterWriter io.Writer        `json:"-"`

	// EnableRulePerformanceLog 是否启用规则级别的详细性能日志
	// 默认为 false,只显示任务级别的性能统计(编译时间等)
	// 设置为 true 时,会显示每个规则在每个程序上的详细执行时间
	EnableRulePerformanceLog bool `json:"-"`
	ProcessWithRule          bool `json:"-"`
	// contains filtered or unexported fields
}

type ScanTaskCallbacks

type ScanTaskCallbacks utils.SafeMap[*ScanTaskCallback]

func NewScanTaskCallbacks

func NewScanTaskCallbacks() *ScanTaskCallbacks

func (*ScanTaskCallbacks) Error

func (s *ScanTaskCallbacks) Error(taskid, status, msg string, args ...any)

Error triggers errorCallback for all callbacks.

func (*ScanTaskCallbacks) Pause

func (s *ScanTaskCallbacks) Pause() bool

func (*ScanTaskCallbacks) Process

func (s *ScanTaskCallbacks) Process(taskId, status string, progress float64, info *RuleProcessInfoList)

func (*ScanTaskCallbacks) Result

func (s *ScanTaskCallbacks) Result(result *ScanResult)

Result triggers resultCallback for all callbacks.

Jump to

Keyboard shortcuts

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