detector

package
v1.18.2 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. * * This product includes software developed at Datadog (https://www.datadoghq.com) Copyright 2024 Datadog, Inc.

* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. * * This product includes software developed at Datadog (https://www.datadoghq.com) Copyright 2024 Datadog, Inc.

* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. * * This product includes software developed at Datadog (https://www.datadoghq.com) Copyright 2024 Datadog, Inc.

* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. * * This product includes software developed at Datadog (https://www.datadoghq.com) Copyright 2024 Datadog, Inc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComposeSearchPath added in v1.17.0

func ComposeSearchPath(searchKey string) []string

ComposeSearchPath turns a search key into structural path components using the shared search-key expansion (anchor stripping, top-level dot split, bracket group expansion), the same rules the Terraform plan path uses.

func ExtractLineFragment

func ExtractLineFragment(line, substr string, key bool) string

ExtractLineFragment will prepare substr for line detection

func GenerateSubstrings

func GenerateSubstrings(ctx context.Context, key string, extracted [][]string, lines []string, currentLine int) (string, string)

GenerateSubstrings returns the substrings used for line searching depending on search key '.' is new line '=' is value in the same line '[]' is in the same line nolint:gocritic

func GetAdjacentVulnLines

func GetAdjacentVulnLines(idx, adj int, lines []string) *[]model.CodeLine

GetAdjacentVulnLines is used to get the lines adjacent to the line that contains the vulnerability adj is the amount of lines wanted

func GetBracketValues

func GetBracketValues(expr string, list [][]string, restOfString string) [][]string

GetBracketValues gets values inside "{{ }}" ignoring any "{{" or "}}" inside

func GetLineBySearchLine

func GetLineBySearchLine(pathComponents []string, file *model.FileMetadata) int

GetLineBySearchLine finds the line of a key in the original file, given its path as a slice of strings, by walking the file's line-info document.

The document is walked in place rather than serialized: this runs once per finding, and the document can be hundreds of KB. Returns -1 when no line marker matches.

func SelectLineWithMinimumDistance

func SelectLineWithMinimumDistance(distances map[int]int, startingFrom int) int

SelectLineWithMinimumDistance will search a map of levenshtein distances to find the minimum distance

Types

type DefaultDetectLineResponse

type DefaultDetectLineResponse struct {
	CurrentLine     int
	IsBreak         bool
	FoundAtLeastOne bool
	ResolvedFile    string
	ResolvedFiles   map[string]model.ResolvedFileSplit
}

DefaultDetectLineResponse is the default response for struct DetectLine

func (*DefaultDetectLineResponse) DetectCurrentLine

func (d *DefaultDetectLineResponse) DetectCurrentLine(str1, str2 string, recurseCount int,
	lines []string, kind model.FileKind) (*DefaultDetectLineResponse, model.ResourceLine, model.ResourceLine, []string)

DetectCurrentLine uses levenshtein distance to find the most accurate line for the vulnerability nolint:gocritic

type DetectLine

type DetectLine struct {
	// contains filtered or unexported fields
}

DetectLine is a struct that associates a kindDetectLine to its FileKind

func NewDetectLine

func NewDetectLine(outputLines int) *DetectLine

NewDetectLine creates a new DetectLine's reference

func (*DetectLine) Add

func (d *DetectLine) Add(detector kindDetectLine, kind model.FileKind) *DetectLine

Add adds a new kindDetectLine to the caller and returns it

func (*DetectLine) DetectLine

func (d *DetectLine) DetectLine(ctx context.Context, file *model.FileMetadata, searchKey string) model.VulnerabilityLines

DetectLine will use the correct kindDetectLine according to the files kind if file kind is not in detectors default detect line is called

func (*DetectLine) SetupLogs

func (d *DetectLine) SetupLogs(logger *zerolog.Logger)

SetupLogs will change the logger feild to be used in kindDetectLine DetectLine method

type DockerComposeDetectLine added in v1.17.0

type DockerComposeDetectLine struct{}

dockerComposeDetectLine resolves compose findings structurally from the document's _dd_lines first: text matching walks the file lines in order and misattributes values merged in from sibling files (e.g. an image inherited via extends). Text matching stays as the fallback for other YAML platforms and for failed lookups.

func (DockerComposeDetectLine) DetectLine added in v1.17.0

func (d DockerComposeDetectLine) DetectLine(ctx context.Context, file *model.FileMetadata, searchKey string,
	outputLines int) model.VulnerabilityLines

DetectLine resolves the vulnerability line for a finding.

Directories

Path Synopsis
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.

Jump to

Keyboard shortcuts

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