CodeQL 文档

敏感信息明文记录

ID: rb/clear-text-logging-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 流,从而导致记录的敏感信息也存储在其中。

示例

以下示例代码将用户凭据(在本例中为其密码)以明文形式记录到 standard out

require 'Logger'

class UserSession
  @@logger = Logger.new STDOUT

  def login(username, password)
    # ...
    @@logger.info "login with password: #{password})"
  end
end

相反,应在记录之前对凭据进行掩盖或删除。

require 'Logger'

class UserSession
  @@logger = Logger.new STDOUT

  def login(username, password)
    # ...
    password_escaped = password.sub(/.*/, "[redacted]")
    @@logger.info "login with password: #{password_escaped})"
  end
end

参考文献

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

  • M. Howard 和 D. LeBlanc,《编写安全代码》,第二版,第 9 章 - '保护机密数据',第 299 页。微软,2002 年。

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

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

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

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