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
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user