mirror of
https://github.com/valitydev/salt.git
synced 2024-11-06 08:35:21 +00:00
Don't allow path separators in minion ID
This commit is contained in:
parent
8aab65c718
commit
ee792581fc
@ -485,22 +485,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) 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
|
||||
|
||||
|
||||
|
@ -60,6 +60,16 @@ class TestVerify(TestCase):
|
||||
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())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user