Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.app.Activity
import android.annotation.SuppressLint
import android.app.Dialog
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.Intent.ACTION_VIEW
import android.content.Intent.CATEGORY_BROWSABLE
Expand All @@ -17,6 +18,7 @@ import android.provider.MediaStore
import android.view.ViewTreeObserver
import android.webkit.CookieManager
import android.webkit.GeolocationPermissions
import android.webkit.JavascriptInterface
import android.webkit.PermissionRequest
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
Expand All @@ -39,6 +41,7 @@ import one.mixin.android.databinding.FragmentWebBottomSheetBinding
import one.mixin.android.extension.REQUEST_CAMERA
import one.mixin.android.extension.createImageTemp
import one.mixin.android.extension.getOtherPath
import one.mixin.android.extension.isCustomerServiceUrl
import one.mixin.android.extension.isExternalTransferUrl
import one.mixin.android.extension.isLightningUrl
import one.mixin.android.extension.isMixinUrl
Expand All @@ -48,12 +51,15 @@ import one.mixin.android.extension.openPermissionSetting
import one.mixin.android.extension.toUri
import one.mixin.android.extension.toast
import one.mixin.android.extension.withArgs
import one.mixin.android.session.Session
import one.mixin.android.ui.conversation.web.PermissionBottomSheetDialogFragment
import one.mixin.android.ui.conversation.web.PermissionBottomSheetDialogFragment.Companion.PERMISSION_AUDIO
import one.mixin.android.ui.conversation.web.PermissionBottomSheetDialogFragment.Companion.PERMISSION_VIDEO
import one.mixin.android.ui.url.UrlInterpreterActivity
import one.mixin.android.ui.web.WebFragment
import one.mixin.android.util.rxpermission.RxPermissions
import one.mixin.android.util.viewBinding
import one.mixin.android.vo.generateConversationId
import one.mixin.android.web3.convertWcLink
import one.mixin.android.widget.BottomSheet
import timber.log.Timber
Expand Down Expand Up @@ -181,6 +187,9 @@ class WebBottomSheetDialogFragment : MixinBottomSheetDialogFragment() {
}
}
webViewClient = BottomSheetWebViewClient()
if (isCustomerServiceUrl(this@WebBottomSheetDialogFragment.url)) {
addJavascriptInterface(SupportWebAppInterface(context), "MixinContext")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restrict the context bridge to the support origin

When the support page embeds an iframe or follows a normal HTTP(S) link, this JavaScript interface remains exposed because BottomSheetWebViewClient allows every HTTP(S) URL to load in the same WebView and the bridge is removed only during destruction. Such third-party content can therefore call MixinContext.getContext() and obtain the user's stable, account-derived support conversation identifier. Restrict HTTP(S) navigation to the customer-service origin or remove/use an origin-scoped bridge before loading any other origin.

Useful? React with 馃憤聽/ 馃憥.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it's ok

}
setDownloadListener { url, _, _, _, _ ->
runCatching {
startActivity(
Expand Down Expand Up @@ -223,13 +232,22 @@ class WebBottomSheetDialogFragment : MixinBottomSheetDialogFragment() {
return rect.height()
}

class SupportWebAppInterface(private val context: Context) {
@JavascriptInterface
fun getContext(): String? {
val conversationId = Session.getAccountId()?.let { generateConversationId(it, Constants.TEAM_MIXIN_USER_ID) }
return WebFragment.WebAppInterface(context, conversationId, false).getContext()
}
}

override fun onDestroyView() {
if (contentView.viewTreeObserver.isAlive) {
contentView.viewTreeObserver.removeOnGlobalLayoutListener(keyboardLayoutListener)
}
bottomSheet = null
binding.webView.apply {
stopLoading()
removeJavascriptInterface("MixinContext")
webChromeClient = null
webViewClient = WebViewClient()
loadUrl("about:blank")
Expand Down
Loading