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

10

我在发布应用到Play商店后收到了以下邮件:

尊敬的Google Play开发者:

我们审查了你的应用[MyAppName],包名为com.example.myappname,并发现你的应用使用了存在安全漏洞的软件。这些漏洞可能会导致用户信息泄露或设备损坏,并且可能被视为违反我们的恶意行为政策。

以下是检测到的问题及相应APK版本的列表。请尽快将应用迁移到使用更新的软件,并递增升级后的APK版本号。

你的应用正在使用一个具有不安全的openFile实现的内容提供程序。

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

漏洞 APK版本 修复截止日期 路径穿越 你的应用正在使用一个具有不安全的openFile实现的内容提供程序。

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

1 2019年6月25日 漏洞 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>

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>

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();
        }

请检查@Atif Pervaiz的答案。 - user10407482
2个回答

7
不要在路径中使用“.”,而是提供您想要使用的文件夹的名称。
例如,如果您想要访问/使用下载文件夹,则在provider_paths.xml中:
<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path
        name="downloads"
        path="Download/" />
</paths>

5
他们实际上提供了一个人需要知道的所有东西;请参见support.google.com

如果导出的ContentProviders中的openFile实现未正确验证传入的Uri参数,则可能存在漏洞。 恶意应用程序可以提供经过精心制作的Uri(例如,包含“/../”的Uri)来欺骗您的应用程序返回指向预期目录之外的文件的ParcelFileDescriptor,从而允许恶意应用程序访问您的应用程序可以访问的任何文件。

FileProvider 必须拒绝包含 ..,被视为“可利用”的任何 Uri

1
Zeilter。如何做到这一点?我使用了Google提供的代码,但功能停止工作了。我的问题和代码是:https://stackoverflow.com/questions/57112903/your-apps-are-using-a-content-provider-with-an-unsafe-implementation-of-openfi - Alpesh
@Alpesh,你还在那里有一个path =“。”,这意味着“当前目录”......根据他们描述漏洞的方式......FileProvider必须拒绝任何包含..Uri,这意味着“上一级目录”。 - Martin Zeitler
我应该在代码部分写什么?不理解。 - Alpesh
你能提供一些示例代码来访问/共享/使用特定文件夹中的文件吗?例如,我的应用程序在地址为root/MyCvs/Templates/的文件夹中创建和使用文件。 - user10407482
1
! uri.toString().contains("..") 怎么样?我猜预发布测试只是使用一个潜在恶意的 Uri 访问提供者,然后查看其响应。 - Martin Zeitler
显示剩余4条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接