Summary
protobufjs-cli's pbts command previously constructed a shell command string from user-supplied file paths and executed it with child_process.exec, allowing shell metacharacters in paths to be interpreted by the shell.
An attacker who can influence or control the input file paths passed to pbts could inject additional commands, leading to arbitrary OS command execution under the privileges of the invoking user.
Affected context
This vulnerability affects workflows that use protobufjs-cli's pbts tool to generate TypeScript definitions, particularly when file paths are derived from external or user-controlled input.
The issue arises when:
pbtsis invoked in build or generation scripts with file paths that may contain untrusted content, and- Those paths are passed into
pbtsversions that construct a shell command string and execute it viachild_process.exec.
It is most relevant in CI/CD pipelines, code generation services, or build tools that automatically discover or accept user-specified .proto files and then invoke pbts.
Exploit preconditions
- Attack surface: The
pbtsCLI command inprotobufjs-cliinvoked as part of local builds, CI/CD pipelines, or automated code generation. - Required access: Ability to supply or influence the input file paths used as arguments to
pbts(e.g., by controlling proto filenames, directories, command-line arguments, or configuration used to build the command). - Trigger point: Execution of
pbtsthat internally constructs a shell command and passes it tochild_process.execto run JSDoc. - Why exploitation is possible: File paths are interpolated into a shell command string without proper escaping or bypassing the shell; shell metacharacters (such as
;,&,|, backticks, or$()) within the path are interpreted by the shell as separate commands or operators rather than as literal characters.
Why this happens
The root cause is the construction of shell commands from untrusted data and their execution via a shell interpreter, mapping directly to CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
Instead of invoking JSDoc using an argument-based API (e.g., child_process.spawn/execFile with an array of arguments), pbts concatenated input file paths into a command string and called child_process.exec. This pattern inherently trusts the content of file paths and fails to neutralize shell metacharacters.
As a result, any attacker-controlled input embedded in the command string can break out of the intended argument context and inject arbitrary shell commands that execute with the same permissions as the process running pbts.
Potential impact
- Execution of arbitrary OS commands in the environment where
pbtsruns (developer workstation, build server, CI agent). - Compromise of CI/CD pipelines, including the ability to exfiltrate credentials, tokens, or other secrets available to the build process.
- Unauthorized modification of generated artifacts, source trees, or build outputs.
- Lateral movement within the developer or build infrastructure through abuse of the compromised process's network and filesystem access.
- Planting of backdoors or malicious code into generated or packaged artifacts, contributing to software supply-chain compromise.
General mitigation guidance
Effective mitigation centers on eliminating direct shell invocation with untrusted input and strictly separating data from command interpretation:
- Prefer process-spawning APIs that do not invoke a shell, such as
child_process.spawn,spawnSync, orexecFile, passing arguments as arrays so they are not parsed by a shell. - Avoid building command strings via concatenation or interpolation of file paths; treat file paths as data-only and let the OS handle them as discrete arguments.
- Normalize and validate file paths before use, limiting to expected character sets and directory scopes to reduce the risk from unexpected metacharacters or traversal.
- Run build and code-generation processes with least privilege, without unnecessary network or secret access, to limit impact if a similar issue arises.
- Apply the same secure patterns in custom scripts or wrappers around
pbtsand other CLI tools, ensuring that any tool invocation that uses untrusted input never passes through a shell when avoidable.
How teams detect issues like this
Detection can focus on both code patterns and runtime behavior:
- Static analysis: Configure rules to flag usages of
child_process.exec(and similar shell-invoking APIs) where command strings are constructed via concatenation or template literals that include variables derived from user input, file names, or environment variables. - Code review: In build tooling, CLIs, and scripts, look specifically for patterns where:
- Command strings are manually assembled (e.g.,
"jsdoc " + filePath), - File system input or configuration drives command construction, or
- Shell metacharacters are not explicitly rejected or escaped.
- Secure coding policies: Establish guidelines and linting rules that disallow shell-based command construction in build pipelines and enforce argument-array process invocation.
- Runtime monitoring: On CI/CD infrastructure, monitor for unexpected outbound connections, anomalous process trees (e.g., shell processes spawned from
nodebuild processes), and unusual file modifications during code generation steps. - Automated review tools and CI-integrated scanners that understand Node.js patterns can help surface risky
child_processusage before it reaches production workflows.

