Expand description
JSON protocol types for communication between the terminal and script subprocesses.
Scripts read ScriptEvent objects from stdin (one JSON object per line) and write
ScriptCommand objects to stdout (one JSON object per line).
§Security Model
§Trust Assumptions
Scripts are user-configured subprocesses launched from ScriptConfig entries in
~/.config/par-term/config.yaml. The script binary is implicitly trusted (it was
placed there by the user). However, this trust must be bounded because:
- Supply-chain attacks: A malicious package could replace a trusted script with one that emits dangerous command payloads.
- Injection through event data: Malicious terminal sequences could produce events whose payloads are forwarded to the script, which could reflect them back in commands (terminal injection risk).
- Compromised scripts: A script may be modified after initial deployment.
§Command Categories
Script commands fall into three security categories:
§Safe Commands (no permission required)
Log: Write to the script’s output buffer (UI only)SetPanel/ClearPanel: Display markdown content in a panelNotify: Show a desktop notificationSetBadge: Set the tab badge textSetVariable: Set a user variable
§Restricted Commands (require permission flags)
These commands require explicit opt-in via ScriptConfig permission fields:
WriteText: Inject text into the PTY (requiresallow_write_text: true)- Must strip VT/ANSI escape sequences before writing
- Subject to rate limiting
RunCommand: Spawn an external process (requiresallow_run_command: true)- Must check against
check_command_denylist()from par-term-config - Must use shell tokenization (not
/bin/sh -c) to prevent metacharacter injection - Subject to rate limiting
- Must check against
ChangeConfig: Modify terminal configuration (requiresallow_change_config: true)- Must validate config keys against an allowlist
§Implementation Status
All commands are implemented:
Log,SetPanel,ClearPanel: Safe, always allowedNotify,SetBadge,SetVariable: Safe, always allowedWriteText: Requiresallow_write_text, rate-limited, VT sequences strippedRunCommand: Requiresallow_run_command, rate-limited, denylist-checked, tokenised without shell invocationChangeConfig: Requiresallow_change_config, allowlisted keys only
§Dispatcher Responsibility
The command dispatcher in src/app/window_manager/scripting.rs is responsible for:
- Checking
command.requires_permission()before executing restricted commands - Verifying the corresponding
ScriptConfig.allow_*flag is set - Applying rate limits, denylists, and input sanitization
See par-term-scripting/SECURITY.md for the complete security model.
Structs§
- Script
Event - An event sent from the terminal to a script subprocess (via stdin).
Enums§
- Script
Command - A command sent from a script subprocess to the terminal (via stdout).
- Script
Event Data - Event-specific payload data.
Functions§
- strip_
vt_ sequences - Strip VT/ANSI escape sequences from text before PTY injection.