plugin

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: 15 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 plugin discovers and runs out-of-tree Fendix plugins.

A plugin is a directory containing a plugin.yaml manifest and an executable entrypoint. The engine invokes the entrypoint with a JSON ScanRequest on stdin; the entrypoint emits zero or more newline-delimited Finding JSON objects on stdout, terminated by {"done": true, "total": N}. This is the same NDJSON contract the embedded Python engine speaks (ADR-002), so plugin authors writing a Python plugin can share most of the engine.py scaffolding.

Discovery walks two roots in order:

  1. <repo>/.fendix/plugins/ (repo-local; OPT-IN — see below)
  2. ~/.fendix/plugins/ (user-global; trusted)

On collision (same plugin name in both roots) the repo-local version wins, so a project can pin a specific plugin version without affecting the developer's other repos.

Repo-local plugins are NOT auto-discovered by default (F-H2): a repository under scan is attacker-controlled in the poisoned- pipeline threat model (a malicious PR can drop a `.fendix/plugins/` directory and get arbitrary code executed in CI). The repo-local root is therefore gated behind explicit opt-in (the AllowRepoLocalPlugins config flag, threaded into Roots). The user-global ~/.fendix/plugins root the operator populated by hand stays trusted and is always searched.

Index

Constants

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout caps a single plugin invocation when the manifest does not specify a Timeout.

View Source
const MaxTimeout = 5 * time.Minute

MaxTimeout is the upper bound on plugin runtime regardless of what the manifest claims. A plugin that wants longer scans should run async and emit findings incrementally; the engine cannot wait forever on a single subprocess.

Variables

This section is empty.

Functions

func DefaultRoots

func DefaultRoots(cwd string, allowRepoLocal bool) []string

DefaultRoots returns the canonical plugin search path. The user-global root (~/.fendix/plugins) is always included — the operator populated it by hand, so it's trusted. The repo-local root (<cwd>/.fendix/plugins) is included only when allowRepoLocal is true (F-H2): the scanned repo is attacker-controlled in the poisoned- pipeline threat model, so a `.fendix/plugins/` committed by a hostile PR must not auto-execute in CI. When repo-local is allowed, it's listed first so it shadows a same-named user-global plugin.

cwd is the working directory whose .fendix/plugins should be searched (typically the scan root). If cwd is empty, the repo-local root is omitted regardless of allowRepoLocal. On systems where os.UserHomeDir fails (very rare) the user-global root is silently omitted.

Types

type Mode

type Mode string

Mode declares whether a plugin sees blackbox (URL/spec/auth) or whitebox (code path) inputs. Plugins that need both can declare Mode="hybrid"; the orchestrator will run them once with all fields populated.

const (
	ModeBlackbox Mode = "blackbox"
	ModeWhitebox Mode = "whitebox"
	ModeHybrid   Mode = "hybrid"
)

type Plugin

type Plugin struct {
	Spec
	// Dir is the absolute path to the plugin directory. Entrypoint
	// is resolved relative to Dir.
	Dir string
}

Plugin is a discovered, validated plugin ready to run.

func Discover

func Discover(roots []string) ([]Plugin, error)

Discover walks the given roots in order, parses every plugin.yaml it finds, and returns the resulting Plugin list deduplicated by Name (earlier roots win — pass repo-local first, user-global second; see DefaultRoots). A malformed plugin.yaml in one directory does not stop discovery in others; the error for that directory is logged at WARN level and the plugin is skipped.

Symlinked plugin *directories* are skipped (F-H2): following a symlink lets a directory entry point outside the discovery root — a poisoned repo could symlink its `.fendix/plugins/x` at an attacker-staged tree, and an operator's `~/.fendix/plugins/y` could be redirected by a hostile package. Only real directories are discovered; copy (or `git clone`) a plugin into the root rather than symlinking it.

Discover is intentionally tolerant of missing roots: a fresh install with no plugin directories returns ([], nil), not an error.

func LoadPlugin

func LoadPlugin(dir string) (Plugin, error)

LoadPlugin parses plugin.yaml under dir and validates the result. Exported wrapper around loadPlugin so the `fendix plugins install` subcommand (internal/pluginscmd, TASK-130) can validate a freshly- cloned tree without re-implementing the manifest parser.

func (Plugin) Run

func (p Plugin) Run(ctx context.Context, req ScanRequest) ([]models.Finding, error)

Run invokes the plugin entrypoint and returns the findings it emitted. A plugin that exits with non-zero status, takes longer than its timeout, or emits a {"error": ...} terminator returns an error; partial findings collected before the failure are preserved in the slice.

Findings emitted without a Source field are tagged with the plugin's Mode so downstream correlation/dedup treats them consistently with the embedded engines.

type ScanRequest

type ScanRequest struct {
	Mode       Mode     `json:"mode"`
	URL        string   `json:"url,omitempty"`
	Spec       string   `json:"spec,omitempty"`
	CodePath   string   `json:"code_path,omitempty"`
	Auth       string   `json:"auth,omitempty"`
	AuthType   string   `json:"auth_type,omitempty"`
	Categories []string `json:"categories,omitempty"`
	Verbose    bool     `json:"verbose"`
}

ScanRequest is the JSON payload the engine sends to a plugin's stdin. It mirrors the embedded engine's ScanRequest plus a Categories field so plugins can filter to relevant work without re-walking the source tree. Field names are stable — adding new fields is fine, removing or renaming them is a breaking change.

type Spec

type Spec struct {
	Name        string        `yaml:"name"`
	Version     string        `yaml:"version,omitempty"`
	Description string        `yaml:"description,omitempty"`
	Entrypoint  string        `yaml:"entrypoint"`
	Mode        Mode          `yaml:"mode"`
	Categories  []string      `yaml:"categories,omitempty"`
	Timeout     time.Duration `yaml:"timeout,omitempty"`
	// Env is an optional allowlist of extra environment variable names
	// the plugin needs passed through from the operator's environment
	// (F-I1). By default the runner inherits only a minimal fixed
	// allowlist (PATH, HOME, LANG/LC_*, TMPDIR) plus the FENDIX_PLUGIN_*
	// vars it sets; a plugin that needs, say, a corporate proxy var can
	// name it here. This is the plugin author *requesting* a var — it
	// does not grant access the operator hasn't already exported.
	// Backwards-compatible: omitting it preserves the minimal default.
	Env []string `yaml:"env,omitempty"`
}

Spec is the on-disk plugin.yaml schema. Unknown fields are rejected (yaml.Decoder.KnownFields(true)) so typos surface as errors rather than silently-ignored config — same posture as .fendix.yaml in policy.Load.

Jump to

Keyboard shortcuts

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