policy

package
v0.0.0-...-a02776c Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package policy loads `.fendix.yaml` — the repo-committable policy file that lets AppSec teams pin Fendix's scan behavior in source control instead of via a long shell-script of CLI flags.

Precedence (lowest to highest):

  1. Cobra defaults (e.g. workers=10).
  2. Policy file values (set on Apply when the user did NOT pass the corresponding CLI flag).
  3. Explicit CLI flags (override policy file when present).

The policy file is intentionally a STRICT subset of the scan-flag surface: only the values teams reasonably want to commit are reflected here. One-shot flags like `--baseline`, `--save-baseline`, `--debug-bundle` are intentionally NOT in the schema — those are per-invocation runtime knobs, not policy.

Index

Constants

View Source
const DefaultPath = ".fendix.yaml"

DefaultPath is the canonical filename. Looked up from the scan command's working directory when --config is not passed and the file exists.

View Source
const SupportedVersion = 1

SupportedVersion is the policy-schema version this build understands. Newer files will be rejected to surface the upgrade requirement loudly rather than silently ignoring fields the binary doesn't know.

Variables

View Source
var (
	ErrUnsupportedVersion = errors.New("policy file version is not supported by this fendix build")
	ErrInvalidFailOn      = errors.New("policy.fail_on must be CRITICAL, HIGH, MEDIUM, LOW, or empty")
)

Errors from the policy layer.

Functions

This section is empty.

Types

type ApplyTo

type ApplyTo struct {
	SetFailOn        func(string)
	SetEnableActive  func(bool)
	SetWorkers       func(int)
	SetTimeoutSec    func(int)
	SetDelayMs       func(int)
	SetFormat        func(string)
	SetCrawlDepth    func(int)
	SetMaxEndpoints  func(int)
	SetWordlistPath  func(string)
	SetRespectRobots func(bool)
	SetMaxRequests   func(int64)
	SetMaxDuration   func(time.Duration)
	SetIgnorePath    func(string)
	SetAuthProfile   func(string)

	SetDeescalateTests   func(bool)
	SetEnforceConfidence func(bool)
}

ApplyTo writes the policy onto a ScanConfig-shaped target via a small per-field setter callback bag. The callbacks live in the scan command (or wherever ScanConfig is defined) so this package has no compile-time coupling to internal/models. Each setter is only invoked when the policy field is present AND the corresponding CLI flag is NOT in `cli`. Returns the number of fields written.

Setter callbacks are nil-safe — pass nil to skip a field (useful in tests that exercise only a subset of the schema).

func (ApplyTo) Run

func (a ApplyTo) Run(p *Policy, cli CLISet) int

Run applies p onto target via the setter callbacks, respecting CLI overrides. Returns the count of fields written. p == nil is a no-op (returns 0).

type AuthSection

type AuthSection struct {
	Profile string `yaml:"profile,omitempty"`
}

AuthSection points at a profile in ~/.fendix/profiles/. The literal secret value is intentionally NOT a field — committable policy must not contain credentials. A `profile` reference is fine because it expands at scan time against the user's local profiles dir.

type BudgetsSection

type BudgetsSection struct {
	MaxRequests *int64         `yaml:"max_requests,omitempty"`
	MaxDuration *time.Duration `yaml:"max_duration,omitempty"`
}

BudgetsSection covers the global request/duration soft caps from TASK-095. Teams gate CI runs on these to keep scan cost predictable.

type CLISet

type CLISet map[string]bool

CLISet declares which CLI flag names the user passed explicitly. Apply only writes a policy value to a ScanConfig field when the matching CLI flag is NOT in this set — that's how CLI overrides policy. Pass cobra's flag.Changed() result for each flag name.

func (CLISet) Has

func (s CLISet) Has(name string) bool

Has reports whether the named flag was explicitly set on the CLI. Nil-safe: a nil CLISet is treated as "no flags explicitly set", which makes the Policy fully apply (useful in tests).

type CrawlerSection

type CrawlerSection struct {
	CrawlDepth    *int   `yaml:"crawl_depth,omitempty"`
	MaxEndpoints  *int   `yaml:"max_endpoints,omitempty"`
	WordlistPath  string `yaml:"wordlist_path,omitempty"`
	RespectRobots *bool  `yaml:"respect_robots,omitempty"`
}

CrawlerSection covers endpoint discovery knobs that affect the scan surface and reliability. WordlistPath is a string (no pointer) — an empty path means "use the built-in CommonPaths" which matches the CLI flag's default behavior.

type Policy

type Policy struct {
	Version int    `yaml:"version"`
	FailOn  string `yaml:"fail_on,omitempty"`

	Scan    *ScanSection    `yaml:"scan,omitempty"`
	Crawler *CrawlerSection `yaml:"crawler,omitempty"`
	Budgets *BudgetsSection `yaml:"budgets,omitempty"`
	Auth    *AuthSection    `yaml:"auth,omitempty"`

	// IgnorePath maps to the `--ignore` CLI flag; teams typically
	// commit a `.fendix-ignore` alongside `.fendix.yaml` and want the
	// path explicit in the policy.
	IgnorePath string `yaml:"ignore_path,omitempty"`
}

Policy is the parsed `.fendix.yaml`. Pointer fields distinguish "explicitly set in the file" from "absent" — Apply only writes a value to ScanConfig when the field is present in the file AND the user didn't pass the corresponding CLI flag.

func Load

func Load(path string) (*Policy, error)

Load reads and parses a policy file. Returns nil if path is empty or the file does not exist (the latter is only an error when the caller passed --config explicitly; that condition is the caller's responsibility to surface). Returns ErrUnsupportedVersion when the file's version is greater than SupportedVersion or missing.

func (*Policy) Validate

func (p *Policy) Validate() error

Validate reports schema-level errors. Called by Load; exposed for tests and for the (future) `fendix validate-policy` subcommand.

type ScanSection

type ScanSection struct {
	EnableActive *bool   `yaml:"enable_active,omitempty"`
	Workers      *int    `yaml:"workers,omitempty"`
	TimeoutSec   *int    `yaml:"timeout,omitempty"`
	DelayMs      *int    `yaml:"delay_ms,omitempty"`
	Format       *string `yaml:"format,omitempty"`
	// DeescalateTests reports findings in test/fixture code as INFO rather
	// than WARN (v1.1 B3). Committable because "do we gate on test-code
	// findings?" is a team triage policy, not a per-invocation knob. Defaults
	// to the CLI default (true) when absent.
	DeescalateTests *bool `yaml:"deescalate_tests,omitempty"`
	// EnforceConfidence gates --fail-on on the deterministic confidence band
	// (v1.2.2 FIX-08). Committable for the same reason deescalate_tests is:
	// "how much corroboration do we demand before failing a build?" is a team
	// triage policy, not a per-invocation knob. Defaults to the CLI default
	// (true) when absent.
	EnforceConfidence *bool `yaml:"enforce_confidence,omitempty"`
}

ScanSection mirrors the scan-runtime knobs that make sense to commit. enable_active is a deliberate inclusion: teams that *want* active probing in CI shouldn't have to remember the flag every time. Per the safety contract, --enable-active still requires an explicit user/policy opt-in (default false).

Jump to

Keyboard shortcuts

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