summaryrefslogtreecommitdiffstats
path: root/src/com/android/messaging
diff options
context:
space:
mode:
authorTom Taylor <tomtaylor@google.com>2016-12-05 16:39:55 -0800
committerTom Taylor <tomtaylor@google.com>2016-12-05 16:39:55 -0800
commita2aa53f83afbd13b04cbdcca494fd3cf659c155d (patch)
tree76fd8f3e351673bc36bb47f05ee97d95c4eec4fe /src/com/android/messaging
parentbcc1f62715f8005684ac6b798d0d54224394e975 (diff)
downloadpackages_apps_Messaging-a2aa53f83afbd13b04cbdcca494fd3cf659c155d.tar.gz
packages_apps_Messaging-a2aa53f83afbd13b04cbdcca494fd3cf659c155d.tar.bz2
packages_apps_Messaging-a2aa53f83afbd13b04cbdcca494fd3cf659c155d.zip
32807795 Security Vulnerability - AOSP Messaging App: thirdparty can
attach private files from "/data/data/com.android.messaging/" directory to the messaging app. * This is a manual merge from ag/871758 -- backporting a security fix from Bugle to Kazoo. * Don't export the MediaScratchFileProvider or the MmsFileProvider. This will block external access from third party apps. In addition, make both providers more robust in handling path names. Make sure the file paths handled in the providers point to the expected directory. Change-Id: I9e6b3ae0e122e3f5022243418f2893d4a0859edb Fixes: 32807795
Diffstat (limited to 'src/com/android/messaging')
-rw-r--r--src/com/android/messaging/datamodel/MediaScratchFileProvider.java18
-rw-r--r--src/com/android/messaging/datamodel/MmsFileProvider.java19
2 files changed, 35 insertions, 2 deletions
diff --git a/src/com/android/messaging/datamodel/MediaScratchFileProvider.java b/src/com/android/messaging/datamodel/MediaScratchFileProvider.java
index 29ae4f4..a19523f 100644
--- a/src/com/android/messaging/datamodel/MediaScratchFileProvider.java
+++ b/src/com/android/messaging/datamodel/MediaScratchFileProvider.java
@@ -32,6 +32,7 @@ import com.android.messaging.util.LogUtil;
import com.google.common.annotations.VisibleForTesting;
import java.io.File;
+import java.io.IOException;
import java.util.List;
/**
@@ -89,8 +90,23 @@ public class MediaScratchFileProvider extends FileProvider {
private static File getFileWithExtension(final String path, final String extension) {
final Context context = Factory.get().getApplicationContext();
- return new File(getDirectory(context),
+ final File filePath = new File(getDirectory(context),
TextUtils.isEmpty(extension) ? path : path + "." + extension);
+
+ try {
+ if (!filePath.getCanonicalPath()
+ .startsWith(getDirectory(context).getCanonicalPath())) {
+ LogUtil.e(TAG, "getFileWithExtension: path "
+ + filePath.getCanonicalPath()
+ + " does not start with "
+ + getDirectory(context).getCanonicalPath());
+ return null;
+ }
+ } catch (IOException e) {
+ LogUtil.e(TAG, "getFileWithExtension: getCanonicalPath failed ", e);
+ return null;
+ }
+ return filePath;
}
private static File getDirectory(final Context context) {
diff --git a/src/com/android/messaging/datamodel/MmsFileProvider.java b/src/com/android/messaging/datamodel/MmsFileProvider.java
index 0022630..eb49802 100644
--- a/src/com/android/messaging/datamodel/MmsFileProvider.java
+++ b/src/com/android/messaging/datamodel/MmsFileProvider.java
@@ -18,12 +18,14 @@ package com.android.messaging.datamodel;
import android.content.Context;
import android.net.Uri;
+import android.text.TextUtils;
import com.android.messaging.Factory;
import com.android.messaging.util.LogUtil;
import com.google.common.annotations.VisibleForTesting;
import java.io.File;
+import java.io.IOException;
/**
* A very simple content provider that can serve mms files from our cache directory.
@@ -60,7 +62,22 @@ public class MmsFileProvider extends FileProvider {
private static File getFile(final String path) {
final Context context = Factory.get().getApplicationContext();
- return new File(getDirectory(context), path + ".dat");
+ final File filePath = new File(getDirectory(context), path + ".dat");
+
+ try {
+ if (!filePath.getCanonicalPath()
+ .startsWith(getDirectory(context).getCanonicalPath())) {
+ LogUtil.e(TAG, "getFile: path "
+ + filePath.getCanonicalPath()
+ + " does not start with "
+ + getDirectory(context).getCanonicalPath());
+ return null;
+ }
+ } catch (IOException e) {
+ LogUtil.e(TAG, "getFile: getCanonicalPath failed ", e);
+ return null;
+ }
+ return filePath;
}
private static File getDirectory(final Context context) {