CodeQL 文档

敏感信息的明文记录<a class="headerlink" href="#clear-text-logging-of-sensitive-information" title="Link to this heading">¶</a>

ID: js/clear-text-logging
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:
   - javascript-code-scanning.qls
   - javascript-security-extended.qls
   - javascript-security-and-quality.qls

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

如果敏感数据被写入日志条目,它可能会暴露给获得日志访问权限的攻击者。

当显示日志输出时,潜在的攻击者可以获取敏感的用户数据。此外,这些数据可能会暴露系统信息,例如完整路径名、系统信息,有时还包括用户名和密码。

建议<a class="headerlink" href="#recommendation" title="Link to this heading">¶</a>

不应记录敏感数据。

示例<a class="headerlink" href="#example" title="Link to this heading">¶</a>

在示例中,使用 `console.info` 记录了整个进程环境。生产环境部署应用程序的普通用户不应该访问有关环境配置的如此多的信息。

// BAD: Logging cleartext sensitive data
console.info(`[INFO] Environment: ${process.env}`);

在第二个示例中,记录的数据并不敏感。

let not_sensitive_data = { a: 1, b : 2} 
// GOOD: it is fine to log data that is not sensitive
console.info(`[INFO] Some object contains: ${not_sensitive_data}`);

参考资料<a class="headerlink" href="#references" title="Link to this heading">¶</a>

  • OWASP: <a class="reference external" href="https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/">将敏感信息插入日志文件</a>。

  • 通用弱点枚举: <a class="reference external" href="https://cwe.mitre.org/data/definitions/312.html">CWE-312</a>。

  • 通用弱点枚举: <a class="reference external" href="https://cwe.mitre.org/data/definitions/359.html">CWE-359</a>。

  • 通用弱点枚举: <a class="reference external" href="https://cwe.mitre.org/data/definitions/532.html">CWE-532</a>。

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