Skip to content

fix(security): abort WebView load on SSL certificate errors (CWE-295)#4

Open
jim-daf wants to merge 1 commit into
SaadAAkash:masterfrom
jim-daf:fix/security-issue-1
Open

fix(security): abort WebView load on SSL certificate errors (CWE-295)#4
jim-daf wants to merge 1 commit into
SaadAAkash:masterfrom
jim-daf:fix/security-issue-1

Conversation

@jim-daf
Copy link
Copy Markdown

@jim-daf jim-daf commented Apr 19, 2026

Security fix - issue #1 (CWE-295)

Resolves #1

Root cause

BkashPaymentActivity.initBkashWebViewClient overrides
onReceivedSslError and unconditionally calls handler.proceed():

override fun onReceivedSslError(view: WebView?, handler: SslErrorHandler, error: SslError?) {
    handler.proceed()
}

That tells the WebView to trust any certificate the server
presents - expired, self-signed, hostname-mismatched, or attacker-
issued. Because this Activity loads the bKash checkout flow, a network
attacker on the same Wi-Fi (coffee shop, hotel, hostile ISP) can MITM
the TLS connection and read or rewrite the payment request and
response. Google Play also flags this exact pattern and will warn /
block release uploads.

What this PR changes

One file, app/src/main/java/ninja/saad/bkashdemo/features/bkash/BkashPaymentActivity.kt:

  • onReceivedSslError now calls handler.cancel() instead of
    handler.proceed(), so the request is aborted whenever the
    certificate fails the platform's validation.

Why not show an "ignore?" dialog (the snippet from the issue)

The original issue suggests an AlertDialog asking the user whether
to continue. That is not appropriate for a payment screen: a
non-technical bKash customer faced with "Continue anyway?" will tap
yes, defeating the protection. The correct behaviour is to fail
closed; if a user really has a broken-clock or corporate-MITM
environment, they will see the connection fail and can take it up
with their network admin.

Scope

Only the SSL handler is touched. Existing JS interface, navigation
handling, and progress-bar logic are unchanged.

…mentActivity

WebViewClient.onReceivedSslError previously called handler.proceed(),
which accepts any invalid TLS certificate without verification
(CWE-295: Improper Certificate Validation). Because this WebView loads
the bKash checkout flow, a network attacker on the same network could
MITM the payment session and harvest credentials.

Replace handler.proceed() with handler.cancel() so the request is
dropped whenever the certificate fails platform validation.

Resolves SaadAAkash#1
@jim-daf jim-daf changed the title fix: secure SSL error handling in BkashPaymentActivity.kt fix(security): abort WebView load on SSL certificate errors (CWE-295) Apr 21, 2026
@jim-daf jim-daf force-pushed the fix/security-issue-1 branch from d8b13b6 to d08f4ae Compare April 21, 2026 21:11
@jim-daf jim-daf marked this pull request as ready for review April 21, 2026 21:12
Copilot AI review requested due to automatic review settings April 21, 2026 21:12
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses CWE-295 by changing the WebView SSL error handling in the bKash checkout flow to fail closed, preventing the app from proceeding on invalid TLS certificates during payment.

Changes:

  • Update onReceivedSslError to call handler.cancel() instead of handler.proceed().
  • Add inline security rationale documenting why the request must be aborted for payment flows.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 57 to 63
override fun onReceivedSslError(view: WebView?, handler: SslErrorHandler, error: SslError?) {
handler.proceed()
// CWE-295: do NOT proceed on invalid certificates. This is a
// payment WebView; silently trusting any cert (or even
// prompting the user) lets a network attacker MITM the
// checkout flow. Abort the request instead.
handler.cancel()
}
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After switching to handler.cancel(), the page load will be aborted on SSL errors, but this WebViewClient doesn’t handle the failure path (e.g., hide loadingProgressBar or show an error/finish the activity). Since onPageFinished won’t run, the progress bar can remain visible indefinitely and the user gets a stuck payment screen. Consider hiding the progress UI and presenting a clear failure state when onReceivedSslError triggers.

Copilot uses AI. Check for mistakes.
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.

Your app is using an unsafe implementation of WebViewClient.onReceivedSslError handler

2 participants