Skip to content

Commit

Permalink
Tests and fix for CVE-2021-3144
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz committed Jan 22, 2021
1 parent aee8413 commit 7c1d565
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions salt/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def get_tok(self, tok):

if rm_tok:
self.rm_token(tok)
return {}

return tdata

Expand Down
40 changes: 40 additions & 0 deletions tests/unit/auth/test_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
import os
import time
import salt.auth
import salt.config
from tests.support.runtests import RUNTIME_VARS
from tests.support.unit import TestCase



class AuthTest(TestCase):

def test_cve_2021_3244(self):
opts = {
"extension_modules": "",
"optimization_order": [0, 1, 2],
"token_expire": 1,
"keep_acl_in_token": False,
"eauth_tokens": "localfs",
"token_dir": RUNTIME_VARS.TMP,
"token_expire_user_override": True,
"external_auth": {
"auto": {
"foo": []
}
}
}
auth = salt.auth.LoadAuth(opts)
load = {
"eauth": "auto",
"username": "foo",
"password": "foo",
"token_expire": -1}
t_data = auth.mk_token(load)
assert t_data['expire'] < time.time()
token_file = os.path.join(RUNTIME_VARS.TMP, t_data['token'])
assert os.path.exists(token_file)
t_data = auth.get_tok(t_data['token'])
assert not os.path.exists(token_file)
assert t_data == {}

0 comments on commit 7c1d565

Please sign in to comment.