shell

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: Apache-2.0 Imports: 8 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 shell decides what the exec node is permitted to run.

This exists because of what the exec node is. Node-RED's threat model is that anyone who can deploy a flow already owns the box, and the exec node is the proof: it runs an arbitrary command line through a shell. That model held when Node-RED was a thing you ran on your own Pi. It does not hold for an App Store app on a customer's plant floor, where the editor is reachable by anyone with a dashboard login, and it is the mechanism behind CVE-2025-41656 — unauthenticated remote code execution against a default Node-RED, achieved by deploying a flow with an exec node in it.

So the node ships disabled, an operator has to name the commands it may run, and there is no shell. Those three together mean a flow author cannot turn "can edit a flow" into "can run anything", which is the property that makes the node shippable at all.

Index

Constants

This section is empty.

Variables

View Source
var ErrDisabled = fmt.Errorf("the exec node is disabled; enable it and list the " +
	"commands a flow may run")

ErrDisabled is returned when the exec node is switched off.

Functions

func SplitArgs

func SplitArgs(line string) ([]string, error)

SplitArgs splits a command line into arguments the way a shell would, honouring single quotes, double quotes and backslash escapes — and nothing else.

Deliberately not a shell. There is no expansion, no substitution, no globbing, no pipes and no operators, because every one of those is a way to turn one allowed command into an arbitrary one. A command line containing an unquoted shell metacharacter is refused rather than being run with the character taken literally, since a flow author who typed it plainly expected it to do something.

Types

type ErrNotAllowed

type ErrNotAllowed struct {
	Command string
	Allowed []string
}

ErrNotAllowed is returned for a command outside the allowlist.

func (*ErrNotAllowed) Error

func (e *ErrNotAllowed) Error() string

type Policy

type Policy struct {
	// contains filtered or unexported fields
}

Policy is the allowlist the exec node is checked against.

func NewPolicy

func NewPolicy(enabled bool, commands []string) (*Policy, error)

NewPolicy builds a policy from the configuration.

An enabled policy with no commands is an error rather than "anything". The permissive reading of an empty list is how a deliberately narrow capability becomes a general-purpose shell, and it would be the single worst default in this codebase.

func (*Policy) Allowed

func (p *Policy) Allowed() []string

Allowed lists the configured commands, for the error message when one is refused. Sorted, so the message is the same every time.

func (*Policy) Enabled

func (p *Policy) Enabled() bool

Enabled reports whether the exec node may run anything at all.

func (*Policy) Resolve

func (p *Policy) Resolve(command string) (string, error)

Resolve checks a command and returns the absolute path to execute.

The comparison is on the resolved absolute path, not on the string the flow typed. Comparing strings would let a flow name "curl" and get whichever curl happens to be first on the PATH of the process — and PATH is something a Function node can read and a sidecar can influence. Resolving first means the allowlist names a file on disk, which is the thing an operator thought they were allowing.

func (*Policy) Unresolved

func (p *Policy) Unresolved() []string

Unresolved lists allowed commands that were not found on the PATH at startup, so the operator can be told at boot rather than at the first message.

Jump to

Keyboard shortcuts

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