security: use create_subprocess_exec instead of create_subprocess_shell#1220
Open
kolega-ai-dev wants to merge 1 commit intobentoml:mainfrom
Open
security: use create_subprocess_exec instead of create_subprocess_shell#1220kolega-ai-dev wants to merge 1 commit intobentoml:mainfrom
kolega-ai-dev wants to merge 1 commit intobentoml:mainfrom
Conversation
async_run_command used create_subprocess_shell with string concatenation, which bypasses the safety of list-based argument passing. Replaced with create_subprocess_exec to pass arguments as a list directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vulnerability identified and fix provided by Kolega.dev
Command Injection via Shell String Concatenation in async_run_command
Location
src/openllm/common.py:425-426Description
The
async_run_commandfunction usesasyncio.create_subprocess_shellwith' '.join(map(str, cmd))at line 426, which is a dangerous pattern. Whileshlexis imported,shlex.quote()is not applied to the joined command. Thecmdlist is constructed from: (1)bentoml_tagderived from filesystem paths, (2)portas an integer, and (3)cli_argsfrom user CLI input. Usingcreate_subprocess_shellwith string concatenation bypasses the safety of list-based argument passing and can allow shell metacharacter injection.Analysis Notes
The synchronous
run_commandfunction correctly usessubprocess.runwith a list of arguments. However, the async counterpartasync_run_commandconcatenates arguments into a single shell string, which is an inconsistent and insecure pattern. While this is a local CLI tool with a limited practical attack surface, the pattern is objectively wrong and should be corrected.Fix Applied
Replaced
asyncio.create_subprocess_shellwithasyncio.create_subprocess_exec, passing*cmdas positional arguments instead of joining them into a shell string. This matches the secure pattern already used by the synchronousrun_commandfunction and eliminates any possibility of shell metacharacter injection.Tests/Linters Ran
1 file already formattedafter auto-format)F401warning for unusedtyper.coreimport (not introduced by this change, verified against main branch)dependency-groups.testsis defined inpyproject.tomlbut no test files exist)Contribution Notes
DEVELOPMENT.md