policy

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package policy validates that verb arguments do not contain shell metacharacters. Per SECURITY.md, coily's subprocess execution

Index

Examples

Constants

View Source
const ShellMeta = "`$;&|<>(){}\\\n\r\t"

ShellMeta is the set of bytes rejected in any string argument that could reach a subprocess. Exported so callers (and tests) can reason about it.

Variables

View Source
var ErrShellMeta = errors.New("policy: shell metacharacter rejected")

ErrShellMeta is returned by ValidateArg when value contains a byte in ShellMeta.

Functions

func ValidateArg

func ValidateArg(name, value string) error

ValidateArg rejects strings containing shell metacharacters. Empty strings are allowed. Callers should check for empty separately if the argument is

func ValidateArgSlice

func ValidateArgSlice(namePrefix string, values []string) error

ValidateArgSlice runs ValidateArg over a []string (for variadic / positional arguments). Uses a synthetic name that includes the index.

Example

Safe input: a positional argument with no shell metacharacters.

package main

import (
	"fmt"

	"github.com/coilysiren/cli-guard/policy"
)

func main() {
	err := policy.ValidateArgSlice("positional", []string{"hello", "world"})
	fmt.Println("err:", err)
}
Output:
err: <nil>
Example (Rejected)

Unsafe input: a shell metacharacter (`;`) in a positional argument is rejected before the value can reach `execve`.

package main

import (
	"fmt"

	"github.com/coilysiren/cli-guard/policy"
)

func main() {
	err := policy.ValidateArgSlice("a", []string{"x;y"})
	fmt.Println("rejected:", err != nil)
}
Output:
rejected: true

func ValidateArgs

func ValidateArgs(args map[string]string) error

ValidateArgs runs ValidateArg over a map, returning the first violation. Convenience for Action funcs that have already gathered flag values.

Types

This section is empty.

Jump to

Keyboard shortcuts

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