bash

package
v0.11.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package bash provides security classification for shell commands. Architecture ported from Claude Code's bashPermissions.ts + bashSecurity.ts: a validator chain where each validator returns allow | deny | ask | passthrough. The first non-passthrough result wins (deny-first semantics).

Validators run cheapest-first: empty check → incomplete detection → metacharacter scan → dangerous patterns → shell-specific checks.

Index

Constants

This section is empty.

Variables

View Source
var AllValidators = []Validator{
	validateEmpty,
	validateIncomplete,
	validateShellSyntax,
	validateShellMetacharacters,
	validateDangerousPatterns,
	validateZshDangerous,
	validateCommandSubstitution,
	validateNewlines,
	validateObfuscatedFlags,
	validateControlCharacters,
	validateUnicodeWhitespace,
	validateBraceExpansion,
}

AllValidators is the default validation chain, ordered cheapest-first.

View Source
var EnvVarSet = map[string]bool{
	"HOME": true, "USER": true, "PATH": true, "PWD": true,
	"LANG": true, "LC_ALL": true, "TERM": true, "SHELL": true,
	"EDITOR": true, "VISUAL": true, "NODE_ENV": true,
	"GOPATH": true, "GOROOT": true, "PYTHONPATH": true,
	"RUST_LOG": true, "DEBUG": true, "VERBOSE": true,
	"CLAUDE_CODE_": true, "OVERKILL_": true,
}

EnvVarSet is environment variables considered safe for prefix stripping.

Functions

This section is empty.

Types

type Behavior

type Behavior string

Behavior is the validator's recommended action.

const (
	Allow       Behavior = "allow"
	Deny        Behavior = "deny"
	Ask         Behavior = "ask"
	Passthrough Behavior = "passthrough"
)

type Result

type Result struct {
	Behavior Behavior
	Message  string
	Reason   string // machine-readable reason for logging/analytics
}

Result is a single validator's output.

func Validate

func Validate(command string) Result

Validate runs the full validator chain against the given command. Returns the first non-passthrough result (deny-first).

func ValidateWith

func ValidateWith(command string, validators []Validator) Result

ValidateWith runs a custom validator chain.

type ValidationCtx

type ValidationCtx struct {
	Command       string // original, as typed
	Trimmed       string // whitespace-trimmed
	BaseCommand   string // first word (the binary/program name)
	Unquoted      string // single-quote content preserved, double-quote content stripped
	FullyUnquoted string // all quote content removed
	HasTreeSitter bool   // true if AST-backed validation is available
}

ValidationCtx carries the parsed/derived forms of a shell command that validators examine.

func NewContext

func NewContext(command string) ValidationCtx

NewContext parses a raw command string into a ValidationCtx.

type Validator

type Validator func(ctx ValidationCtx) Result

Validator is a single security check function.

Jump to

Keyboard shortcuts

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