Skip to content

Commit 3a3b7e7

Browse files
author
lindakladivova
committed
applying relevant github-advanced-security suggestions
1 parent 817795e commit 3a3b7e7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

python/grass/workflows/server.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import atexit
4949
import signal
5050
import sys
51+
import shutil
5152

5253

5354
class JupyterServerInstance:
@@ -112,7 +113,7 @@ def find_free_port():
112113
:return: A free port number (int).
113114
"""
114115
with socket.socket() as sock:
115-
sock.bind(("", 0))
116+
sock.bind(("127.0.0.1", 0))
116117
return sock.getsockname()[1]
117118

118119
def is_server_running(self, retries=10, delay=0.2):
@@ -183,6 +184,9 @@ def stop_server(self):
183184

184185
# Check if the process with the given PID is a Jupyter server
185186
try:
187+
ps_cmd = shutil.which("ps")
188+
if not ps_cmd:
189+
raise RuntimeError(_("Unable to find 'ps' command in PATH."))
186190
proc_name = (
187191
subprocess.check_output(["ps", "-p", str(self.pid), "-o", "args="])
188192
.decode()
@@ -200,6 +204,9 @@ def stop_server(self):
200204
# Attempt to terminate the server process
201205
if self.is_server_running(self.port):
202206
try:
207+
kill_cmd = shutil.which("kill")
208+
if not kill_cmd:
209+
raise RuntimeError(_("Unable to find 'kill' command in PATH."))
203210
subprocess.check_call(["kill", str(self.pid)])
204211
except subprocess.CalledProcessError as e:
205212
raise RuntimeError(

0 commit comments

Comments
 (0)