CodeQL 文档

通过隐式 Intent 泄露敏感信息

ID: java/android/sensitive-communication
Kind: path-problem
Security severity: 8.2
Severity: warning
Precision: medium
Tags:
   - security
   - external/cwe/cwe-927
Query suites:
   - java-security-extended.qls
   - java-security-and-quality.qls

单击以在 CodeQL 存储库中查看查询

当隐式 Intent 与 startActivitystartServicesendBroadcast 等方法一起使用时,设备上的其他应用程序可能会读取它。

这意味着这些 Intent 中的敏感数据可能会泄露。

建议

对于 sendBroadcast 方法,可以指定接收者权限,以便只有具有特定权限的应用程序才能接收 Intent;或者可以使用 LocalBroadcastManager。否则,请确保包含敏感数据的 Intent 设置了显式接收者类。

示例

以下示例展示了广播 Intent 的两种方式。在“BAD”情况下,未指定“接收者权限”。在“GOOD”情况下,指定了“接收者权限”或“接收者应用程序”。

public void sendBroadcast1(Context context, String token, String refreshToken) 
{
    {
        // BAD: broadcast sensitive information to all listeners
        Intent intent = new Intent();
        intent.setAction("com.example.custom_action");
        intent.putExtra("token", token);
        intent.putExtra("refreshToken", refreshToken);
        context.sendBroadcast(intent);
    }

    {
        // GOOD: broadcast sensitive information only to those with permission
        Intent intent = new Intent();
        intent.setAction("com.example.custom_action");
        intent.putExtra("token", token);
        intent.putExtra("refreshToken", refreshToken);
        context.sendBroadcast(intent, "com.example.user_permission");
    }

    {
        // GOOD: broadcast sensitive information to a specific application
        Intent intent = new Intent();
        intent.setAction("com.example.custom_action");
        intent.setClassName("com.example2", "com.example2.UserInfoHandler");
        intent.putExtra("token", token);
        intent.putExtra("refreshToken", refreshToken);
        context.sendBroadcast(intent);
    }
}

参考

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