Skip to content
This repository was archived by the owner on May 17, 2025. It is now read-only.

Commit bc79575

Browse files
committed
attempting to fix security flaw (issue #1)
1 parent 5736ec6 commit bc79575

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

mlalchemy/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def parse_yaml_query(yaml_content):
3333
On success, the processed MLQuery object.
3434
"""
3535
logger.debug("Attempting to parse YAML content:\n%s" % yaml_content)
36-
return parse_query(yaml.load(yaml_content))
36+
return parse_query(yaml.safe_load(yaml_content))
3737

3838

3939
def parse_json_query(json_content):

tests/test_yaml_security.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from __future__ import unicode_literals
4+
5+
import unittest
6+
import yaml
7+
8+
from mlalchemy import *
9+
from mlalchemy.testing import MLAlchemyTestCase
10+
11+
12+
class TestYamlSecurity(MLAlchemyTestCase):
13+
14+
def test_basic_yaml_security(self):
15+
with self.assertRaises(yaml.constructor.ConstructorError):
16+
parse_yaml_query('!!python/object/apply:os.system ["echo Hello"]')
17+
18+
19+
if __name__ == "__main__":
20+
unittest.main()
21+

0 commit comments

Comments
 (0)