CVE-2017-2809 (published 2017-09-14T19:29Z)

An exploitable vulnerability exists in the yaml loading functionality of ansible-vault before 1.0.5. A specially crafted vault can execute arbitrary python commands resulting in command execution. An attacker can insert python into the vault to trigger this vulnerability.

Severity: MEDIUM
CVSS v2 base score: 6.8 (AV:N/AC:M/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 7.8, HIGH (CVSS:3.0/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-94
cwe_name: Improper Control of Generation of Code ('Code Injection')
description: The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
extended_description: 
            When a product allows a user's input to contain code syntax, it might be possible for an attacker to craft the code in such a way that it will alter the intended control flow of the product. Such an alteration could lead to arbitrary code execution.
            Injection problems encompass a wide variety of issues -- all mitigated in very different ways. For this reason, the most effective way to discuss these weaknesses is to note the distinct features which classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed. The most classic instantiations of this category of weakness are SQL injection and format string vulnerabilities.
         
         

Fix information:
repo_url: https://github.com/tomoh1r/ansible-vault
commit_details: repo_url: https://github.com/tomoh1r/ansible-vault
author: Tomohiro Nakamura
author_date: 2017-09-13 20:49:38+09:00
msg: Fix security issue refs #4

* Update version to 1.0.5
* Update to use yaml.safe_load()
* Update to tomoh1r
repository: repo_url: https://github.com/tomoh1r/ansible-vault
repo_name: tomoh1r/ansible-vault
description: This project aim to R/W an ansible-vault yaml file
repo_language: Python
owner: tomoh1r
file_changes: filename: .travis.yml
change_type: ModificationType.MODIFY
diff: @@ -1,14 +1,20 @@
 ---
 language: python
 sudo: false
+cache:
+  directories:
+    - $HOME/.cache/pip
 python:
-- 2.7
-env:
-  matrix:
-    - TOXENV=py27
-    - TOXENV=py27-ansible2
+  - "2.7"
+  - "3.3"
+  - "3.4"
+  - "3.5"
+  - "3.6"
 install:
-  - pip install tox
-script: tox
+  - python -m pip install -U setuptools pip
+  - python setup.py setup_test
+script:
+  - python -m pytest
+  - if [ "$TRAVIS_PYTHON_VERSION" == '2.7' ] ; then python -m pip install -U 'ansible<2.0.0' && python -m pytest ; fi
 
 # vim:st=2 sts=2 sw=2:

programming_language: Shell
filename: CHANGES.txt
change_type: ModificationType.MODIFY
diff: @@ -1,3 +1,13 @@
+1.0.5 (2017/09/13)
+
+* Update to use yaml.safe_load()$
+* Update to tomoh1r$
+
+1.0.4 (2015/11/29)
+
+* Apply to Ansible 2
+* Add unit tests
+
 1.0.3 (2015/05/18)
 
 * fix README.rst typo

programming_language: Markdown
filename: README.rst
change_type: ModificationType.MODIFY
diff: @@ -2,8 +2,8 @@
 ansible-vault
 =============
 
-.. image:: https://travis-ci.org/jptomo/ansible-vault.svg?branch=master
-   :target: https://travis-ci.org/jptomo/ansible-vault
+.. image:: https://travis-ci.org/tomoh1r/ansible-vault.svg?branch=master
+   :target: https://travis-ci.org/tomoh1r/ansible-vault
 
 This project aim to R/W an ansible-vault yaml file
 

programming_language: Markdown
filename: README_test.rst
change_type: ModificationType.MODIFY
diff: @@ -12,4 +12,5 @@ how to test
 
    .. code-block:: console
 
+      $ ./venvtest/bin/python setup.py setup_test
       $ ./venvtest/bin/python setup.py test

programming_language: Shell
filename: api.py
change_type: ModificationType.MODIFY
diff: @@ -15,7 +15,7 @@ class Vault(object):
 
     def load(self, stream):
         '''read vault steam and return python object'''
-        return yaml.load(self.vault.decrypt(stream))
+        return yaml.safe_load(self.vault.decrypt(stream))
 
     def dump(self, data, stream=None):
         '''encrypt data and print stdout or write to stream'''

programming_language: Python
filename: pwned.txt
change_type: ModificationType.ADD
diff: @@ -0,0 +1,7 @@
+$ANSIBLE_VAULT;1.1;AES256
+31616433623434626463363932323936663066353063393731346536636437633463633137643032
+3663656431663830396662646132343735623538346330640a363532326262353732636161633431
+61353936346235396464333333653831356638393264343662363362653433353762396663653465
+6439366430336336660a363931663030323665633136363362353162333864653933653763656462
+31656431653333343834623731393263393865353831333963616165613237376630646665306363
+6238373037663462343565643737303136333032386136356438

programming_language: Ruby
filename: test_api.py
change_type: ModificationType.MODIFY
diff: @@ -1,9 +1,9 @@
 import os
 from tempfile import mkstemp
 
-from testfixtures import ShouldRaise
-
 from ansible.errors import AnsibleError
+from testfixtures import ShouldRaise
+from yaml.constructor import ConstructorError
 
 
 here = os.path.dirname(os.path.abspath(__file__))
@@ -28,6 +28,12 @@ class TestVaultLoad(object):
         with ShouldRaise(AnsibleError('Decryption failed')):
             vault.load(open(fpath).read())
 
+    def test_not_pwned(self):
+        fpath = os.path.join(here, 'file', 'pwned.txt')
+        vault = self._makeOne('password')
+        with ShouldRaise(ConstructorError):
+            vault.load(open(fpath).read())
+
 
 class TestVaultDump(object):
     def _getTargetClass(self):

programming_language: Python
filename: setup.cfg
change_type: ModificationType.MODIFY
diff: @@ -1,2 +1,10 @@
 [metadata]
 description-file = README.rst
+
+[aliases]
+setup_test = develop easy_install ansible-vault[test]
+release = register clean --all sdist
+
+[tools:pytest]
+norecursedirs = venv
+testpaths = ansible_vault/test

programming_language: Markdown
filename: setup.py
change_type: ModificationType.MODIFY
diff: @@ -32,19 +32,21 @@ class PyTest(TestCommand):
 
 setup(
     name='ansible-vault',
-    version='1.0.4',
+    version='1.0.5',
     author='Tomohiro NAKAMURA',
     author_email='quickness.net@gmail.com',
-    url='https://github.com/jptomo/ansible-vault',
+    url='https://github.com/tomoh1r/ansible-vault',
     description='R/W an ansible-vault yaml file',
     long_description=_read('README.rst'),
     packages=find_packages(),
     install_requires=['ansible'],
-    tests_require=['pytest', 'testfixtures'],
     cmdclass={'test': PyTest},
     classifiers=[
         'Development Status :: 5 - Production/Stable',
         'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
     ],
     license='GPLv3',
+    extras_require = {
+        'test': ['pytest', 'testfixtures'],
+    }
 )

programming_language: Python
filename: tox.ini
change_type: ModificationType.DELETE
diff: @@ -1,14 +0,0 @@
-[tox]
-envlist = py27, py27-ansible2
-setupdir = .
-
-[testenv]
-basepython = python2.7
-
-[testenv:py27]
-commands = python2.7 setup.py test
-
-[testenv:py27-ansible2]
-commands =
-    pip install -U git+https://github.com/ansible/ansible.git@stable-2.0#egg=ansible
-    python2.7 setup.py test

programming_language: unknown