From d2e62ffb199d515b588b4899f7e53ed00bc47819 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 21 Oct 2022 16:27:59 -0400 Subject: [PATCH] Prevent invalid user agent header values from being set --- .../more/settings/screen/SettingsAdvancedScreen.kt | 8 ++++++++ i18n/src/main/res/values/strings.xml | 1 + 2 files changed, 9 insertions(+) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt index e25f67620..512312f62 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt @@ -61,6 +61,7 @@ import eu.kanade.tachiyomi.util.system.setDefaultSettings import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.launch import logcat.LogPriority +import okhttp3.Headers import rikka.sui.Sui import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -267,6 +268,13 @@ class SettingsAdvancedScreen : SearchableSettings { context.toast(R.string.error_user_agent_string_blank) return@EditTextPreference false } + try { + // OkHttp checks for valid values internally + Headers.Builder().add("User-Agent", it) + } catch (_: IllegalArgumentException) { + context.toast(R.string.error_user_agent_string_invalid) + return@EditTextPreference false + } context.toast(R.string.requires_app_restart) true }, diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index 08d6c4b08..df7fe818e 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -498,6 +498,7 @@ DNS over HTTPS (DoH) Default user agent string User agent string can not be blank + Invalid user agent string Reset default user agent string Requires app restart to take effect Cookies cleared