Prevent invalid user agent header values from being set

This commit is contained in:
arkon 2022-10-21 16:27:59 -04:00
parent 2921be620a
commit d2e62ffb19
2 changed files with 9 additions and 0 deletions

View file

@ -61,6 +61,7 @@ import eu.kanade.tachiyomi.util.system.setDefaultSettings
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import logcat.LogPriority import logcat.LogPriority
import okhttp3.Headers
import rikka.sui.Sui import rikka.sui.Sui
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -267,6 +268,13 @@ class SettingsAdvancedScreen : SearchableSettings {
context.toast(R.string.error_user_agent_string_blank) context.toast(R.string.error_user_agent_string_blank)
return@EditTextPreference false 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) context.toast(R.string.requires_app_restart)
true true
}, },

View file

@ -498,6 +498,7 @@
<string name="pref_dns_over_https">DNS over HTTPS (DoH)</string> <string name="pref_dns_over_https">DNS over HTTPS (DoH)</string>
<string name="pref_user_agent_string">Default user agent string</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_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="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="requires_app_restart">Requires app restart to take effect</string>
<string name="cookies_cleared">Cookies cleared</string> <string name="cookies_cleared">Cookies cleared</string>