From 59c4102ba387c8a4104923eba9c90124c3e9e481 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Thu, 10 Nov 2022 14:30:47 -0700 Subject: [PATCH] Restrict the File Provider to a subfolder of the cache directory. https://redmine.stoutner.com/issues/779 --- .../activities/ImportExportActivity.java | 37 +++++++++++++++++-- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values-it/strings.xml | 2 +- app/src/main/res/values-pt-rBR/strings.xml | 2 +- app/src/main/res/values-ru/strings.xml | 7 +++- app/src/main/res/values-tr/strings.xml | 2 +- app/src/main/res/values/strings.xml | 5 ++- app/src/main/res/xml/file_provider_paths.xml | 2 +- 10 files changed, 49 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/ImportExportActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/ImportExportActivity.java index 7c347a44..4c48b426 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/ImportExportActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/ImportExportActivity.java @@ -1,5 +1,5 @@ /* - * Copyright © 2018-2022 Soren Stoutner . + * Copyright 2018-2022 Soren Stoutner . * * This file is part of Privacy Browser Android . * @@ -105,6 +105,7 @@ public class ImportExportActivity extends AppCompatActivity { Button importExportButton; // Define the class variables. + private File fileProviderDirectory; private boolean openKeychainInstalled; private File temporaryPgpEncryptedImportFile; private File temporaryPreEncryptedExportFile; @@ -499,6 +500,13 @@ public class ImportExportActivity extends AppCompatActivity { //noinspection ResultOfMethodCallIgnored temporaryPgpEncryptedImportFile.delete(); } + + // Delete the file provider directory if it exists. + if (fileProviderDirectory.exists()) { + //noinspection ResultOfMethodCallIgnored + fileProviderDirectory.delete(); + } + break; case OPENPGP_EXPORT_RESULT_CODE: @@ -507,6 +515,13 @@ public class ImportExportActivity extends AppCompatActivity { //noinspection ResultOfMethodCallIgnored temporaryPreEncryptedExportFile.delete(); } + + // Delete the file provider directory if it exists. + if (fileProviderDirectory.exists()) { + //noinspection ResultOfMethodCallIgnored + fileProviderDirectory.delete(); + } + break; } } @@ -657,8 +672,15 @@ public class ImportExportActivity extends AppCompatActivity { case OPENPGP_ENCRYPTION: try { + // Get a handle for the file provider directory. + fileProviderDirectory = new File(getApplicationContext().getCacheDir() + "/" + getString(R.string.file_provider_directory)); + + // Create the file provider directory. Any errors will be handled by the catch statement below. + //noinspection ResultOfMethodCallIgnored + fileProviderDirectory.mkdir(); + // Set the temporary PGP encrypted import file. - temporaryPgpEncryptedImportFile = File.createTempFile("temporary_pgp_encrypted_import_file", null, getApplicationContext().getCacheDir()); + temporaryPgpEncryptedImportFile = File.createTempFile("temporary_pgp_encrypted_import_file", null, fileProviderDirectory); // Create a temporary PGP encrypted import file output stream. FileOutputStream temporaryPgpEncryptedImportFileOutputStream = new FileOutputStream(temporaryPgpEncryptedImportFile); @@ -858,8 +880,15 @@ public class ImportExportActivity extends AppCompatActivity { case OPENPGP_ENCRYPTION: try { + // Get a handle for the file provider directory. + fileProviderDirectory = new File(getApplicationContext().getCacheDir() + "/" + getString(R.string.file_provider_directory)); + + // Create the file provider directory. Any errors will be handled by the catch statement below. + //noinspection ResultOfMethodCallIgnored + fileProviderDirectory.mkdir(); + // Set the temporary pre-encrypted export file. - temporaryPreEncryptedExportFile = new File(getApplicationContext().getCacheDir() + "/" + getString(R.string.settings) + " " + BuildConfig.VERSION_NAME + ".pbs"); + temporaryPreEncryptedExportFile = new File(fileProviderDirectory + "/" + getString(R.string.settings) + " " + BuildConfig.VERSION_NAME + ".pbs"); // Delete the temporary pre-encrypted export file if it already exists. if (temporaryPreEncryptedExportFile.exists()) { @@ -932,4 +961,4 @@ public class ImportExportActivity extends AppCompatActivity { // Restart Privacy Browser after 150 milliseconds to allow enough time for the preferences to be saved. restartHandler.postDelayed(restartRunnable, 150); } -} \ No newline at end of file +} diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index f0e0c5eb..336b27b0 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -193,7 +193,7 @@ Manchmal müssen MIME-gekapselte HTML-Web-Archive (MHT) manuell festgelegt werden, um korrekt geöffnet zu werden. + The `%*$s` code inserts variables into the displayed text and should be preserved in translation. --> URL speichern Archiv speichern Text speichern diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index a304733f..628fe9b0 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -189,7 +189,7 @@ A veces se necesita especificar manualmente los archivos web MIME Encapsulated HTML (MHT) para que se abran correctamente. + The `%*$s` code inserts variables into the displayed text and should be preserved in translation. --> Guardar URL Guardar archivo Guardar texto diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 5f9cdc6f..6a42d9a5 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -190,7 +190,7 @@ Parfois, les archives web MHT (MIME Encapsulated HTML) doivent être spécifiées manuellement pour être ouvertes correctement. + The `%*$s` code inserts variables into the displayed text and should be preserved in translation. --> Enregistrer l\'URL Enregistrer l\'archive Sauvegarder le texte diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index d601ddbf..be1697eb 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -189,7 +189,7 @@ Talvolta gli archivi web del tipo MIME Encapsulated HTML (MHT) devono essere specificati manualmente per essere aperti correttamente. + The `%*$s` code inserts variables into the displayed text and should be preserved in translation. --> Salva URL Salva Archivio Salva Testo diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 4dac8dc4..e5217f01 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -187,7 +187,7 @@ Às vezes, os arquivos da web MIME Encapsulated HTML (MHT) precisam ser especificados manualmente para serem abertos corretamente. + The `%*$s` code inserts variables into the displayed text and should be preserved in translation. --> Salvar URL Salvar Arquivo Salvar Texto diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 3afebf9e..31755ca0 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -116,6 +116,7 @@ Настройки Импорт/Экспорт Logcat + Инструменты разработчика WebView Руководство О Privacy Browser @@ -186,7 +187,7 @@ Иногда для корректного открытия веб-архивов MIME Encapsulated HTML (MHT) необходимо указать вручную. + The `%*$s` code inserts variables into the displayed text and should be preserved in translation. --> Сохранить URL Сохранить архив Сохранить текст @@ -198,6 +199,8 @@ неправильный URL Сохранение файла: Обработка изображения… : + Ошибка сохранения %1$s: \u0020 %2$s + Неизвестная ошибка Заголовки запроса @@ -560,6 +563,8 @@ Потянуть для обновления Некоторые веб-сайты могут работать некорректно при включении данной опции. Загрузка во внешнем приложении + Внешние приложения не будут учитывать настройки прокси Privacy Browser и не будут иметь доступа к cookie + (это означает, что файлы, загруженные с сайтов, для которых требуется авторизация, вряд ли будут работать). Прокручивать панель приложения Прокручивает панель приложения вверху экрана при прокрутке WebView вниз. Нижняя панель приложения diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 90a66064..ee192741 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -173,7 +173,7 @@ Sonraki + The `%*$s` code inserts variables into the displayed text and should be preserved in translation. --> Resmi kaydet Dosya adı Bilinmeyen boyut diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1e30a7a8..6f0a5d8f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,6 +25,7 @@ com.stoutner.privacybrowser.fileprovider.standard + file_provider Privacy Browser @@ -195,7 +196,7 @@ Sometimes MIME Encapsulated HTML (MHT) web archives need to be manually specified to be opened correctly. + The `%*$s` code inserts variables into the displayed text and should be preserved in translation. --> Save Dialog Save URL Save Archive @@ -209,7 +210,7 @@ Saving file: %1$s saved. Processing image… : - Error saving %1$s: \u0020 %2$s --> + Error saving %1$s: \u0020 %2$s Unknown error diff --git a/app/src/main/res/xml/file_provider_paths.xml b/app/src/main/res/xml/file_provider_paths.xml index ffbe1760..d3786604 100644 --- a/app/src/main/res/xml/file_provider_paths.xml +++ b/app/src/main/res/xml/file_provider_paths.xml @@ -21,5 +21,5 @@ + path="file_provider" /> -- 2.45.2