【问题标题】:Your app contains an Implicit Internal Intent vulnerability您的应用包含隐式内部意图漏洞
【发布时间】:2022-01-28 15:52:29
【问题描述】:

Google 拒绝了我的应用,当我将应用作为生产版本提交时,我遇到了这个安全错误:

隐式内部意图

您的应用包含隐式内部意图漏洞。请 有关详细信息,请参阅此 Google 帮助中心文章。

com.mypackage.name.sync.SyncService.onHandleIntent

我采纳了此处列出的所有建议: Remediation for Implicit PendingIntent Vulnerability

但错误仍然存​​在。

我的服务:

public class SyncService extends IntentService {
    protected void onHandleIntent(Intent intent) {
... 
 Intent i = new Intent("com.mypackage.name.REFRESH");
 app.sendBroadcast(i);
...
   }
 }

清单:

<service
    android:name=".sync.SyncService"
    android:exported="false" >
</service>

服务在许多地方以 3 种方法启动,如下所示: (根据谷歌的建议,我确实添加了 PendingIntent.FLAG_IMMUTABLE)

方法一:

Intent intent = new Intent(this, SyncService.class);
PendingIntent pIntent = PendingIntent.getService(this, 0, intent,
            PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmMgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtMillis,
        SYNC_FREQUENCY, pIntent);

方法二:

Intent intent = new Intent("com.mypackage.name.REFRESH");
intent = new Intent(getApplicationContext(), SyncService.class);
intent.putExtra("notification_unassigned_sync", true);
startService(intent);

方法三:

Intent intent = new Intent(getApplicationContext(), SyncService.class);
startService(intent);

我的代码有什么问题吗?有什么建议吗?

【问题讨论】:

    标签: java android android-intent google-play-console android-pendingintent


    【解决方案1】:

    为意图设置包名称应该可以解决问题

    intent.setPackage("com.mypackage.name"); // replace with your package name 
                                             // from AndroidManifest.xml
    

    【讨论】:

    • 我这样做了,出现同样的问题...
    • 在哪里?在应用程序中的所有意图调用中?
    • 仅使用第 3 方操作字符串(如 com.mypackage.name.REFRESH)创建的意图。未指定目标包或组件类(活动、服务)的 Intent 被认为是隐含的,并且 google play 不喜欢它们(它们可以被未指定的包/应用程序接收)。您可以将隐式意图与内置操作(如 ACTION_VIEW)一起使用
    • 也可能与我注意到您从服务中的 onHandle() 方法广播 Intent 的问题无关。有必要吗(intent触发的代码不能直接执行吗)?
    【解决方案2】:

    如何实现广播接收器?

    1. 创建一个名为MyBroadcastReceiver.java的java类。

    2. 将此代码粘贴到类中

      public class MyBroadcastReceiverextends BroadcastReceiver {
          @Override
          public void onReceive(Context context, Intent intent) {
              Toast.makeText(context,"I have received.",Toast.LENGHT_SHORT).show();
          }
      }
      
    3. 实现此代码后,您需要将其添加到 application 标记内的清单中。

      <receiver android:name="com.chatverse.free.TimeBroadcastReceiver"
           android:exported="true">
           <intent-filter>
               <action android:name="com.mypackage.name.REFRESH"/> 
           </intent-filter>
      </receiver>
      
    4. 将此代码添加到打开第一个活动的活动中。

      IntentFilter mFilter = new IntentFilter("com.mypackage.name.REFRESH");
      registerReceiver(new MyBroadcastReceiver(), mFilter);
      

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-21
    • 2019-04-05
    • 1970-01-01
    • 1970-01-01
    • 2022-08-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多