semgrep

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package semgrep holds all of the data structures and logic related to running semgrep commands on a codebase.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSemgrepConfigValue

func CreateSemgrepConfigValue(template string, rulesDir string) (string, error)

CreateSemgrepConfigValue creates a semgrep config value based on the provided template and rules directory. If the template is not valid, an error is returned.

Types

type Dev

type Dev struct {
	Origin    string `json:"origin" yaml:"origin"`
	RID       string `json:"r_id" yaml:"r_id"`
	RuleID    string `json:"rule_id" yaml:"rule_id"`
	RVID      string `json:"rv_id" yaml:"rv_id"`
	URL       string `json:"url" yaml:"url"`
	VersionID string `json:"version_id" yaml:"version_id"`
}

Dev holds all of the development information for a semgrep finding.

type Error

type Error struct {
	Code    int    `json:"code" yaml:"code"`
	Level   string `json:"level" yaml:"level"`
	Message string `json:"message" yaml:"message"`
	Type    string `json:"type" yaml:"type"`
}

Error holds the error information for a semgrep finding.

type Extra

type Extra struct {
	EngineKind      string             `json:"engine_kind" yaml:"engine_kind"`
	Fingerprint     string             `json:"fingerprint" yaml:"fingerprint"`
	IsIgnored       bool               `json:"is_ignored" yaml:"is_ignored"`
	Lines           string             `json:"lines" yaml:"lines"`
	Message         string             `json:"message" yaml:"message"`
	Metadata        Metadata           `json:"metadata" yaml:"metadata"`
	Metavars        map[string]Metavar `json:"metavars" yaml:"metavars"`
	Severity        string             `json:"severity" yaml:"severity"`
	ValidationState string             `json:"validation_state" yaml:"validation_state"`
	SemgrepDev      Dev                `json:"semgrep.dev" yaml:"semgrep.dev"`
	Shortlink       string             `json:"shortlink" yaml:"shortlink"`
	Source          string             `json:"source" yaml:"source"`
	SourceRuleURL   string             `json:"source-rule-url" yaml:"source-rule-url"`
}

Extra holds additional information for a semgrep finding.

type Metadata

type Metadata struct {
	Category           string   `json:"category" yaml:"category"`
	Confidence         string   `json:"confidence" yaml:"confidence"`
	CWE                []string `json:"cwe" yaml:"cwe"`
	CWE2021Top25       bool     `json:"cwe2021-top25" yaml:"cwe2021-top25"`
	CWE2022Top25       bool     `json:"cwe2022-top25" yaml:"cwe2022-top25"`
	Impact             string   `json:"impact" yaml:"impact"`
	License            string   `json:"license" yaml:"license"`
	Likelihood         string   `json:"likelihood" yaml:"likelihood"`
	OWASP              []string `json:"owasp" yaml:"owasp"`
	References         []string `json:"references" yaml:"references"`
	Subcategory        []string `json:"subcategory" yaml:"subcategory"`
	Technology         []string `json:"technology" yaml:"technology"`
	VulnerabilityClass []string `json:"vulnerability_class" yaml:"vulnerability_class"`
}

Metadata holds the metadata for a semgrep finding.

type Metavar

type Metavar struct {
	AbstractContent string `json:"abstract_content" yaml:"abstract_content"`
	End             struct {
		Col    int `json:"col" yaml:"col"`
		Line   int `json:"line" yaml:"line"`
		Offset int `json:"offset" yaml:"offset"`
	} `json:"end" yaml:"end"`
	Start struct {
		Col    int `json:"col" yaml:"col"`
		Line   int `json:"line" yaml:"line"`
		Offset int `json:"offset" yaml:"offset"`
	} `json:"start" yaml:"start"`
}

Metavar holds the meta variable information for a semgrep finding.

type Report

type Report struct {
	Errors  []Error  `json:"errors" yaml:"errors"`
	Results []Result `json:"results" yaml:"results"`
}

Report holds all of the information for a semgrep run, including all of the non-fatal errors and results.

func ExecuteSemgrep

func ExecuteSemgrep(ctx context.Context, target string, configValue string) (Report, error)

ExecuteSemgrep runs the semgrep command with the provided target and configValue. It returns the report of the semgrep including all of the results and the non-fatal errors.

type Result

type Result struct {
	CheckID string `json:"check_id" yaml:"check_id"`
	Path    string `json:"path" yaml:"path"`
	Start   struct {
		Line   int `json:"line" yaml:"line"`
		Col    int `json:"col" yaml:"col"`
		Offset int `json:"offset" yaml:"offset"`
	} `json:"start" yaml:"start"`
	End struct {
		Line   int `json:"line" yaml:"line"`
		Col    int `json:"col" yaml:"col"`
		Offset int `json:"offset" yaml:"offset"`
	} `json:"end" yaml:"end"`
	Extra Extra `json:"extra" yaml:"extra"`
}

Result holds the output result information for a given semgrep finding.

Jump to

Keyboard shortcuts

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