您的应用正在使用内容提供程序以及openFile的不安全实现

Far*_*ooq 10 android-security

在Playstore上发布我的应用程序后,我已收到此电子邮件:

您好Google Play开发人员,

我们查看了[MyAppName],其软件包名称为com.example.myappname,发现您的应用使用了包含用户安全漏洞的软件。具有这些漏洞的应用程序可能会泄露用户信息或损坏用户的设备,并且可能被视为违反了我们的恶意行为政策。

以下是问题列表以及您最近提交的文件中检测到的相应APK版本。请迁移您的应用,以尽快使用更新的软件,并增加已升级APK的版本号。

您的应用正在使用带有不安全的openFile实现的内容提供程序。

要解决此问题,请按照此Google帮助中心文章中的步骤进行操作。

漏洞APK版本修复路径遍历的最后期限您的应用程序使用了带有不安全实施openFile的内容提供程序。

要解决此问题,请按照此Google帮助中心文章中的步骤进行操作。

2019年6月1日漏洞APK版本修复的最后期限要确认您已正确升级,请将应用程序的更新版本提交到Play控制台,并在五个小时后返回。如果应用程序未正确更新,我们将显示警告消息。


我在应用程序中使用了Realm数据库,iText pdf库,文件提供程序。我正在使用FileProvider使用意图从存储中打开pdf文件。

res> xml> provider_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path
        name="external_files"
        path="." />
</paths>
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.appName">

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_icon"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_icon"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        ...

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths" />
        </provider>
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

TemplatesFragment.java

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyCvs/Templates/" + templateName);
        Uri uriPdf = FileProvider.getUriForFile(getActivity(), BuildConfig.APPLICATION_ID + ".provider", file);
        Intent target = new Intent(Intent.ACTION_VIEW);
        target.setDataAndType(uriPdf, "application/pdf");
        target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        target.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Intent intent = Intent.createChooser(target, "Open File");
        try {
            startActivity(intent);
        } catch (Exception e) {
            // Instruct the user to install a PDF reader here, or something
            Toast.makeText(getActivity(), "" + e.getMessage(), Toast.LENGTH_SHORT).show();
        }
Run Code Online (Sandbox Code Playgroud)

Ati*_*aiz 6

不要"."输入path,而是提供您要使用的文件夹的名称。

例如,如果要访问/使用“下载”文件夹,则在中provider_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path
        name="downloads"
        path="Download/" />
</paths>
Run Code Online (Sandbox Code Playgroud)


Mar*_*ler 5

实际上,它们提供了所有需要了解的知识。请参阅support.google.com

的实现openFile在出口ContentProviders可能容易,如果他们不正确验证传入的URI参数。恶意应用程序可以提供精心制作的Uri(例如,包含“ /../”的Uri),以诱骗您的应用程序返回ParcelFileDescriptor目标目录之外的文件的,从而允许恶意应用程序访问您可访问的任何文件应用程式。

FileProvider必须拒绝任何Uri含有........那些被认为“开采”。