这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit dcedf39

Browse files
Changed: Only allow ContentProvider access if allow-external-apps is set to true
1 parent e302a14 commit dcedf39

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

app/src/main/java/com/termux/app/RunCommandService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
122122
// user knows someone tried to run a command in termux context, since it may be malicious
123123
// app or imported (tasker) plugin project and not the user himself. If a pending intent is
124124
// also sent, then its creator is also logged and shown.
125-
errmsg = PluginUtils.checkIfRunCommandServiceAllowExternalAppsPolicyIsViolated(this);
125+
errmsg = PluginUtils.checkIfAllowExternalAppsPolicyIsViolated(this, LOG_TAG);
126126
if (errmsg != null) {
127127
executionCommand.setStateFailed(Errno.ERRNO_FAILED.getCode(), errmsg);
128128
PluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, true);

app/src/main/java/com/termux/app/TermuxOpenReceiver.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.provider.MediaStore;
1414
import android.webkit.MimeTypeMap;
1515

16+
import com.termux.app.utils.PluginUtils;
1617
import com.termux.shared.data.IntentUtils;
1718
import com.termux.shared.logger.Logger;
1819
import com.termux.shared.termux.TermuxConstants;
@@ -190,6 +191,12 @@ public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) thr
190191
throw new IllegalArgumentException("Invalid path: " + path);
191192
}
192193

194+
// If "allow-external-apps" property to not set to "true", then throw exception
195+
String errmsg = PluginUtils.checkIfAllowExternalAppsPolicyIsViolated(getContext(), LOG_TAG);
196+
if (errmsg != null) {
197+
throw new IllegalArgumentException(errmsg);
198+
}
199+
193200
// Do not allow apps with RUN_COMMAND permission to modify termux apps properties files,
194201
// including allow-external-apps
195202
if (TermuxConstants.TERMUX_PROPERTIES_PRIMARY_FILE_PATH.equals(path) ||

app/src/main/java/com/termux/app/utils/PluginUtils.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,12 @@ public static void setupPluginCommandErrorsNotificationChannel(final Context con
321321
* @param context The {@link Context} to get error string.
322322
* @return Returns the {@code error} if policy is violated, otherwise {@code null}.
323323
*/
324-
public static String checkIfRunCommandServiceAllowExternalAppsPolicyIsViolated(final Context context) {
324+
public static String checkIfAllowExternalAppsPolicyIsViolated(final Context context, String apiName) {
325325
String errmsg = null;
326-
if (!SharedProperties.isPropertyValueTrue(context, TermuxPropertyConstants.getTermuxPropertiesFile(), TermuxConstants.PROP_ALLOW_EXTERNAL_APPS, true)) {
327-
errmsg = context.getString(R.string.error_run_command_service_allow_external_apps_ungranted);
326+
if (!SharedProperties.isPropertyValueTrue(context, TermuxPropertyConstants.getTermuxPropertiesFile(),
327+
TermuxConstants.PROP_ALLOW_EXTERNAL_APPS, true)) {
328+
errmsg = context.getString(R.string.error_allow_external_apps_ungranted, apiName,
329+
TermuxFileUtils.getUnExpandedTermuxPath(TermuxConstants.TERMUX_PROPERTIES_PRIMARY_FILE_PATH));
328330
}
329331

330332
return errmsg;

app/src/main/res/values/strings.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<!ENTITY TERMUX_STYLING_APP_NAME "Termux:Styling">
1010
<!ENTITY TERMUX_TASKER_APP_NAME "Termux:Tasker">
1111
<!ENTITY TERMUX_WIDGET_APP_NAME "Termux:Widget">
12-
<!ENTITY TERMUX_PROPERTIES_PRIMARY_PATH_SHORT "~/.termux/termux.properties">
1312
]>
1413

1514
<resources>
@@ -105,8 +104,6 @@
105104
<!-- Termux RunCommandService -->
106105
<string name="error_run_command_service_invalid_intent_action">Invalid intent action to RunCommandService: `%1$s`</string>
107106
<string name="error_run_command_service_mandatory_extra_missing">Mandatory extra missing to RunCommandService: \"%1$s\"</string>
108-
<string name="error_run_command_service_allow_external_apps_ungranted">RunCommandService requires `allow-external-apps`
109-
property to be set to `true` in `&TERMUX_PROPERTIES_PRIMARY_PATH_SHORT;` file.</string>
110107
<string name="error_run_command_service_api_help">Visit %1$s for more info on RUN_COMMAND Intent usage.</string>
111108

112109

@@ -118,6 +115,12 @@
118115

119116

120117

118+
<!-- Miscellaneous -->
119+
<string name="error_allow_external_apps_ungranted">%1$s requires `allow-external-apps`
120+
property to be set to `true` in `%2$s` file.</string>
121+
122+
123+
121124
<!-- Termux Settings -->
122125
<string name="title_activity_termux_settings">&TERMUX_APP_NAME; Settings</string>
123126

0 commit comments

Comments
 (0)