Help us shape the future of Go! Take the 2026 Go Developer Survey

remediate

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package remediate turns findings into actionable guidance: how urgent it is, how to rotate the credential, how to stop needing it at all (keyless / workload identity), and how to load it efficiently in the file's language.

Index

Constants

This section is empty.

Variables

View Source
var Caveats = map[string]string{
	"go":         `os.Getenv returns "" when the variable is unset; validate required values at startup`,
	"javascript": "the lookup throws \"X is not set\" when the variable is unset (fail-fast)",
	"typescript": "the lookup throws \"X is not set\" when the variable is unset (fail-fast)",
	"python":     `os.environ["X"] raises KeyError when unset (fail-fast); module-level lookups fail at import`,
	"java":       "Objects.requireNonNull throws \"X is not set\" when unset (fail-fast); static fields fail at class load",
	"csharp":     "the lookup throws InvalidOperationException when unset (fail-fast)",
	"ruby":       "ENV.fetch raises KeyError when unset (fail-fast)",
	"php":        "getenv returns false when unset; validate required values at startup",
	"shell":      `"${X:?}" aborts the script when X is unset (fail-fast)`,
}

Caveats are semantic notes about the env-lookup replacement per language.

View Source
var Stores = []string{"env", "vault", "aws", "azure", "gcp"}

Stores supported by snippets.

Functions

func EnvExpr

func EnvExpr(lang, env string) string

EnvExpr is a drop-in expression reading an env var in the language.

func EnvName

func EnvName(ruleID, line, secret string, fam Family) string

EnvName picks a variable name: the conventional one for the rule, else the identifier the literal was assigned to, else one derived from the rule.

func LanguageFor

func LanguageFor(path string) string

LanguageFor maps a file name to a snippet language.

func Languages

func Languages() []string

Languages lists languages with snippets.

func Snippet

func Snippet(lang, store, env string) (string, bool)

Snippet returns a code pattern for loading the secret in lang from store. Patterns follow the same rules: one shared client, fetch at startup or on first use, cache in memory with a TTL shorter than the rotation period, refetch once on an auth failure, never log the value.

func Validate

func Validate(lang, content string) (checked bool, err error)

Validate checks that rewritten source still parses. checked is false when no validator is available for the language (the change is then flagged for manual review rather than trusted).

Types

type Family

type Family struct {
	Name      string
	Rotate    string
	Eliminate string
	EnvVar    string
	// SDKChain: the official SDK resolves credentials itself (AWS/Azure/GCP),
	// so the right fix is deleting the literal, not reading an env var.
	SDKChain bool
}

Family describes one credential issuer.

func FamilyFor

func FamilyFor(ruleID string) Family

FamilyFor returns the issuer family for a rule ID.

type Guidance

type Guidance struct {
	Urgency   string   `json:"Urgency"`             // revoke-now | rotate | review
	Family    string   `json:"Family"`              // provider family, e.g. "AWS"
	Rotate    string   `json:"Rotate"`              // how to revoke/rotate
	Eliminate string   `json:"Eliminate,omitempty"` // how to stop needing a static secret
	EnvVar    string   `json:"EnvVar"`              // suggested variable / secret name
	Language  string   `json:"Language,omitempty"`  // detected from the file
	Replace   string   `json:"Replace,omitempty"`   // drop-in expression replacing the literal
	Store     string   `json:"Store,omitempty"`     // secret store the snippet targets
	Steps     []string `json:"Steps,omitempty"`     // ordered checklist
	Runbook   string   `json:"Runbook,omitempty"`   // org runbook link from config
}

Guidance is attached to every finding.

func For

func For(in Input) Guidance

For builds guidance for one finding.

type Input

type Input struct {
	RuleID, File, Line, Secret, Verification string
	Store, Runbook                           string // org defaults from config/flags
}

Input is what guidance needs about a finding.

type PatchItem

type PatchItem struct {
	File   string // relative to Root
	Line   int    // 1-based
	Secret string
	EnvVar string
}

PatchItem is one literal to replace.

type PatchResult

type PatchResult struct {
	Diff    string
	Patched []PatchItem
	Skipped []string          // human-readable reasons
	EnvVars []string          // variables the patched code now expects
	Files   map[string]string // new content per file (for in-place --fix)
	// Unchecked lists files whose language has no syntax validator here.
	Unchecked []string
	Langs     []string // languages touched (for caveats)
}

PatchResult is a unified diff plus what could not be patched.

func BuildPatch

func BuildPatch(root string, items []PatchItem) PatchResult

BuildPatch replaces each quoted secret literal with an environment lookup in the file's language and returns a unified diff for `git apply`. Unquoted values (YAML, .env, properties) are reported as skipped: they need moving to a secret store rather than a code change.

Jump to

Keyboard shortcuts

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