Skip to content

Commit 070b23a

Browse files
authored
Merge pull request #4675 from StackStorm/service_action_fix
Fix a possible shell command injection in the linux.service action
2 parents 63fe4d2 + 2c830c5 commit 070b23a

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ Fixed
3030
In such scenario, package / module was incorrectly loaded from Python 2 site-packages instead of
3131
Python 3 standard library which broke such packs. (bug fix) #4658 #4674
3232
* Remove policy-delayed status to avoid bouncing between delayed statuses. (bug fix) #4655
33+
* Fix a possible shell injection in the ``linux.service`` action. User who had access to run this
34+
action could cause a shell command injection by passing a compromised value for either the
35+
``service`` or ``action`` parameter. (bug fix) #4675
36+
37+
Reported by James Robinson (Netskope and Veracode).
3338

3439
3.0.0 - April 18, 2019
3540
----------------------

contrib/linux/actions/service.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,25 @@
2020
import platform
2121
import subprocess
2222

23+
from st2common.util.shell import quote_unix
24+
2325
distro = platform.linux_distribution()[0]
2426

25-
args = {'act': sys.argv[1], 'service': sys.argv[2]}
27+
if len(sys.argv) < 3:
28+
raise ValueError('Usage: service.py <action> <service>')
29+
30+
args = {'act': quote_unix(sys.argv[1]), 'service': quote_unix(sys.argv[2])}
2631

2732
if re.search(distro, 'Ubuntu'):
2833
if os.path.isfile("/etc/init/%s.conf" % args['service']):
29-
cmd = args['act'] + " " + args['service']
34+
cmd_args = ['service', args['service'], args['act']]
3035
elif os.path.isfile("/etc/init.d/%s" % args['service']):
31-
cmd = "/etc/init.d/%s %s" % (args['service'], args['act'])
36+
cmd_args = ['/etc/init.d/%s' % (args['service']), args['act']]
3237
else:
3338
print("Unknown service")
3439
sys.exit(2)
3540
elif re.search(distro, 'Redhat') or re.search(distro, 'Fedora') or \
3641
re.search(distro, 'CentOS Linux'):
37-
cmd = "systemctl %s %s" % (args['act'], args['service'])
42+
cmd_args = ['systemctl', args['act'], args['service']]
3843

39-
subprocess.call(cmd, shell=True)
44+
subprocess.call(cmd_args, shell=False)

contrib/linux/actions/service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
parameters:
88
act:
99
type: "string"
10-
description: "Action to perform on service"
10+
description: "Action to perform on service (e.g. start, stop, restart, etc.)"
1111
position: 0
1212
service:
1313
type: "string"

0 commit comments

Comments
 (0)