CodeQL 文档

敏感信息的明文存储

ID: py/clear-text-storage-sensitive-data
Kind: path-problem
Security severity: 7.5
Severity: error
Precision: high
Tags:
   - security
   - external/cwe/cwe-312
   - external/cwe/cwe-315
   - external/cwe/cwe-359
Query suites:
   - python-code-scanning.qls
   - python-security-extended.qls
   - python-security-and-quality.qls

单击以查看 CodeQL 代码库中的查询

以明文形式存储的敏感信息可被获取存储权限的攻击者访问。这对 cookie 来说尤其重要,因为 cookie 存储在最终用户的机器上。

建议

确保敏感信息在存储之前始终被加密。如果可能,完全避免将敏感信息放入 cookie 中。相反,首选在 cookie 中存储一个密钥,该密钥可用于查找敏感信息。

一般而言,仅在需要以明文形式使用敏感信息时才对其进行解密。

请注意,外部进程通常会存储应用程序的 standard outstandard error 流,这会导致记录的敏感信息也被存储。

示例

以下示例代码将用户凭据(在本例中为密码)以明文形式存储在 cookie 中

from flask import Flask, make_response, request

app = Flask("Leak password")

@app.route('/')
def index():
    password = request.args.get("password")
    resp = make_response(render_template(...))
    resp.set_cookie("password", password)
    return resp

相反,凭据应被加密,例如使用 cryptography 模块,或者根本不存储。

参考资料

  • M. Dowd,J. McDonald 和 J. Schuhm,《软件安全评估艺术》,第 1 版,第 2 章 -“加密的常见漏洞”,第 43 页。Addison Wesley,2006 年。

  • M. Howard 和 D. LeBlanc,《编写安全代码》,第 2 版,第 9 章 -“保护秘密数据”,第 299 页。Microsoft,2002 年。

  • 常见弱点枚举:CWE-312.

  • 常见弱点枚举:CWE-315.

  • 常见弱点枚举:CWE-359.

  • ©GitHub, Inc.
  • 条款
  • 隐私