Skip to content

Commit

Permalink
attempting to fix security flaw (issue #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
thanethomson committed Nov 7, 2017
1 parent 5736ec6 commit bc79575
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mlalchemy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def parse_yaml_query(yaml_content):
On success, the processed MLQuery object.
"""
logger.debug("Attempting to parse YAML content:\n%s" % yaml_content)
return parse_query(yaml.load(yaml_content))
return parse_query(yaml.safe_load(yaml_content))


def parse_json_query(json_content):
Expand Down
21 changes: 21 additions & 0 deletions tests/test_yaml_security.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

import unittest
import yaml

from mlalchemy import *
from mlalchemy.testing import MLAlchemyTestCase


class TestYamlSecurity(MLAlchemyTestCase):

def test_basic_yaml_security(self):
with self.assertRaises(yaml.constructor.ConstructorError):
parse_yaml_query('!!python/object/apply:os.system ["echo Hello"]')


if __name__ == "__main__":
unittest.main()

0 comments on commit bc79575

Please sign in to comment.