CodeQL 文档

敏感信息的明文存储

ID: rb/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-359
   - external/cwe/cwe-532
Query suites:
   - ruby-code-scanning.qls
   - ruby-security-extended.qls
   - ruby-security-and-quality.qls

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

未加密存储的敏感信息可供获得存储访问权限的攻击者访问。

建议

确保敏感信息在存储之前始终被加密。

通常,仅在需要以明文使用敏感信息时才对其进行解密。

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

示例

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

class UserSession
  def login(username, password)
    # ...
    logfile = File.open("login_attempts.log")
    logfile.puts "login with password: #{password})"
  end
end

相反,凭据应在存储之前被掩盖或删除

class UserSession
  def login(username, password)
    # ...
    password_escaped = password.sub(/.*/, "[redacted]")
    logfile = File.open("login_attempts.log")
    logfile.puts "login with password: #{password_escaped})"
  end
end

参考资料

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

  • M. Howard 和 D. LeBlanc,编写安全代码,第 2 版,第 9 章 - “保护机密数据”,第 299 页。微软,2002。

  • 常见漏洞枚举:CWE-312.

  • 常见漏洞枚举:CWE-359.

  • 常见漏洞枚举:CWE-532.

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