我在我的项目上运行了 bandit 并遇到了以下安全问题,我不明白为什么这是一个问题以及这些问题的解决方案是什么。
--------------------------------------------------
>> Issue: [B108:hardcoded_tmp_directory] Probable insecure usage of temp file/directory.
Severity: Medium Confidence: Medium
Location: abc/xyz/xxx.py:176
More Info: https://bandit.readthedocs.io/en/latest/plugins/b108_hardcoded_tmp_directory.html
175 def get_pickle_file_path(self):
176 return os.path.join("/tmp/aaa", "folder_" + self.name)
177
--------------------------------------------------
>> Issue: [B102:exec_used] Use of exec detected.
Severity: Medium Confidence: High
Location: abc/models.py:1405
More Info: https://bandit.readthedocs.io/en/latest/plugins/b102_exec_used.html
1404 loc = {'result': []}
1405 exec(self.code, globals(), loc)
1406 return loc['result']
在寻找B108问题的解决方案后。我发现这个where/tmp
被tempfile.gettempdir()
函数替换了,但是两者的值是一样的。tempfile.gettempdir()
解决方案是什么/tmp
?