Documentation
¶
Overview ¶
Package model is the TokenHound Finding and Report model: statuses and their classes, confidence, grades, targets, locations, warnings, progress events and the canonical JSON Report (docs/schema/report.v1.json).
It imports only the standard library, so every internal package can share it without importing the public tokenhound package. The tokenhound package re-exports every identifier here with type aliases, so tokenhound.Finding and model.Finding are the same type.
Index ¶
- Constants
- func SurfaceRank(status string) int
- func WarningCodes() []string
- type Confidence
- type DetectorInfo
- type DollarsMethod
- type Event
- type EventKind
- type Finding
- type FirstSeen
- type FixPlan
- type FixStep
- type Grade
- type Location
- type LocationKind
- type Meta
- type ProviderInfo
- type Report
- type Status
- type StatusClass
- type SurfaceStatus
- type Target
- type TargetGrade
- type TargetKind
- type Timestamp
- type USD
- type VerifyEvidence
- type Visibility
- type Warning
Constants ¶
const ( VerificationOn = "on" VerificationOff = "off" )
Verification values of Meta.Verification.
const ( // SurfaceFound: at least one file of the surface exists and was opened (a file // that failed to parse or was too large still counts as found). SurfaceFound = "found" // SurfaceNotInstalled: no file of the surface exists. SurfaceNotInstalled = "not_installed" // SurfaceUnreadable: a file of the surface exists but none could be read. SurfaceUnreadable = "unreadable" // SurfaceNotVisited: the scan stopped (timeout or cancel) before this surface was // looked for, so nothing is known about it. It never appears on a completed scan. SurfaceNotVisited = "not_visited" )
Surface statuses.
const ( // CodeFileUnreadable is a file that could not be opened or read; the rest of the // scan continues. CodeFileUnreadable = "file_unreadable" // CodeInternalError is an error no other code describes. CodeInternalError = "internal_error" // CodeReadFailed is a file, blob or stream that could not be read. CodeReadFailed = "read_failed" // CodeRegistryEntrySkipped is a registry file skipped while the rest loaded. CodeRegistryEntrySkipped = "registry_entry_skipped" // CodeTimeout is a scan stopped by its timeout with partial results. CodeTimeout = "timeout" // CodeUntrustedConfigKey is a project-tier config value that was not honoured as // written. The detail says why: project_tier (a key only the user tier may set: // network.*, alerts.*, hook.*, ping), gate_loosening (verification off, timeout, // a lower limits.* or verify.timeout, a higher grade.f_threshold_usd_per_day or // verify.max_concurrency), project_limit_cap (a limit raised above 4x its // default) and fail_on_loosening (a fail_on that would loosen the policy) mean // the value was ignored; env_reference means a ${NAME} reference was kept as a // literal, not expanded. CodeUntrustedConfigKey = "untrusted_config_key" // CodeConfigPathOutsideRoot is a project config path that escapes the project // root (absolute or with ..); it was ignored. CodeConfigPathOutsideRoot = "config_path_outside_root" // CodeFileTooLarge is a file or stream larger than limits.max_file_bytes; it was // skipped. CodeFileTooLarge = "file_too_large" // CodeGitNotFound is a scan root inside a git repository that was walked without // git, because no git binary was found. Files that .gitignore excludes were not // skipped. CodeGitNotFound = "git_not_found" // CodeDecodeDepthLimit is decoding of a chunk that stopped early: max_depth means // a span nested deeper than limits.decode_max_depth was not decoded, size_budget // means the decoded bytes of one chunk reached their budget. The rest of the scan // continues. CodeDecodeDepthLimit = "decode_depth_limit" // CodeSurfaceParseFailed is an agent surface file that could not be parsed in // full: the detail parse_error means the file is corrupt or malformed (it was // skipped), unsupported_format means the surface names a parse format this binary // has no parser for yet (skipped), partial_parse means a tolerant parser (dotenv) // skipped some lines and read the rest, walk_limit means the search for files stopped // at its entry budget, budget means the surface files read so far reached the byte // budget and the rest were not read. The scan continues. CodeSurfaceParseFailed = "surface_parse_failed" // CodeNotebookParseFailed is a .ipynb file in the working tree that is not a // readable notebook (not JSON, not an object, no cells array, truncated): the file // was scanned as plain text instead, without cell locations. The detail is // parse_error. The scan continues. CodeNotebookParseFailed = "notebook_parse_failed" )
Warning codes. Every code is listed in docs/schema/report.v1.json.
const ( // ProviderGeneric is the provider id of findings no provider pattern claims. ProviderGeneric = "generic" // ProviderGenericName is the display name of ProviderGeneric. ProviderGenericName = "Generic" // DetectorGenericHighEntropy is the detector id of the generic entropy detector. DetectorGenericHighEntropy = "generic.high-entropy" // DetectorGenericHighEntropyName is the pattern name of DetectorGenericHighEntropy. DetectorGenericHighEntropyName = "high-entropy" )
The built-in generic entropy detector. It has no registry entry; the engine adds these provider and detector facts to a Report that references them.
const SchemaVersion = 1
SchemaVersion is the version of the JSON Report schema (docs/schema/report.v1.json) that this model marshals to.
Variables ¶
This section is empty.
Functions ¶
func SurfaceRank ¶
SurfaceRank orders surface statuses for merging: found beats unreadable beats not_installed beats not_visited. An unknown status ranks lowest.
func WarningCodes ¶
func WarningCodes() []string
WarningCodes returns every documented warning code, sorted.
Types ¶
type Confidence ¶
type Confidence string
Confidence is how sure detection is that a match is a real key.
const ( ConfidenceHigh Confidence = "high" ConfidenceMedium Confidence = "medium" ConfidenceLow Confidence = "low" )
Confidence levels.
func (Confidence) Valid ¶
func (c Confidence) Valid() bool
Valid reports whether c is a known confidence level.
type DetectorInfo ¶
DetectorInfo describes a detector referenced by a finding.
type DollarsMethod ¶
type DollarsMethod struct {
// Formula is the arithmetic applied, as text.
Formula string `json:"formula"`
// Tier is the spend registry tier id the figure uses.
Tier string `json:"tier"`
// TierSource is "verified" when verification saw the tier, else "default".
TierSource string `json:"tier_source"`
// Assumed is true when the tier is the registry default, not one verification saw.
Assumed bool `json:"assumed"`
// LimitPerMin is the rate limit in LimitUnit per minute.
LimitPerMin int64 `json:"limit_per_min"`
// LimitSource is "verified" when LimitPerMin came from verify_evidence.limits,
// else "tier".
LimitSource string `json:"limit_source"`
// LimitUnit is "tokens" or "requests".
LimitUnit string `json:"limit_unit"`
// UnitPriceUSD is the price of PriceUnitSize limit units.
UnitPriceUSD USD `json:"unit_price_usd"`
// PriceUnitSize is how many limit units UnitPriceUSD buys (1000000 for token
// prices written per million tokens).
PriceUnitSize int64 `json:"price_unit_size"`
// Model is the most expensive model the tier reaches.
Model string `json:"model"`
// CapUSDPerDay is the tier spend cap, when the registry knows one.
CapUSDPerDay *USD `json:"cap_usd_per_day,omitempty"`
// SpendAsOf is the date of the spend registry figures, YYYY-MM-DD.
SpendAsOf string `json:"spend_as_of"`
}
DollarsMethod lists the inputs behind a dollars-at-risk figure, so a reader can check or challenge it.
type Event ¶
type Event struct {
Kind EventKind `json:"kind"`
ID string `json:"id"`
Provider string `json:"provider"`
Detector string `json:"detector"`
Redacted string `json:"redacted"`
Location *Location `json:"location,omitempty"`
}
Event is a scan progress event. It carries the redacted form of a key only, never key material. Location is the sighting that caused the event, when there is one.
type EventKind ¶
type EventKind string
EventKind is the kind of a scan progress event.
const ( // EventFindingDetected is sent the first time a credential is seen. EventFindingDetected EventKind = "finding-detected" // EventLocationAdded is sent for every later sighting of a known credential. EventLocationAdded EventKind = "location-added" // EventStatusUpdated is sent when verification changes a finding's status. EventStatusUpdated EventKind = "status-updated" )
Event kinds.
type Finding ¶
type Finding struct {
// ID is the fingerprint "th_" plus 16 lowercase hex characters.
ID string `json:"id"`
Provider string `json:"provider"`
Detector string `json:"detector"`
AlsoMatchedBy []string `json:"also_matched_by,omitempty"`
Confidence Confidence `json:"confidence"`
// Redacted is the display form, for example "sk-pro...a1b2 (51)".
Redacted string `json:"redacted"`
Locations []Location `json:"locations"`
Suppressed bool `json:"suppressed"`
SuppressionReason string `json:"suppression_reason,omitempty"`
NewVsBaseline *bool `json:"new_vs_baseline,omitempty"`
Status Status `json:"status"`
StatusReason string `json:"status_reason,omitempty"`
Verified bool `json:"verified"`
VerifyEvidence *VerifyEvidence `json:"verify_evidence,omitempty"`
Tier string `json:"tier,omitempty"`
Scopes []string `json:"scopes,omitempty"`
Org string `json:"org,omitempty"`
FirstSeen *FirstSeen `json:"first_seen,omitempty"`
AgeDays *int `json:"age_days,omitempty"`
// DollarsAtRiskPerDay is set for verified keys; dead keys carry 0.
DollarsAtRiskPerDay *USD `json:"dollars_at_risk_per_day,omitempty"`
// PotentialDollarsAtRiskPerDay is set for unverified keys and never graded.
PotentialDollarsAtRiskPerDay *USD `json:"potential_dollars_at_risk_per_day,omitempty"`
DollarsMethod *DollarsMethod `json:"dollars_method,omitempty"`
FixPlan *FixPlan `json:"fix_plan,omitempty"`
}
Finding is one unique credential with every place it was seen. It never holds key material: only the redacted form.
func (Finding) MarshalJSON ¶
MarshalJSON marshals locations as [] when nil.
type FirstSeen ¶
type FirstSeen struct {
Commit string `json:"commit"`
Author string `json:"author"`
Date Timestamp `json:"date"`
}
FirstSeen is the earliest commit that introduced a key.
type FixPlan ¶
type FixPlan struct {
Steps []FixStep `json:"steps"`
}
FixPlan is the ordered list of steps to contain a finding.
func (FixPlan) MarshalJSON ¶
MarshalJSON marshals steps as [] when nil.
type FixStep ¶
type FixStep struct {
Kind string `json:"kind"`
Text string `json:"text"`
URL string `json:"url,omitempty"`
Command string `json:"command,omitempty"`
}
FixStep is one fix plan step.
type Grade ¶
type Grade string
Grade is an A to F exposure grade for a target or the whole report.
type Location ¶
type Location struct {
Target Target `json:"target"`
Kind LocationKind `json:"kind"`
// Path uses forward slashes; machine paths start with "~/" and archive members
// are joined with "!/".
Path string `json:"path"`
Line int `json:"line,omitempty"`
Column int `json:"column,omitempty"`
Commit string `json:"commit,omitempty"`
Author string `json:"author,omitempty"`
Date Timestamp `json:"date,omitzero"`
Branch string `json:"branch,omitempty"`
Layer string `json:"layer,omitempty"`
SurfaceID string `json:"surface_id,omitempty"`
Field string `json:"field,omitempty"`
Cell int `json:"cell,omitempty"`
}
Location is one place a finding was seen. It never carries file content. Line, Column and Cell are 1-based and omitted when 0.
type LocationKind ¶
type LocationKind string
LocationKind is where in a target a finding was seen.
const ( LocationFile LocationKind = "file" LocationStaged LocationKind = "staged" LocationCommit LocationKind = "commit" LocationImage LocationKind = "image" LocationArchive LocationKind = "archive" LocationNotebook LocationKind = "notebook" LocationSurface LocationKind = "surface" LocationStdin LocationKind = "stdin" )
Location kinds.
func (LocationKind) Valid ¶
func (k LocationKind) Valid() bool
Valid reports whether k is a known location kind.
type Meta ¶
type Meta struct {
SchemaVersion int `json:"schema_version"`
ToolVersion string `json:"tool_version"`
RegistrySnapshot string `json:"registry_snapshot"`
GeneratedAt Timestamp `json:"generated_at"`
DurationMS int64 `json:"duration_ms"`
// FilesScanned counts the files and streams whose content reached detection.
FilesScanned int `json:"files_scanned"`
// Verification is "on" when keys were verified with read-only calls and "off"
// when the run was offline (--no-verify); empty when unknown.
Verification string `json:"verification,omitempty"`
// HistoryScanned is true when git history was scanned.
HistoryScanned bool `json:"history_scanned,omitempty"`
// CommitsScanned counts the commits of the scanned history.
CommitsScanned int `json:"commits_scanned,omitempty"`
// BinarySkipped counts the files skipped because a NUL byte appears in their first
// 8 KiB. They are not warnings and do not count in FilesScanned.
BinarySkipped int `json:"binary_skipped,omitempty"`
}
Meta describes the run that produced a Report.
type ProviderInfo ¶
type ProviderInfo struct {
Name string `json:"name"`
RevokeURL string `json:"revoke_url,omitempty"`
RotateDoc string `json:"rotate_doc,omitempty"`
// VerifyHost is the host a read-only verification call goes to ("*" marks a
// templated label), for providers that have a verify block.
VerifyHost string `json:"verify_host,omitempty"`
// VerifyNote says in one short phrase how keys are checked, for example
// "read-only GET call to api.openai.com (models)".
VerifyNote string `json:"verify_note,omitempty"`
}
ProviderInfo describes a provider referenced by a finding, so a Report is self-sufficient.
type Report ¶
type Report struct {
Meta Meta `json:"meta"`
Targets []Target `json:"targets"`
// Providers and Detectors are keyed by id and hold every id a finding references.
Providers map[string]ProviderInfo `json:"providers"`
Detectors map[string]DetectorInfo `json:"detectors"`
Findings []Finding `json:"findings"`
Warnings []Warning `json:"warnings"`
Grades []TargetGrade `json:"grades"`
Grade Grade `json:"grade"`
GradeReasons []string `json:"grade_reasons"`
// SurfacesChecked lists every agent surface a surface scan looked at and whether
// its files were there. It is omitted when no surface was scanned, so Reports of
// other scans do not change.
SurfacesChecked []SurfaceStatus `json:"surfaces_checked,omitempty"`
}
Report is the canonical result of a scan.
func (Report) MarshalJSON ¶
MarshalJSON marshals nil arrays as [] and nil maps as {}.
type Status ¶
type Status string
Status is the verification status of a finding.
const ( StatusLive Status = "live" StatusDead Status = "dead" StatusUnknown Status = "unknown" StatusRateLimited Status = "rate-limited" StatusNotVerified Status = "not-verified" )
Verification statuses.
func (Status) Class ¶
func (s Status) Class() StatusClass
Class returns the class of s, or "" when s is not a known status.
type StatusClass ¶
type StatusClass string
StatusClass groups statuses for ranking, grading and fail_on.
const ( ClassLive StatusClass = "live" ClassUnverified StatusClass = "unverified" ClassDead StatusClass = "dead" )
Status classes. Unverified covers not-verified, unknown and rate-limited.
type SurfaceStatus ¶
type SurfaceStatus struct {
// SurfaceID is the registry id of the surface, for example "codex".
SurfaceID string `json:"surface_id"`
// Status is SurfaceFound, SurfaceNotInstalled, SurfaceUnreadable or SurfaceNotVisited.
Status string `json:"status"`
}
SurfaceStatus is the outcome of looking for one agent surface.
type Target ¶
type Target struct {
Kind TargetKind `json:"kind"`
ID string `json:"id"`
Visibility Visibility `json:"visibility"`
}
Target is one scanned thing: a repo, this machine, an image, an org repo or stdin.
type TargetGrade ¶
type TargetGrade struct {
Target Target `json:"target"`
Grade Grade `json:"grade"`
Reasons []string `json:"reasons"`
}
TargetGrade is the grade of one target with the reasons that set it.
func (TargetGrade) MarshalJSON ¶
func (g TargetGrade) MarshalJSON() ([]byte, error)
MarshalJSON marshals reasons as [] when nil.
type TargetKind ¶
type TargetKind string
TargetKind is the kind of thing a scan target is.
const ( TargetRepo TargetKind = "repo" TargetMachine TargetKind = "machine" TargetImage TargetKind = "image" TargetOrgRepo TargetKind = "org-repo" TargetStdin TargetKind = "stdin" )
Target kinds.
func (TargetKind) Valid ¶
func (k TargetKind) Valid() bool
Valid reports whether k is a known target kind.
type Timestamp ¶
Timestamp is a point in time that marshals as RFC 3339 in UTC with whole seconds, for example "2026-11-13T00:00:00Z".
func (Timestamp) MarshalJSON ¶
MarshalJSON marshals t as an RFC 3339 UTC string with whole seconds.
type USD ¶
type USD float64
USD is an amount in US dollars. It marshals as a JSON number with exactly two decimals, rounded half away from zero.
func (USD) MarshalJSON ¶
MarshalJSON marshals u with exactly two decimals. Negative amounts are an error: every money field in the report schema has minimum 0. Negative zero marshals as 0.00.
type VerifyEvidence ¶
type VerifyEvidence struct {
Tier string `json:"tier,omitempty"`
Org string `json:"org,omitempty"`
Project string `json:"project,omitempty"`
Scopes []string `json:"scopes,omitempty"`
Limits map[string]string `json:"limits,omitempty"`
}
VerifyEvidence is what a live verification response revealed.
type Visibility ¶
type Visibility string
Visibility is whether a target is publicly readable.
const ( VisibilityPublic Visibility = "public" VisibilityPrivate Visibility = "private" VisibilityUnknown Visibility = "unknown" )
Visibilities.
func (Visibility) Valid ¶
func (v Visibility) Valid() bool
Valid reports whether v is a known visibility.
type Warning ¶
type Warning struct {
Code string `json:"code"`
Location string `json:"location"`
DetailCode string `json:"detail_code"`
}
Warning is a non-fatal problem in the AD-3 shape: a documented code, a location and a detail code. It never carries error text or file content. Build warnings from errors with internal/warnx.