Skip to content

Fix: Cloudflare bot checks failing and endless Google captchas - #18

Merged
GothwadTech merged 2 commits into
mainfrom
fix/bot-verification
Nov 28, 2026
Merged

GothwadTech merged 2 commits into
mainfrom
fix/bot-verification

Conversation

@GothwadTech

@GothwadTech GothwadTech commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

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

# Cause Why it breaks verification
1 CookieManager.setAcceptCookie(settings.cookiesEnabled && !tab.isIncognito) setAcceptCookie is process-wide. Opening one incognito tab disabled cookies for every tab, so the challenge cookie was never stored and every check re-challenged.
2 WebView's stock UA (…; wv) … Version/4.0 Chrome/…) ; wv) and Version/4.0 are exactly the tokens Turnstile/reCAPTCHA read as "embedded app view, not a browser".
3 Hardcoded desktop UA Chrome/128.0.0.0 and useWideViewPort/loadWithOverviewMode always on A UA version that never matches the real engine, plus a 980 px viewport reported under a mobile UA, are both inconsistency signals.

Fixes

  1. Cookie acceptance is now driven only by the user's cookie setting. Incognito still gets no DOM storage, no cache and a cookie wipe on close — the isolation just no longer leaks into normal tabs.
  2. New browser/UserAgentUtils.kt: normalize() removes ; wv) and Version/4.0 and 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.
  3. useWideViewPort / loadWithOverviewMode only in desktop mode, so the viewport agrees with the UA.
  4. Cookies are flushed after each page finishes, so a passed challenge survives the next launch.

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 wv token 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 & Tests on this PR: rules, unit tests (now including UserAgentUtilsTest), compile and lint.

Summary by CodeRabbit

  • New Features
    • Desktop mode now uses a desktop-style browser identity and viewport settings.
  • Bug Fixes
    • Browser identities are cleaned up and converted more consistently, including preserving the browser version when switching to desktop mode.
    • Cookie preferences are applied consistently, and cookies are saved after pages finish loading.
    • The fallback desktop browser identity has been updated.

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.
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

Changes: WebView behavior

Layer / File(s) Summary
User-agent normalization and conversion
app/src/main/java/com/bansify/browser/browser/UserAgentUtils.kt, app/src/test/java/com/bansify/browser/UserAgentUtilsTest.kt
Adds helpers to normalize WebView user-agent markers, derive a desktop user agent, and detect WebView markers. Tests cover normalization and desktop conversion.
WebView settings and cookie behavior
app/src/main/java/com/bansify/browser/browser/WebViewPool.kt, docs/ARCHITECTURE.md
WebViewPool stores normalized device user agents and derives desktop user agents. Viewport settings follow desktop mode. Cookie acceptance follows the configured preference, and cookies flush after page completion. The architecture document describes these settings and cookie behavior.

Change: Bug fix

Merge Risk: Moderate · up to fd3b8

The change targets Cloudflare and Google challenge loops, but it lets private tabs share cookies with regular browsing and can leave some private cookies on disk after the last private tab closes. Resolve or explicitly accept the private-browsing privacy trade-off before merging. Mobile pages may also render differently because viewport-meta support is now off outside desktop mode.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.
@GothwadTech
GothwadTech merged commit 3c3d839 into main Nov 28, 2026
4 checks passed
@GothwadTech
GothwadTech deleted the fix/bot-verification branch November 28, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant