fingerprint

package
v1.6.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 5 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fingerprint provides unified fingerprint generation algorithms for deduplication of security findings across SDK and Backend.

IMPORTANT: This package is shared between sdk and api. Any changes to fingerprint algorithms must be backward compatible or coordinated across both projects.

Index

Constants

View Source
const MaxSnippetHashLines = 10

MaxSnippetHashLines is how many lines of a match SnippetHash input should hold at most. Scanners cut long matches (Semgrep and Opengrep keep the first lines of a match), so a producer that reads the lines from the file cuts at the same place and both agree.

View Source
const PartialSnippetHash = "snippetHash/v1"

PartialSnippetHash is the partial_fingerprints key that carries SnippetHash of a SAST finding's source lines when the report does not carry the lines themselves. A producer that has the scanned tree (a CI job, a sensor) sends the hash instead of the code: the receiver keys the finding on the code it flags without receiving that code.

Variables

This section is empty.

Functions

func Generate

func Generate(input Input) string

Generate creates a fingerprint for the given input. The fingerprint is a SHA256 hash (64 hex characters) that uniquely identifies a finding based on its type and relevant attributes.

The algorithm varies by finding type to ensure optimal deduplication:

  • SAST: file + rule + location (same vulnerability in same place)
  • SAST content: file + rule + enclosing function + snippet hash (no lines)
  • SCA: package + version + vuln ID (same vuln in same dependency)
  • Secret: file + rule + location + secret hash (same secret in same place)
  • Misconfig: resource + rule (same misconfiguration on same resource)
  • Generic: rule + file + location + message (fallback)

func GenerateAuto

func GenerateAuto(input Input) string

GenerateAuto automatically detects the type and generates a fingerprint. Use this when you're not sure which specific generator to use.

func GenerateContainer

func GenerateContainer(imageTarget, packageName, packageVersion, vulnID string) string

GenerateContainer creates a fingerprint for container image vulnerability findings. imageTarget is the image name or digest (e.g., "nginx:latest"). packageName is the vulnerable package name. packageVersion is the installed package version. vulnID is the CVE or other vulnerability identifier.

func GenerateDAST

func GenerateDAST(templateID, targetHost, targetPath, parameter string) string

GenerateDAST creates a fingerprint for DAST findings (Nuclei, ZAP, etc.). templateID is the scanner rule/template ID. targetHost is the hostname being scanned. targetPath is the URL path where the finding was detected. parameter is the affected parameter name (not value).

func GenerateGeneric

func GenerateGeneric(ruleID, filePath string, startLine, endLine int, message string) string

GenerateGeneric creates a fingerprint for generic findings. Use this when the finding type doesn't fit other categories.

func GenerateMisconfiguration

func GenerateMisconfiguration(resourceType, resourceName, ruleID, filePath string) string

GenerateMisconfiguration creates a fingerprint for misconfiguration findings.

func GenerateSAST

func GenerateSAST(filePath, ruleID string, startLine, endLine int) string

GenerateSAST creates a fingerprint for SAST/code vulnerability findings. This is a convenience function for the common SAST case.

func GenerateSASTStable added in v1.6.0

func GenerateSASTStable(filePath, ruleID, logicalLocation, snippet string) string

GenerateSASTStable creates a line-independent SAST fingerprint from the file, the rule, the enclosing function (logicalLocation, may be empty) and the source snippet of the finding. Whitespace differences in the snippet are ignored. Inserting code above the finding does not change the result; editing the flagged code or moving it to another function does.

It returns "" when snippet is empty: without the code the key would merge every match of the rule in the file, so callers must fall back to GenerateSAST.

func GenerateSCA

func GenerateSCA(packageName, packageVersion, vulnID string) string

GenerateSCA creates a fingerprint for SCA/dependency vulnerability findings. This is a convenience function for the common SCA case.

func GenerateSecret

func GenerateSecret(filePath, ruleID string, startLine int, secretValue string) string

GenerateSecret creates a fingerprint for secret detection findings. This is a convenience function for the common secret case.

func GenerateWeb3

func GenerateWeb3(contractAddress string, chainID int, swcID, functionSignature string) string

