首页 > 解决方案 > 来自 Google Play 商店的 Android React Native App HostNameVerifier 错误

问题描述

请帮忙,我在 MainApplication.java 文件中有以下实现。我正在检查固定的主机名,然后相应地返回 true 或 false。

错误不安全的主机名验证程序

安全性 您的应用正在使用不安全的主机名验证器实现。请参阅此 Google 帮助中心文章了解详细信息,包括修复漏洞的截止日期。

ld/a/a/a/a/c/e$1; ld/a/a/a/a/c/f$1; sv:截止日期:2020 年 12 月 10 日

 @Override
  public void onCreate() {
    super.onCreate();
    hostnameVerifier();
    MobileCore.setApplication(this);
    SoLoader.init(this, /* native exopackage */ false);
    ReactNativeFirebaseApp.setApplicationContext(this);
  }

private void hostnameVerifier(){
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
      @Override
      public boolean verify(String arg0, SSLSession arg1) {
        String hostList[] = {"in.appcenter.ms", "graph.facebook.com",
            "assets.adobedtm.com", "codepushupdates.azureedge.net", "app-measurement.com",
            "forter.com", "dmn1", "dmn2", "dmn3", "quantummetric.com", "urbanairship.com", "demdex.net", "search.unbxd.io",
            "monetate.net", "bazaarvoice.com", "google.com", "stylitics.com", "getcandid.com","braintreegateway.com"
          };

          for (String host : hostList) {
            if (host.contains(arg0) || arg0.endsWith(host)) {
              return true;
            }
          }
        return false;
      }
    });
  }

我应该改变什么,请帮助。

标签: androidreact-nativegoogle-playandroid-security

解决方案


在 google play 控制台上,转到发布管理 -> 选择 apk 版本 -> 安全选项卡。在那里,您将看到该 apk 的安全问题列表以及代码中可能导致该安全问题的类。

如果您没有看到类名,而是在安全警告消息中看到一些编码代码,请通过禁用您可能使用的任何代码压缩工具来上传另一个构建。就我而言,它是 proguard,我禁用了它并获得了库名称。仅供参考 - 就我而言,图书馆是 Braintree


推荐阅读