fix: captcha dialog not triggering on VK's id.vk.ru auth domain
Real kernel log format is "CAPTCHA_SOLVE|<mode>|<url>|<token>", and the URL's host is id.vk.ru (VK ID), not login.vk.com — the previous regex only knew about login.vk.com/localhost/127.0.0.1, so the whole line was ignored and the captcha dialog never opened. Also the old \S* capture would have swallowed the trailing "|<token>" into the captured URL since it doesn't stop at "|". Now parses the CAPTCHA_SOLVE-prefixed line directly (stopping at the next "|"), with the domain-list match kept only as a fallback.
This commit is contained in:
2 files changed
+11
-6
No files matched your search
@@ -55,7 +55,7 @@ fun CaptchaWebViewDialog(captchaUrl: String, onDismiss: () -> Unit) {
|
|||||||
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
|
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
|
||||||
val url = request.url.toString()
|
val url = request.url.toString()
|
||||||
// Allow all captcha-related domains to load inside WebView
|
// Allow all captcha-related domains to load inside WebView
|
||||||
val allowedDomains = listOf("localhost", "127.0.0.1", "fapi.vk.com", "login.vk.com", "api.vk.com", "captcha.vk.com", "vk.com", "vk.ru")
|
val allowedDomains = listOf("localhost", "127.0.0.1", "fapi.vk.com", "login.vk.com", "id.vk.ru", "api.vk.com", "captcha.vk.com", "vk.com", "vk.ru")
|
||||||
val isAllowed = allowedDomains.any { url.contains(it) }
|
val isAllowed = allowedDomains.any { url.contains(it) }
|
||||||
// Only dismiss if navigating to a completely unrelated page
|
// Only dismiss if navigating to a completely unrelated page
|
||||||
if (!isAllowed) {
|
if (!isAllowed) {
|
||||||
|
|||||||
@@ -93,11 +93,16 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkForCaptcha(log: String) {
|
private fun checkForCaptcha(log: String) {
|
||||||
// Match URLs on localhost or 127.0.0.1 (local kernel server) as well as login.vk.com
|
// Kernel emits "CAPTCHA_SOLVE|<mode>|<url>|<token>" for the manual WebView flow.
|
||||||
val urlPattern = "(https?://(localhost:\\d+|127\\.0\\.0\\.1:\\d+|login\\.vk\\.com)\\S*)".toRegex()
|
// The url itself never contains "|", so stop the capture there instead of
|
||||||
val match = urlPattern.find(log)
|
// greedily eating the trailing token with it.
|
||||||
if (match != null) {
|
val solveMatch = "CAPTCHA_SOLVE\\|[^|]*\\|(https?://[^|\\s]+)".toRegex().find(log)
|
||||||
_proxyState.value = ProxyState.CaptchaRequired(match.value)
|
// Fallback for plain URLs in the log (localhost/127.0.0.1 local server,
|
||||||
|
// or VK's own auth domains, which have changed over time: login.vk.com -> id.vk.ru).
|
||||||
|
val fallbackMatch = "(https?://(localhost:\\d+|127\\.0\\.0\\.1:\\d+|id\\.vk\\.ru|login\\.vk\\.com)\\S*)".toRegex().find(log)
|
||||||
|
val captchaUrl = solveMatch?.groupValues?.get(1) ?: fallbackMatch?.value
|
||||||
|
if (captchaUrl != null) {
|
||||||
|
_proxyState.value = ProxyState.CaptchaRequired(captchaUrl)
|
||||||
ProxyService.updateNotification("Требуется авторизация", "Нажмите сюда, чтобы пройти капчу!")
|
ProxyService.updateNotification("Требуется авторизация", "Нажмите сюда, чтобы пройти капчу!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user