Skip to content

Commit fcd3d40

Browse files
committed
fix(serve): Invoke pip without shell in xgboost install_package
Replace the shell-interpreted, string-built pip command in install_package() with a list-argument subprocess call using sys.executable -m pip. This removes the shell=True pattern and prevents shell metacharacter interpretation in package_name as a defense-in-depth hardening against accidental misuse.
1 parent 3024a57 commit fcd3d40

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

‎sagemaker-serve/src/sagemaker/serve/model_server/torchserve/xgboost_inference.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import absolute_import
44
import os
55
import io
6+
import sys
67
import subprocess
78
import cloudpickle
89
import shutil
@@ -155,13 +156,10 @@ def _pickle_file_integrity_check():
155156

156157
def install_package(package_name, version=None):
157158
"""Placeholder docstring"""
158-
if version:
159-
command = f"pip install {package_name}=={version}"
160-
else:
161-
command = f"pip install {package_name}"
159+
package_spec = f"{package_name}=={version}" if version else package_name
162160

163161
try:
164-
subprocess.check_call(command, shell=True)
162+
subprocess.check_call([sys.executable, "-m", "pip", "install", package_spec])
165163
print(f"Successfully installed {package_name} using install_package")
166164
except subprocess.CalledProcessError as e:
167165
print(f"Failed to install {package_name}. Error: {e}")

0 commit comments

Comments
 (0)