Skip to content

Commit

Permalink
fix safe mode
Browse files Browse the repository at this point in the history
  • Loading branch information
polstianka committed Nov 18, 2024
1 parent ec6edba commit 714d295
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SafeModeClient(

fun isHasScamUris(vararg uris: Uri): Boolean {
for (uri in uris) {
if (uri == Uri.EMPTY) {
if (uri == Uri.EMPTY || uri.scheme != "https") {
continue
}
var host = uri.host ?: continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,10 @@ class TonConnectManager(
fromPackageName = fromPackageName
)

if (isScam(context, uri, normalizedUri, tonConnect.manifestUrl.toUri())) {
return null
}

safeModeClient.isReadyFlow.take(1).onEach {
connectRemoteApp(activity, tonConnect)
if (!isScam(context, uri, normalizedUri, tonConnect.manifestUrl.toUri())) {
connectRemoteApp(activity, tonConnect)
}
}.launchIn(scope)
return null
} catch (e: Exception) {
Expand Down Expand Up @@ -275,6 +273,10 @@ class TonConnectManager(
val clientId = tonConnect.clientId
try {
val app = readManifest(tonConnect.manifestUrl)
if (isScam(activity, app.iconUrl.toUri(), app.url)) {
return@withContext JsonBuilder.connectEventError(BridgeError.badRequest("client error"))
}

val screen = TonConnectScreen.newInstance(
app = app,
proofPayload = tonConnect.proofPayload,
Expand Down Expand Up @@ -325,9 +327,11 @@ class TonConnectManager(
}
}

fun isScam(context: Context, vararg uris: Uri): Boolean {
suspend fun isScam(context: Context, vararg uris: Uri): Boolean {
if (settingsRepository.isSafeModeEnabled() && safeModeClient.isHasScamUris(*uris)) {
TonConnectSafeModeDialog(context).show()
withContext(Dispatchers.Main) {
TonConnectSafeModeDialog(context).show()
}
return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.webkit.WebResourceRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.tonapps.tonkeeper.ui.screen.browser.search

import android.app.Application
import android.net.Uri
import android.util.Log
import com.tonapps.extensions.MutableEffectFlow
import com.tonapps.network.get
import com.tonapps.tonkeeper.ui.base.BaseWalletVM
Expand Down Expand Up @@ -72,6 +73,9 @@ class BrowserSearchViewModel(
if (isDomain(query)) {
return Uri.parse("https://$query")
}
if (query.startsWith("http://")) {
return uri(query.replace("http://", "https://"))
}
return try {
val uri = Uri.parse(query)
if (uri.scheme != "https") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.tonapps.tonkeeper.ui.screen.settings.security.SecurityScreen
import com.tonapps.tonkeeperx.R
import uikit.dialog.modal.ModalDialog
import uikit.navigation.Navigation
import uikit.widget.HeaderView
import uikit.widget.ModalHeader

class TonConnectSafeModeDialog(context: Context): ModalDialog(context, R.layout.dialog_tonconnect_safemode) {

Expand All @@ -15,7 +15,7 @@ class TonConnectSafeModeDialog(context: Context): ModalDialog(context, R.layout.
}

init {
findViewById<HeaderView>(R.id.header)!!.doOnCloseClick = { dismiss() }
findViewById<ModalHeader>(R.id.header)!!.onCloseClick = { dismiss() }
findViewById<View>(R.id.open_settings)!!.setOnClickListener {
dismiss()
navigation?.add(SecurityScreen.newInstance())
Expand Down

0 comments on commit 714d295

Please sign in to comment.