Documentation
¶
Overview ¶
Package importkit holds the text, reference and package helpers shared by the importers of package importer and the interoperability adapters (v2/interop/<format>, nested modules of this repository). It is internal: the helpers are not part of the module's API and change with the importers.
Index ¶
- Constants
- Variables
- func AddDepProperty(d *ctis.Dependency, key, value string)
- func AddRefs(dst []string, refs ...string) []string
- func AddScore(f *ctis.Finding, s ctis.Score)
- func AddTags(dst []string, tags ...string) []string
- func AddVendorID(v *ctis.VulnerabilityDetails, raw, source string)
- func AddVulnID(v *ctis.VulnerabilityDetails, raw string)
- func AddWebRefs(dst []string, refs ...string) []string
- func AppendUnique(dst []string, s string) []string
- func CleanPURL(purl string) string
- func CvssOrder(version string) int
- func CvssVectorScore(vector, source string) (ctis.Score, bool)
- func DocRef(prefix, s string) string
- func Extra(f *ctis.Finding, key, value string)
- func Extras(f *ctis.Finding, kv ...string)
- func FirstNonEmpty(vals ...string) string
- func FloatString(v float64) string
- func GoodPURL(purl string) string
- func Line(s string, limit int) string
- func NameVersion(name, version string) string
- func ParseTime(s string) *time.Time
- func Probe() ctis.Report
- func PurlName(purl string) string
- func PurlOf(ecosystem, name, version string) string
- func PurlType(purl string) string
- func RawTextEvidence(f *ctis.Finding, label, body, protocol string)
- func RefOr(prefix, s string) string
- func RepoAsset(value, branch, commit, source string) ctis.Asset
- func SeverityFromCVSS(score float64) ctis.Severity
- func SeverityWord(s string) (ctis.Severity, bool)
- func SourceRef(system, id string) ctis.SourceRef
- func StripUserinfo(s string) string
- func SubjectAssetOf(kind, purl, name, version, fallback string) (ctis.AssetType, string)
- func Text(s string, limit int) string
- func TokenOf(s string) string
- func VexOf(nativeStatus, nativeJustification, statement, source string, asOf *time.Time) (ctis.VEX, error)
- func WebURL(s string) string
Constants ¶
const ( CapTitle = 500 CapCategory = 255 CapDescription = 32 << 10 CapEvidence = 64 << 10 CapRemediation = 16 << 10 CapReference = 2 << 10 MaxReferences = 100 CapTag = 100 MaxTags = 50 CapShort = 255 )
Text caps, the same as the CTIS receiver caps (spec section 7), so a report never carries more than a receiver keeps.
const CodeAssetID = "asset-1"
CodeAssetID is the id of the one asset of a code report.
const MaxDepProperties = 32
MaxDepProperties bounds the properties of one dependency.
const MaxDependsOn = 1000
MaxDependsOn bounds the depends_on list of one dependency.
const ProbeID = "0192f0a0-0000-7000-8000-000000000001"
ProbeID is a UUIDv7: Validate requires metadata.id.
const TruncMarker = "…[truncated]"
Variables ¶
var ProbeTime = time.Unix(1, 0).UTC()
ProbeTime is any non-zero time: Validate requires metadata.generated_at.
var PurlTypes = map[string]string{
"npm": "npm", "pypi": "pypi", "pip": "pypi", "maven": "maven", "gradle": "maven",
"nuget": "nuget", "cargo": "cargo", "crates.io": "cargo", "golang": "golang", "go": "golang",
"composer": "composer", "packagist": "composer", "gem": "gem", "rubygems": "gem",
"hex": "hex", "pub": "pub", "swift": "swift", "swifturl": "swift", "cocoapods": "cocoapods",
}
PurlTypes maps OSV ecosystem names and language words to the package URL type.
Functions ¶
func AddDepProperty ¶
func AddDepProperty(d *ctis.Dependency, key, value string)
AddDepProperty sets a bounded dependency property.
func AddVendorID ¶
func AddVendorID(v *ctis.VulnerabilityDetails, raw, source string)
AddVendorID adds an id the vendor named source issued (an advisory number, a plugin id the source treats as the vulnerability's) to v.
func AddVulnID ¶
func AddVulnID(v *ctis.VulnerabilityDetails, raw string)
AddVulnID adds a CVE, GHSA or OSV id to v once (canonical form); an id of another shape is dropped. Use addVendorID for a vendor's own id.
func AddWebRefs ¶
AddWebRefs appends the http(s) URLs among refs (bounded, distinct).
func AppendUnique ¶
func CleanPURL ¶
CleanPURL bounds a package URL and drops one with control characters or whitespace (a hostile value must not reach a receiver's match keys).
func CvssVectorScore ¶
CvssVectorScore returns a CVSS score of a vector string with no value.
func DocRef ¶
DocRef builds a document-local reference "<prefix>-<s>" (ctis.IsDocumentRef: never UUID-shaped, at most 255 characters of the reference alphabet). When s does not fit the alphabet or the length, the reference is the prefix and a hash of s, so it is stable and still unique per s.
func FirstNonEmpty ¶
func FloatString ¶
FloatString formats a score for a native value.
func NameVersion ¶
NameVersion returns "name@version", or the name alone.
func PurlName ¶
PurlName returns the name of a package URL with its namespace ("@scope/name", "group:artifact"), unescaped, or "".
func PurlOf ¶
PurlOf builds a package URL from an OSV ecosystem, a name and a version; "" when the ecosystem has no package URL type or the result is not a canonical package URL.
func PurlType ¶
PurlType returns the type of a package URL ("npm", "golang", "maven"), or "" when s is not a package URL.
func RawTextEvidence ¶
RawTextEvidence adds source text as a raw_text evidence item. The text is bounded; an empty text adds nothing. Callers pass text that holds no credential (ctis.RedactSecretFinding masks what the builder sees).
func RefOr ¶
RefOr returns s when it already is a document reference, else a reference derived from it (docRef with the prefix).
func RepoAsset ¶
RepoAsset is a repository asset with the branch and commit it was scanned at, and where the importer learned it (properties.source). It carries no criticality: that is the receiver's call (CTIS spec 4.1).
func SeverityFromCVSS ¶
SeverityFromCVSS bands a CVSS base score (the CVSS v3/v4 qualitative scale).
func SeverityWord ¶
SeverityWord maps a qualitative severity word of an advisory database (CRITICAL, HIGH, MODERATE, MEDIUM, LOW, NONE, INFO).
func StripUserinfo ¶
StripUserinfo removes credentials from a URL (https://user:pass@host/).
func SubjectAssetOf ¶
SubjectAssetOf chooses the asset type and value of an SBOM subject (a CycloneDX metadata component, an SPDX root package): a container is an image when its name and version make an image reference, a component with a package URL is that package, anything else is unclassified, named by name and version (or fallback).
func Text ¶
Text cleans a source text: control characters other than tab, newline and carriage return are removed, the ends are trimmed, and a value longer than limit characters is cut with a marker.
func TokenOf ¶
TokenOf lowercases the name of an advisory source into an open token (a-z, 0-9, '.', '_', '-'); anything else becomes '-'. It may be empty.
func VexOf ¶
func VexOf(nativeStatus, nativeJustification, statement, source string, asOf *time.Time) (ctis.VEX, error)
VexOf builds a CTIS VEX statement from a document's native status and justification. It returns an error for a status no table knows, and for a not_affected statement with neither a known justification nor an impact statement (CTIS requires one of them, and a receiver must not suppress a finding on a bare claim).
Types ¶
This section is empty.