recipe

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package recipe builds declarative HTTP modules. The common bearer/basic whoami-plus-counts credential becomes a small data value; recipe.HTTP{...} .Module() returns a module.Module that the registry can hold alongside the hand-written exotic-signing modules.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsafeBase = errors.New("recipe: refused unsafe base URL")

ErrUnsafeBase is returned when a templated base URL would resolve somewhere the module did not intend.

Functions

This section is empty.

Types

type AuthKind

type AuthKind int

AuthKind selects how the credential is attached to each request.

const (
	// Bearer sets "Authorization: Bearer <token>".
	Bearer AuthKind = iota
	// BasicKeyUser sets HTTP Basic with the token as username, empty password
	// (Stripe, Twilio-style).
	BasicKeyUser
	// Basic uses Fields[UserField]:Fields[PassField] as HTTP Basic.
	Basic
	// Header sets a custom header (HeaderName) to ValuePrefix+token.
	Header
	// PreAuthed means Authenticate already produced a bearer Token; attach it.
	PreAuthed
	// None attaches no auth (token is in the URL or in static Headers).
	None
)

type AuthSpec

type AuthSpec struct {
	Kind        AuthKind
	HeaderName  string // for Header
	ValuePrefix string // for Header (e.g. "token ", "SSWS ")
	UserField   string // for Basic
	PassField   string // for Basic
	TokenField  string // Fields key holding the secret; defaults to "token"
	// RawAuth, with PreAuthed, sets Authorization to ValuePrefix+token instead of
	// the default "Bearer " scheme (e.g. CyberArk PVWA's raw session token).
	RawAuth bool
}

AuthSpec describes request authentication.

type Call

type Call struct {
	Method       string // default GET
	Path         string // appended to Base; may template {field}
	Accept       string
	ReadOnlyPOST bool
	Body         string
	Fields       []Extract
	Count        *CountSpec
	Signals      []Signal
	Optional     bool // a failure here doesn't abort the whole recon
}

Call is one read-only request in a recipe.

func GET

func GET(path string) Call

GET is a convenience constructor.

func (Call) CountArray

func (c Call) CountArray(path, key string) Call

CountArray counts the length of a JSON array at path.

func (Call) CountArrayFlag

func (c Call) CountArrayFlag(path, key string, fl module.FlagLevel) Call

CountArrayFlag is like CountArray with a flag level.

func (Call) CountFlag

func (c Call) CountFlag(path, key string, fl module.FlagLevel) Call

CountFlag is like CountFrom but tags the count with a flag level (e.g. to mark access to a PII or data-store resource).

func (Call) CountFrom

func (c Call) CountFrom(path, key string) Call

CountFrom adds a count extraction from a numeric JSON path.

func (Call) Field

func (c Call) Field(key, path string) Call

Field adds a labeled extraction (builder style).

func (Call) FlagField

func (c Call) FlagField(key, path string, fl module.FlagLevel) Call

FlagField adds a labeled extraction carrying a flag level.

func (Call) Signal

func (c Call) Signal(s Signal) Call

Signal adds a flag-raising signal (builder style).

type CountSpec

type CountSpec struct {
	Key          string
	Path         string // count = numeric value at path, or array length at path
	ArrayLen     bool   // treat Path as an array and use its length
	FromLinkLast bool   // parse Link rel="last" page number from the response
	Flag         module.FlagLevel
}

CountSpec sizes blast radius cheaply.

type Extract

type Extract struct {
	Key  string
	Path string // dotted JSON path
	Flag module.FlagLevel
}

Extract pulls a labeled value out of a JSON response body.

type HTTP

type HTTP struct {
	Rule       string            // gitleaks rule id (routing); may be empty for custom-recognized
	ModuleName string            // overrides the module name (defaults to Rule)
	Base       string            // base URL, may template {field}
	Accept     string            // default Accept header for all calls
	Headers    map[string]string // static extra headers on every request
	Auth       AuthSpec
	Whoami     Call
	Calls      []Call // additional inventory/count calls
	// Endpoint declares where this module's credential may legitimately be sent.
	// Required for any spec whose Base is templated on a URL-valued field; the
	// catalog guard test fails without it. See module.EndpointPolicy.
	Endpoint module.EndpointPolicy
	// MultiScope marks an API where the whoami can 401 for a token that is still
	// live against a different scope (e.g. Cloudflare's user-scoped
	// /user/tokens/verify rejects an account/zone-scoped token). For these we keep
	// probing the other calls after a whoami 401 instead of stopping early, so a
	// scoped-but-live key isn't falsely declared DEAD. Default off preserves the
	// OPSEC early-stop for single-scope APIs.
	MultiScope bool
	// TitlePrefix is shown before the redacted key in the note title.
	TitlePrefix string
	// Summarize, if set, produces the one-line takeaway from findings.
	Summarize func([]module.Finding) string
	// Authenticate, if set, runs the optional headless token exchange before
	// recon; its Token is attached when Auth.Kind == PreAuthed.
	Authenticate func(ctx context.Context, c *recon.Client, f module.Fields) (module.Token, error)
	// Static findings are appended unconditionally (e.g. "scopes not
	// introspectable read-only" for restricted keys).
	Static []module.Finding
	// Harvest, if set, extracts downstream secret values for recursive triage.
	// The pipeline only invokes it under --live --intrusive within the bounded
	// recursion budget; implementations must self-gate on c.Live()/c.Intrusive().
	Harvest func(ctx context.Context, c *recon.Client, t module.Token, f module.Fields) ([]module.Harvested, error)
}

HTTP is a declarative module specification.

func (HTTP) Module

func (h HTTP) Module() module.Module

Module materializes the spec into a module.Module.

type Signal

type Signal struct {
	Path     string // JSON path to inspect (string or joined array)
	Contains string // substring trigger
	Regex    string // regex trigger (alternative to Contains)
	Key      string // finding key to emit
	Value    string // finding value (defaults to the matched field value)
	Flag     module.FlagLevel
}

Signal raises a flag when a response field contains/matches something.

Jump to

Keyboard shortcuts

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