Skip to content

Commit

Permalink
Don't allow path separators in minion ID
Browse files Browse the repository at this point in the history
  • Loading branch information
terminalmage authored and Ch3LL committed Oct 3, 2017
1 parent 5f8b5e1 commit 80d9030
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
15 changes: 4 additions & 11 deletions salt/utils/verify.py
Expand Up @@ -480,22 +480,15 @@ def clean_path(root, path, subdir=False):
return ''


def clean_id(id_):
'''
Returns if the passed id is clean.
'''
if re.search(r'\.\.\{sep}'.format(sep=os.sep), id_):
return False
return True


def valid_id(opts, id_):
'''
Returns if the passed id is valid
'''
try:
return bool(clean_path(opts['pki_dir'], id_)) and clean_id(id_)
except (AttributeError, KeyError, TypeError) as e:
if any(x in id_ for x in ('/', '\\', '\0')):
return False
return bool(clean_path(opts['pki_dir'], id_))
except (AttributeError, KeyError, TypeError):
return False


Expand Down
10 changes: 10 additions & 0 deletions tests/unit/utils/test_verify.py
Expand Up @@ -58,6 +58,16 @@ def test_valid_id_exception_handler(self):
opts = {'pki_dir': '/tmp/whatever'}
self.assertFalse(valid_id(opts, None))

def test_valid_id_pathsep(self):
'''
Path separators in id should make it invalid
'''
opts = {'pki_dir': '/tmp/whatever'}
# We have to test both path separators because os.path.normpath will
# convert forward slashes to backslashes on Windows.
for pathsep in ('/', '\\'):
self.assertFalse(valid_id(opts, pathsep.join(('..', 'foobar'))))

def test_zmq_verify(self):
self.assertTrue(zmq_version())

Expand Down

0 comments on commit 80d9030

Please sign in to comment.