GenerateWeb3 creates a fingerprint for smart contract findings (Slither, Mythril, etc.). contractAddress is the contract address (e.g., "0x..."). chainID is the blockchain chain ID (e.g., 1 for Ethereum mainnet). swcID is the SWC registry ID (e.g., "SWC-101"). functionSignature is the affected function (e.g., "transfer(address,uint256)").

func Hash

func Hash(s string) string

Hash computes SHA256 hash of the input string. Returns 64 hex characters.

func SnippetHash added in v1.6.1

func SnippetHash(snippet string) string

SnippetHash is the hash of the code a SAST finding flags, independent of the line it is on and of indentation: CRLF becomes LF, each line is trimmed and every run of whitespace inside it becomes one space, empty lines are dropped, and the rest is joined with LF. The result is the first 16 bytes of its SHA-256 in lowercase hex (32 characters), or "" when no code is left. Moving the code changes nothing; editing it changes the hash.

The receiver computes the same value from finding.location.snippet, so a producer that sends the snippet and one that sends only this hash (as PartialSnippetHash) key the same finding the same way.

Types

type Input

type Input struct {
	// Type of finding (sast, sca, secret, misconfig, generic)
	Type Type

	// Common fields
	RuleID   string // Rule/check identifier
	FilePath string // File path where finding was detected
	Message  string // Finding message/description

	// Location fields (for SAST, Secret)
	StartLine   int
	EndLine     int
	StartColumn int
	EndColumn   int

	// SCA-specific fields
	PackageName     string // Package/dependency name
	PackageVersion  string // Package version
	VulnerabilityID string // CVE ID or other vuln identifier

	// SAST-content fields
	Snippet         string // Source text of the finding's region
	LogicalLocation string // Enclosing function/method, fully qualified when known

	// Secret-specific fields. Never pass the raw secret: the hash prefix is
	// unsalted and short, so it identifies the secret to anyone holding it.
	// Pass the masked value or a keyed hash (HMAC) of the secret instead.
	SecretValue string

	// Misconfiguration-specific fields
	ResourceType string // e.g., "aws_s3_bucket", "dockerfile"
	ResourceName string // Resource identifier

	// DAST-specific fields (for Nuclei, ZAP)
	TargetHost string // Target hostname (e.g., "example.com")
	TargetPath string // URL path (e.g., "/api/users")
	Parameter  string // Affected parameter name (e.g., "id")

	// Container-specific fields (for Trivy image)
	ImageTarget string // Image name or digest (e.g., "nginx:latest", "sha256:abc...")

	// Web3-specific fields (for Slither)
	ContractAddress   string // Contract address (e.g., "0x...")
	ChainID           int    // Blockchain chain ID (e.g., 1 for Ethereum mainnet)
	SWCID             string // SWC registry ID (e.g., "SWC-101")
	FunctionSignature string // Function signature (e.g., "transfer(address,uint256)")
}

Input contains the data needed to generate a fingerprint. Not all fields are required - only the relevant ones for the finding type.

type Type

type Type string

Type represents the type of finding for fingerprint generation.

const (
	// TypeSAST is for Static Application Security Testing findings (code vulnerabilities).
	// Its key includes the line numbers, so the identity changes when code
	// above the finding moves. Prefer TypeSASTContent when a snippet is known.
	TypeSAST Type = "sast"

	// TypeSASTContent is the line-independent SAST recipe: file, rule,
	// enclosing function and the normalised source snippet.
	TypeSASTContent Type = "sast-content"

	// TypeSCA is for Software Composition Analysis findings (dependency vulnerabilities).
	TypeSCA Type = "sca"

	// TypeSecret is for secret/credential detection findings.
	TypeSecret Type = "secret"

	// TypeMisconfiguration is for infrastructure/configuration findings.
	TypeMisconfiguration Type = "misconfig"

	// TypeDAST is for Dynamic Application Security Testing findings (Nuclei, ZAP).
	TypeDAST Type = "dast"

	// TypeContainer is for container image vulnerability findings (Trivy image).
	TypeContainer Type = "container"

	// TypeWeb3 is for smart contract/blockchain findings (Slither).
	TypeWeb3 Type = "web3"

	// TypeGeneric is for findings that don't fit other categories.
	TypeGeneric Type = "generic"
)

func DetectType

func DetectType(input Input) Type

DetectType attempts to detect the finding type from available data. This is useful when the type is not explicitly provided.

Jump to

Keyboard shortcuts

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