From dcedf394343f97284359f33a52e264089a335751 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Fri, 24 Sep 2021 00:47:38 +0500 Subject: [PATCH] Changed: Only allow ContentProvider access if allow-external-apps is set to true --- app/src/main/java/com/termux/app/RunCommandService.java | 2 +- app/src/main/java/com/termux/app/TermuxOpenReceiver.java | 7 +++++++ app/src/main/java/com/termux/app/utils/PluginUtils.java | 8 +++++--- app/src/main/res/values/strings.xml | 9 ++++++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/termux/app/RunCommandService.java b/app/src/main/java/com/termux/app/RunCommandService.java index f54f1693..7939d9c5 100644 --- a/app/src/main/java/com/termux/app/RunCommandService.java +++ b/app/src/main/java/com/termux/app/RunCommandService.java @@ -122,7 +122,7 @@ public class RunCommandService extends Service { // user knows someone tried to run a command in termux context, since it may be malicious // app or imported (tasker) plugin project and not the user himself. If a pending intent is // also sent, then its creator is also logged and shown. - errmsg = PluginUtils.checkIfRunCommandServiceAllowExternalAppsPolicyIsViolated(this); + errmsg = PluginUtils.checkIfAllowExternalAppsPolicyIsViolated(this, LOG_TAG); if (errmsg != null) { executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg); PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, true); diff --git a/app/src/main/java/com/termux/app/TermuxOpenReceiver.java b/app/src/main/java/com/termux/app/TermuxOpenReceiver.java index a4f7e5bd..b5cb358e 100644 --- a/app/src/main/java/com/termux/app/TermuxOpenReceiver.java +++ b/app/src/main/java/com/termux/app/TermuxOpenReceiver.java @@ -13,6 +13,7 @@ import android.os.ParcelFileDescriptor; import android.provider.MediaStore; import android.webkit.MimeTypeMap; +import com.termux.app.utils.PluginUtils; import com.termux.shared.data.IntentUtils; import com.termux.shared.logger.Logger; import com.termux.shared.termux.TermuxConstants; @@ -190,6 +191,12 @@ public class TermuxOpenReceiver extends BroadcastReceiver { throw new IllegalArgumentException("Invalid path: " + path); } + // If "allow-external-apps" property to not set to "true", then throw exception + String errmsg = PluginUtils.checkIfAllowExternalAppsPolicyIsViolated(getContext(), LOG_TAG); + if (errmsg != null) { + throw new IllegalArgumentException(errmsg); + } + // Do not allow apps with RUN_COMMAND permission to modify termux apps properties files, // including allow-external-apps if (TermuxConstants.TERMUX_PROPERTIES_PRIMARY_FILE_PATH.equals(path) || diff --git a/app/src/main/java/com/termux/app/utils/PluginUtils.java b/app/src/main/java/com/termux/app/utils/PluginUtils.java index 17fbbdb7..adc165a2 100644 --- a/app/src/main/java/com/termux/app/utils/PluginUtils.java +++ b/app/src/main/java/com/termux/app/utils/PluginUtils.java @@ -321,10 +321,12 @@ public class PluginUtils { * @param context The {@link Context} to get error string. * @return Returns the {@code error} if policy is violated, otherwise {@code null}. */ - public static String checkIfRunCommandServiceAllowExternalAppsPolicyIsViolated(final Context context) { + public static String checkIfAllowExternalAppsPolicyIsViolated(final Context context, String apiName) { String errmsg = null; - if (!SharedProperties.isPropertyValueTrue(context, TermuxPropertyConstants.getTermuxPropertiesFile(), TermuxConstants.PROP_ALLOW_EXTERNAL_APPS, true)) { - errmsg = context.getString(R.string.error_run_command_service_allow_external_apps_ungranted); + if (!SharedProperties.isPropertyValueTrue(context, TermuxPropertyConstants.getTermuxPropertiesFile(), + TermuxConstants.PROP_ALLOW_EXTERNAL_APPS, true)) { + errmsg = context.getString(R.string.error_allow_external_apps_ungranted, apiName, + TermuxFileUtils.getUnExpandedTermuxPath(TermuxConstants.TERMUX_PROPERTIES_PRIMARY_FILE_PATH)); } return errmsg; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 192eddd5..d5335bf0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -9,7 +9,6 @@ - ]> @@ -105,8 +104,6 @@ Invalid intent action to RunCommandService: `%1$s` Mandatory extra missing to RunCommandService: \"%1$s\" - RunCommandService requires `allow-external-apps` - property to be set to `true` in `&TERMUX_PROPERTIES_PRIMARY_PATH_SHORT;` file. Visit %1$s for more info on RUN_COMMAND Intent usage. @@ -118,6 +115,12 @@ + + %1$s requires `allow-external-apps` + property to be set to `true` in `%2$s` file. + + + &TERMUX_APP_NAME; Settings