Fix exposing private messages files through attachments with a content URI. am: 0d5452146c am: f5c73b1923 am: 83d5883687
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Messaging/+/23089831 Change-Id: I37c232a6a57edc0cc0d069818787c8c77fe3d00e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import android.content.ContentResolver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.messaging.Factory;
|
import com.android.messaging.Factory;
|
||||||
@@ -28,6 +29,8 @@ import com.google.common.io.Files;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -121,6 +124,10 @@ public class FileUtil {
|
|||||||
// We're told it's possible to create world readable hardlinks to other apps private data
|
// We're told it's possible to create world readable hardlinks to other apps private data
|
||||||
// so we ban all /data file uris.
|
// so we ban all /data file uris.
|
||||||
public static boolean isInPrivateDir(Uri uri) {
|
public static boolean isInPrivateDir(Uri uri) {
|
||||||
|
return isFileUriInPrivateDir(uri) || isContentUriInPrivateDir(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isFileUriInPrivateDir(Uri uri) {
|
||||||
if (!UriUtil.isFileUri(uri)) {
|
if (!UriUtil.isFileUri(uri)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -128,6 +135,24 @@ public class FileUtil {
|
|||||||
return FileUtil.isSameOrSubDirectory(Environment.getDataDirectory(), file);
|
return FileUtil.isSameOrSubDirectory(Environment.getDataDirectory(), file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isContentUriInPrivateDir(Uri uri) {
|
||||||
|
if (!uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Context context = Factory.get().getApplicationContext();
|
||||||
|
ParcelFileDescriptor pfd = context.getContentResolver().openFileDescriptor(uri, "r");
|
||||||
|
int fd = pfd.getFd();
|
||||||
|
// Use the file descriptor to find out the read file path through symbolic link.
|
||||||
|
Path fdPath = Paths.get("/proc/self/fd/" + fd);
|
||||||
|
Path filePath = java.nio.file.Files.readSymbolicLink(fdPath);
|
||||||
|
pfd.close();
|
||||||
|
return FileUtil.isSameOrSubDirectory(Environment.getDataDirectory(), filePath.toFile());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks, whether the child directory is the same as, or a sub-directory of the base
|
* Checks, whether the child directory is the same as, or a sub-directory of the base
|
||||||
* directory.
|
* directory.
|
||||||
|
|||||||
Reference in New Issue
Block a user