execnode

package
v0.0.0-...-0c19b3a Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package execnode provides the Exec node implementation (Node-RED type ID "exec" - named execnode here to avoid shadowing the imported stdlib os/exec package within this file).

Security

This node runs an external command with the same OS privileges as the Go-RED process. Anyone able to deploy a flow that uses it can therefore run arbitrary commands on the host - this is inherent to the feature (Node-RED's own exec node has the identical property) and cannot be fully engineered away, only its sharpest edges blunted:

  • Command is fixed at deploy time via node configuration and is never read from the message; a compromised or malicious upstream node in the same flow cannot redirect execution to a different binary.
  • Arguments are always passed as a Go argv slice via exec.CommandContext(ctx, Command, args...), never through a shell (no "sh -c", unlike Node-RED's default useSpawn=false mode). Nothing in Args or in msg.payload (if AppendPayload is set) is ever interpreted for shell metacharacters (;, |, $(), backticks, ...), because there is no shell in the path at all.
  • Every run is bounded by TimeoutMs and by a fixed cap on captured stdout/stderr bytes, so a runaway or wedged command can't hang a node indefinitely or exhaust memory.
  • The node refuses to run at all unless the enableEnvVar environment variable is set on the Go-RED process - an explicit, instance-level opt-in, not just something gated by editor/API auth. A fresh Go-RED deployment cannot execute commands by accident.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	// Command is the executable name or path. Fixed at deploy time - never
	// taken from the message. Required.
	Command string
	// Args are fixed extra arguments, in order, before any AppendPayload
	// arguments.
	Args []string
	// AppendPayload, if true, appends msg.payload - which must be a string
	// or an array of strings - as trailing argv entries.
	AppendPayload bool
	// TimeoutMs bounds how long the command may run.
	TimeoutMs int64
}

Node holds an Exec node's configuration.

func (*Node) Execute

func (n *Node) Execute(ctx interface{}, input map[string]interface{}) (map[string]interface{}, error)

Execute runs Command with Args (+ msg.payload if AppendPayload), and returns a copy of input with payload set to captured stdout, "stderr" set to captured stderr, and "exitCode" set to the process's exit code.

func (*Node) GetConfig

func (n *Node) GetConfig() map[string]interface{}

func (*Node) SetConfig

func (n *Node) SetConfig(config map[string]interface{}) error

func (*Node) Validate

func (n *Node) Validate() error

Jump to

Keyboard shortcuts

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