Эх сурвалжийг харах

Prevent invalid user agent header values from being set

arkon 2 жил өмнө
parent
commit
d2e62ffb19

+ 8 - 0
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
                     },

+ 1 - 0
i18n/src/main/res/values/strings.xml

@@ -498,6 +498,7 @@
     <string name="pref_dns_over_https">DNS over HTTPS (DoH)</string>
     <string name="pref_user_agent_string">Default user agent string</string>
     <string name="error_user_agent_string_blank">User agent string can not be blank</string>
+    <string name="error_user_agent_string_invalid">Invalid user agent string</string>
     <string name="pref_reset_user_agent_string">Reset default user agent string</string>
     <string name="requires_app_restart">Requires app restart to take effect</string>
     <string name="cookies_cleared">Cookies cleared</string>