Repository navigation
Fix: Cloudflare bot checks failing and endless Google captchas - #18
Merged
Merged
Conversation
Cloudflare Turnstile failed and Google kept asking for a captcha. Three causes: 1. CookieManager.setAcceptCookie is process-wide, but it was set from the current tab: "cookiesEnabled && !tab.isIncognito". Opening an incognito tab therefore disabled cookies for every tab, so challenge cookies never stuck. It is now set from the user's cookie preference only. 2. WebView's stock UA carries "; wv)" and "Version/4.0", the tokens bot checks read as "embedded app view". UserAgentUtils.normalize() strips exactly those and keeps the real engine version; the desktop UA is derived from the device UA instead of the hardcoded Chrome/128 (a version that never matched the engine). 3. A mobile UA with useWideViewPort/loadWithOverviewMode on reports a 980px viewport, an inconsistency challenge scripts flag. Both are now desktop-mode only. Also: cookies are flushed after each page so a passed challenge survives a restart. Adds UserAgentUtils + 5 unit tests, and a docs note on why each of these matters.
|
Caution Review failedThe pull request is closed. Walkthrough
Change: Bug fix Merge Risk:
|
The unit-test job failed twice in a row on 'AssertionError at MavenArtifactFetcher.java:129 ... IOException' — Robolectric could not fetch its android-all jar from Maven Central. Cache ~/.m2/repository/org/robolectric across runs so one bad network moment cannot block a pull request.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
Sites behind Cloudflare's managed challenge ("Verifying you are human…") never let the user through, and Google asks for a captcha again and again.
Root causes — all three were in our code
CookieManager.setAcceptCookie(settings.cookiesEnabled && !tab.isIncognito)setAcceptCookieis process-wide. Opening one incognito tab disabled cookies for every tab, so the challenge cookie was never stored and every check re-challenged.…; wv) … Version/4.0 Chrome/…); wv)andVersion/4.0are exactly the tokens Turnstile/reCAPTCHA read as "embedded app view, not a browser".Chrome/128.0.0.0anduseWideViewPort/loadWithOverviewModealways onFixes
browser/UserAgentUtils.kt:normalize()removes; wv)andVersion/4.0and keeps the real engine version;toDesktop()builds a desktop UA from the device UA so the version always matches. Both covered by 5 unit tests.useWideViewPort/loadWithOverviewModeonly in desktop mode, so the viewport agrees with the UA.Honest note on the user agent
The browser now presents the same UA shape as Chrome on Android. That is what a WebView-based browser has to do: the
wvtoken marks an app view, and every bot check treats it that way. Nothing is faked beyond dropping those two tokens — the engine version, platform and mobile marker stay exactly as the device reports them.Checks
Quality Gate & Testson this PR: rules, unit tests (now includingUserAgentUtilsTest), compile and lint.Summary by CodeRabbit