Skip to content

Commit

Permalink
escape command quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Dragun authored and rplevka committed Dec 7, 2022
1 parent 8226ca8 commit 442d894
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions broker/session.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import socket
import tempfile
from pathlib import Path
from logzero import logger
from ssh2.session import Session as ssh2_Session
Expand Down Expand Up @@ -200,6 +201,12 @@ def run(self, command, demux=True, **kwargs):
"""This is the container approximation of Session.run"""
kwargs.pop("timeout", None) # Timeouts are set at the client level
kwargs["demux"] = demux
if "'" in command:
with tempfile.NamedTemporaryFile(mode="w", suffix=".sh") as tmp:
tmp.write(command)
tmp.seek(0)
command = f"/bin/bash {tmp.name}"
self.sftp_write(tmp.name)
if any([s in command for s in "|&><"]):
# Containers don't handle pipes, redirects, etc well in a bare exec_run
command = f"/bin/bash -c '{command}'"
Expand Down

0 comments on commit 442d894

Please sign in to comment.