敏感信息的明文存储¶
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
未加密存储的敏感信息可供获得存储访问权限的攻击者访问。
建议¶
确保敏感信息在存储之前始终被加密。
通常,仅在需要以明文使用敏感信息时才对其进行解密。
请注意,外部进程通常会存储应用程序的 standard out
和 standard 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