CVE-2025-8022: bun vulnerable to OS Command Injection
8.8
Basic Information
Technical Details
Package Name | Ecosystem | Vulnerable Versions | First Patched Version |
---|---|---|---|
bun | npm | <= 1.1.39 |
Vulnerability Intelligence
Miggo AI
Root Cause Analysis
The vulnerability exists in the $
shell API of the bun
package. When a user provides input to the $
tagged template literal, the code attempts to sanitize it by escaping special characters. The process starts in shell.shellCmdFromJS
, which is the entry point from JavaScript. This function iterates through the parts of the template literal and passes the dynamic, user-controlled values to shell.handleTemplateValue
. For string values, handleTemplateValue
calls ShellSrcBuilder.appendJSValueStr
, which in turn relies on shell.needsEscapeUtf8AsciiLatin1
to determine if the string needs escaping. The vulnerability lies in the needsEscapeUtf8AsciiLatin1
function, specifically in the SPECIAL_CHARS
array it uses for checking. This array is missing the hyphen character (-
). As a result, if a user provides a string that starts with a hyphen, it is not identified as needing to be escaped and is concatenated directly into the command string. This allows an attacker to inject arbitrary command-line arguments, leading to OS command injection. The proof of concept demonstrates this by injecting the --upload-pack
argument into a git ls-remote
command.
Vulnerable functions
shell.shellCmdFromJS
src/shell/shell.zig
shell.handleTemplateValue
src/shell/shell.zig
shell.needsEscapeUtf8AsciiLatin1
src/shell/shell.zig