CodeQL 文档

Android 敏感键盘缓存

ID: java/android/sensitive-keyboard-cache
Kind: problem
Security severity: 8.1
Severity: warning
Precision: medium
Tags:
   - security
   - external/cwe/cwe-524
Query suites:
   - java-security-extended.qls
   - java-security-and-quality.qls

点击查看 CodeQL 代码库中的查询

当用户在 Android 应用程序的文本输入字段中输入信息时,他们的输入会被保存到键盘缓存中,该缓存提供自动完成建议和预测。存在敏感用户数据(例如密码或银行信息)可能通过键盘缓存泄露给其他应用程序的风险。

建议

对于预期接受敏感信息的输入字段,请使用 "textNoSuggestions"(或用于密码的 "textPassword")等输入类型,以确保输入不会存储在键盘缓存中。

或者,除了通过 XML 声明输入类型之外,您还可以使用 TextView.setInputType() 在代码中设置输入类型。

示例

在以下示例中,标记为“错误”的字段允许将密码保存到键盘缓存,而标记为“正确”的字段使用 "textPassword" 输入类型来确保密码不被缓存。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <!-- BAD: This password field uses the `text` input type, which allows the input to be saved to the keyboard cache. -->
    <EditText
        android:id="@+id/password_bad"
        android:inputType="text"/> 

    <!-- GOOD: This password field uses the `textPassword` input type, which ensures that the input is not saved to the keyboard cache. -->
    <EditText
        android:id="@+id/password_good"
        android:inputType="textPassword"/>  
</LinearLayout>

参考资料

  • ©GitHub 公司
  • 条款
  • 隐私