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
- func Generate(input Input) string
- func GenerateAuto(input Input) string
- func GenerateContainer(imageTarget, packageName, packageVersion, vulnID string) string
- func GenerateDAST(templateID, targetHost, targetPath, parameter string) string
- func GenerateGeneric(ruleID, filePath string, startLine, endLine int, message string) string
- func GenerateMisconfiguration(resourceType, resourceName, ruleID, filePath string) string
- func GenerateSAST(filePath, ruleID string, startLine, endLine int) string
- func GenerateSASTStable(filePath, ruleID, logicalLocation, snippet string) string
- func GenerateSCA(packageName, packageVersion, vulnID string) string
- func GenerateSecret(filePath, ruleID string, startLine int, secretValue string) string
- func GenerateWeb3(contractAddress string, chainID int, swcID, functionSignature string) string
- func Hash(s string) string
- func SnippetHash(snippet string) string
- type Input
- type Type
Constants ¶
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.
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 ¶
Generate creates a fingerprint for the given input.
The recipes below are recipe v1 (CTIS 1.x) and are frozen: receivers store the values, so no change may alter an output (TestRecipeV1Pinned pins them). Two known weaknesses are never changed in v1; recipe v2 ("ctis-fp/2", CTIS 2.0) replaces them:
- Joiner ambiguity: most recipes join their fields with ":", and a field that itself contains ":" (a maven package name such as "group:artifact") can shift into the next field, so two different inputs can share a value. Escaping ":" would change the fingerprints of every existing maven finding; v2 joins with the unit separator "\x1f", as TypeSASTContent already does, and escapes nothing.
- Unsalted secret prefix: TypeSecret hashes SecretValue without a key and keeps 16 hex characters, so anyone holding a candidate secret can confirm it. From 2.0 a receiver accepts only HMAC-SHA256(producer_key, secret) in that position; callers should pass such a keyed value (or a masked one) already today.
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 ¶
GenerateAuto automatically detects the type and generates a fingerprint. Use this when you're not sure which specific generator to use.
func GenerateContainer ¶
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 ¶
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 ¶
GenerateGeneric creates a fingerprint for generic findings. Use this when the finding type doesn't fit other categories.
func GenerateMisconfiguration ¶
GenerateMisconfiguration creates a fingerprint for misconfiguration findings.
func GenerateSAST ¶
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
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 ¶
GenerateSCA creates a fingerprint for SCA/dependency vulnerability findings. This is a convenience function for the common SCA case.
func GenerateSecret ¶
GenerateSecret creates a fingerprint for secret detection findings. This is a convenience function for the common secret case.
func GenerateWeb3 ¶
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 SnippetHash ¶ added in v1.6.1
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 ¶
DetectType attempts to detect the finding type from available data. This is useful when the type is not explicitly provided.