【问题标题】:Your app(s) are vulnerable to Intent Redirection. startActivityForResult您的应用容易受到 Intent 重定向的影响。开始活动结果
【发布时间】:2021-08-10 05:19:45
【问题描述】:

我的应用程序存在意图重定向问题。所以过了一段时间,我设法找出问题所在。 问题是

androidx.activity.ComponentActivity->startActivityForResult

我在 SMS Retriever 中的广播接收器中使用它

  private final BroadcastReceiver smsVerificationReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
            Bundle extras = intent.getExtras();
            Status smsRetrieverStatus = (Status) extras.get(SmsRetriever.EXTRA_STATUS);

            switch (smsRetrieverStatus.getStatusCode()) {
                case CommonStatusCodes.SUCCESS:
                    // Get consent intent
                    Intent consentIntent = extras.getParcelable(SmsRetriever.EXTRA_CONSENT_INTENT);
                    try {

                        startActivityForResult(consentIntent, SMS_CONSENT_REQUEST);

                    } catch (ActivityNotFoundException e) {
                        // Handle the exception ...
                    }
                    break;
                case CommonStatusCodes.TIMEOUT:
                    // Time out occurred, handle the error.
                    break;
            }
        }
    }
};

onActivityResult

  @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {

        case SMS_CONSENT_REQUEST:
            if (resultCode == RESULT_OK) {
                // Get SMS message content
                String message = data.getStringExtra(SmsRetriever.EXTRA_SMS_MESSAGE);
                // Extract one-time code from the message and complete verification
                
                if(message != null && message.contains("is")){
                    String pass = message.substring(message.indexOf("is") +2).trim();
                    
                    mEtCode.setText(pass);
                }

             } else {
                // Consent canceled, handle the error ...
            }
            break;
    }
}

【问题讨论】:

  • 你的问题是什么?
  • 修复意图重定向。它会导致安全问题。谷歌给出了解决问题的最后期限。如果您不修复它,该应用程序将从 Playstore 中删除,我在进行一些更改后上传了 beta 版本。如果它被正确批准,那么我将自己回答这个问题。
  • 谷歌对这个垃圾很荒谬。他们标记了已禁用导出的 BroadcastReceiver 的onReceive,因为它可能被恶意劫持。听起来安全漏洞是编写 API 的白痴,而不是文档中使用它们的开发人员。

标签: android android-security


【解决方案1】:

我做了一些修改来解决这个问题。现在它在上传到 google play 后没有显示任何漏洞。欲了解更多信息,请访问this link

    private final BroadcastReceiver smsVerificationReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
            Bundle extras = intent.getExtras();
            Status smsRetrieverStatus = (Status) extras.get(SmsRetriever.EXTRA_STATUS);

            switch (smsRetrieverStatus.getStatusCode()) {
                case CommonStatusCodes.SUCCESS:
                    // Get consent intent
                    Intent consentIntent = extras.getParcelable(SmsRetriever.EXTRA_CONSENT_INTENT);
                    try {

                        ComponentName name = consentIntent.resolveActivity(getPackageManager());

                        Log.e(TAG, "onReceive: "+name.getPackageName() + " " + name.getClassName());

                        if (name.getPackageName().equalsIgnoreCase("com.google.android.gms") &&
                                name.getClassName().equalsIgnoreCase("com.google.android.gms.auth.api.phone.ui.UserConsentPromptActivity")) {

                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                                consentIntent.removeFlags(FLAG_GRANT_READ_URI_PERMISSION);
                                consentIntent.removeFlags(FLAG_GRANT_WRITE_URI_PERMISSION);
                                consentIntent.removeFlags(FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
                                consentIntent.removeFlags(FLAG_GRANT_PREFIX_URI_PERMISSION);
                            }

                            someActivityResultLauncher.launch(consentIntent);
                        }
                    } catch (ActivityNotFoundException e) {
                        // Handle the exception ...
                    }
                    break;
                case CommonStatusCodes.TIMEOUT:
                    // Time out occurred, handle the error.
                    break;
            }
        }
    }
};

结果。

    ActivityResultLauncher<Intent> someActivityResultLauncher = registerForActivityResult(
        new ActivityResultContracts.StartActivityForResult(),
        result -> {
            if (result.getResultCode() == Activity.RESULT_OK) {
                // There are no request codes
                Intent data = result.getData();
                
                String message = data.getStringExtra(SmsRetriever.EXTRA_SMS_MESSAGE);
                // Extract one-time code from the message and complete verification

                if(message != null && message.contains("is")){
                    String pass = message.substring(message.indexOf("is") +2).trim();

                    mEtCode.setText(pass);
                }
            }
        });

【讨论】:

    猜你喜欢
    • 2021-03-25
    • 2021-05-21
    • 2022-06-28
    • 2018-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    • 1970-01-01
    相关资源
    最近更新 更多