Skip to content

fix(Web3TokenView): only enable WebView contents debugging in debug builds (refs #2323)#3439

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

fix(Web3TokenView): only enable WebView contents debugging in debug builds (refs #2323)#3439
jim-daf wants to merge 1 commit into
AlphaWallet:masterfrom
jim-daf:fix/security-issue-2323

Conversation

@jim-daf
Copy link
Copy Markdown

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

Restrict WebContentsDebuggingEnabled to debug builds (refs #2323)

What this PR does is fix the most concrete security smell that exists
in the same file the original draft was touching.

The concrete problem

app/src/main/java/com/alphawallet/app/web3/Web3TokenView.java:

WebView.setWebContentsDebuggingEnabled(true);

is called unconditionally inside init(). That setting is process-wide
on Android and remains active in release builds. Combined with the fact
that Web3TokenView is the WebView that runs TokenScript / dapp
JavaScript inside a wallet, i.e. a process that signs transactions
and holds key material in memory, it lets anyone with USB access on a
production device attach chrome://inspect and read the page's DOM and
JS state. CWE-489 (Active Debug Code).

MetaMask, Trust Wallet, and every other audited Android wallet gate
this call behind BuildConfig.DEBUG.

The fix

WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG);

BuildConfig is already imported in the file, so this is a one-line
behavioral change. No other functionality is altered.

…uilds (AlphaWallet#2323)

Refs AlphaWallet#2323

Web3TokenView.init() unconditionally calls
`WebView.setWebContentsDebuggingEnabled(true)`, which leaves the in-app
WebView attachable from `chrome://inspect` on any device with USB
debugging enabled — including release builds installed on end-user
devices. Because Web3TokenView is the surface that runs TokenScript /
dapp JavaScript inside a *wallet* application, that is a CWE-489
exposure of session content for a process that signs transactions.

Gate the call behind `BuildConfig.DEBUG` so contents debugging is only
available in developer builds. This matches the practice used by
MetaMask, Trust Wallet, and other audited Android wallet apps.

This change does *not* address the larger refactor requested in AlphaWallet#2323
(replacing the legacy provider with a MetaMask-style one); that work is
left tracked by the issue.
@jim-daf jim-daf changed the title fix: secure JavaScript interface in Web3TokenView.java fix(Web3TokenView): only enable WebView contents debugging in debug builds (refs #2323) Apr 21, 2026
@jim-daf jim-daf force-pushed the fix/security-issue-2323 branch from 893083a to dcbabab Compare April 21, 2026 20:16
@jim-daf jim-daf marked this pull request as ready for review April 21, 2026 20:52
@jim-daf jim-daf requested a review from JamesSmartCell as a code owner April 21, 2026 20:52
Copilot AI review requested due to automatic review settings April 21, 2026 20:52
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

Restricts Android WebView contents debugging to debug builds for Web3TokenView, reducing exposure of TokenScript/dapp runtime state in production.

Changes:

  • Gate WebView.setWebContentsDebuggingEnabled(...) behind BuildConfig.DEBUG.
  • Add an inline security rationale comment referencing CWE-489 and the impact on wallet WebView state.

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

Comment on lines +126 to +130
// CWE-489: Web3TokenView holds session JS for a wallet that signs
// transactions. Leaving WebView contents debuggable in release builds
// lets anyone with USB access attach chrome://inspect and read the
// page's DOM/JS. Restrict to debug builds only.
WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG);
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.

WebView.setWebContentsDebuggingEnabled(...) is process-wide. Even though this call is now gated by BuildConfig.DEBUG, there is still an unconditional WebView.setWebContentsDebuggingEnabled(true) in app/src/main/java/com/alphawallet/app/web3/Web3View.java (around line 190) which is used by production layouts (e.g. fragment_webview.xml). That means release builds can still end up with WebView debugging enabled, defeating the security goal described in the comment. Consider gating/removing the other call sites as well (or centralizing this setting so it can’t be re-enabled in release).

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.

2 participants