CodeQL 文档

敏感信息的明文传输

ID: swift/cleartext-transmission
Kind: path-problem
Security severity: 7.5
Severity: warning
Precision: high
Tags:
   - security
   - external/cwe/cwe-319
Query suites:
   - swift-code-scanning.qls
   - swift-security-extended.qls
   - swift-security-and-quality.qls

点击查看 CodeQL 仓库中的查询

未加密传输的敏感信息可能被攻击者访问。

建议

确保敏感信息在通过网络传输之前始终被加密。一般来说,只在需要以明文使用敏感信息的地方解密它。避免在不需要的时候传输敏感信息。

示例

以下示例展示了三种信息传输情况。在“错误”情况下,传输的数据是敏感的(信用卡号)并且未加密。在“正确”情况下,数据要么不敏感,要么使用加密保护。


func transmitMyData(connection : NWConnection, faveSong : String, creditCardNo : String) {
	// ...

	// GOOD: not sensitive information
	connection.send(content: faveSong, completion: .idempotent)

	// BAD: sensitive information saved in cleartext
	connection.send(content: creditCardNo, completion: .idempotent)

	// GOOD: encrypted sensitive information saved
	connection.send(content: encrypt(creditCardNo), completion: .idempotent)

	// ...
}

参考

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