Skip to content

Commit f9fd2d4

Browse files
hush-husharbll
authored andcommitted
Use safe_load instead of load from PyYaml
PyYAML 'load()' method could execute arbitrary code. We now use 'safe_load' everywhere to avoid it.
1 parent e9e7fcd commit f9fd2d4

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

checks/check_status.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ def get_jmx_status():
896896
check_data = defaultdict(lambda: defaultdict(list))
897897
try:
898898
if os.path.exists(java_status_path):
899-
java_jmx_stats = yaml.load(file(java_status_path))
899+
java_jmx_stats = yaml.safe_load(file(java_status_path))
900900

901901
status_age = time.time() - java_jmx_stats.get('timestamp')/1000 # JMX timestamp is saved in milliseconds
902902
jmx_checks = java_jmx_stats.get('checks', {})
@@ -941,7 +941,7 @@ def get_jmx_status():
941941
check_statuses.append(check_status)
942942

943943
if os.path.exists(python_status_path):
944-
python_jmx_stats = yaml.load(file(python_status_path))
944+
python_jmx_stats = yaml.safe_load(file(python_status_path))
945945
jmx_checks = python_jmx_stats.get('invalid_checks', {})
946946
for check_name, excep in jmx_checks.iteritems():
947947
check_statuses.append(CheckStatus(check_name, [], init_failed_error=excep))

util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
# 3p
1212
import yaml # noqa, let's guess, probably imported somewhere
1313
try:
14-
from yaml import CLoader as yLoader
15-
from yaml import CDumper as yDumper
14+
from yaml import CSafeLoader as yLoader
15+
from yaml import CSafeDumper as yDumper
1616
except ImportError:
1717
# On source install C Extensions might have not been built
18-
from yaml import Loader as yLoader # noqa, imported from here elsewhere
19-
from yaml import Dumper as yDumper # noqa, imported from here elsewhere
18+
from yaml import SafeLoader as yLoader # noqa, imported from here elsewhere
19+
from yaml import SafeDumper as yDumper # noqa, imported from here elsewhere
2020

2121
# These classes are now in utils/, they are just here for compatibility reasons,
2222
# if a user actually uses them in a custom check

utils/jmx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,6 @@ def get_jmx_appnames(cls):
146146
check_names = []
147147
jmx_status_path = os.path.join(cls._get_dir(), cls._STATUS_FILE)
148148
if os.path.exists(jmx_status_path):
149-
jmx_checks = yaml.load(file(jmx_status_path)).get('checks', {})
149+
jmx_checks = yaml.safe_load(file(jmx_status_path)).get('checks', {})
150150
check_names = [name for name in jmx_checks.get('initialized_checks', {}).iterkeys()]
151151
return check_names

0 commit comments

Comments
 (0)