Help us learn about your current experience with the documentation. Take the survey.
服务器端代码注入(Python)
Description
目标应用被发现存在代码注入漏洞。恶意攻击者可以注入任意 Python 代码在服务器上执行。这可能导致系统完全被攻破,通过访问存储的密钥、注入代码接管账户或执行操作系统命令。
Remediation
切勿将用户输入直接传递给将字符串数据作为代码评估的函数,例如 eval 或 exec。向这些方法传递字符串值几乎没有任何好处,因此最佳建议是用更安全的动态评估逻辑实现来替换当前逻辑。一种替代方法是将函数或方法存储在哈希映射中,可以使用键进行查找。如果键存在,则可以执行该函数。
def func_to_run():
print('hello world')
function_map = {'fn': func_to_run}
input = 'fn'
if input in function_map:
function_map[input]()
else:
print('invalid input')Details
| ID | Aggregated | CWE | Type | Risk |
|---|---|---|---|---|
| 94.3 | false | 94 | Active | high |