Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d1b0010 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal Committed by Jonathan Klee
Browse files

apps: enable safeBrowsingEnabled and scope OAuth credential capture to trusted host

parent 209f43ec
Loading
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -17,9 +17,16 @@

package foundation.e.apps.feature.auth.login

import java.net.URI

internal object GoogleOAuthCredentialsExtractor {
    const val EMBEDDED_SETUP_URL = "https://accounts.google.com/EmbeddedSetup"
    private const val AUTH_TOKEN_COOKIE = "oauth_token"
    private val ALLOWED_HOSTS = setOfNotNull(URI(EMBEDDED_SETUP_URL).host)

    fun isAllowedHost(host: String?): Boolean {
        return host != null && host in ALLOWED_HOSTS
    }

    fun extractOauthToken(cookieHeader: String?): String? {
        if (cookieHeader.isNullOrBlank()) {
+5 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.net.toUri
import foundation.e.apps.feature.auth.login.GoogleOAuthCredentialsExtractor
import foundation.e.apps.feature.auth.login.LoginOauthToken

@@ -106,7 +107,6 @@ private fun WebView.configureGoogleOAuthWebView(
    cookieManager.acceptThirdPartyCookies(this)
    cookieManager.setAcceptThirdPartyCookies(this, true)

    settings.safeBrowsingEnabled = false
    settings.apply {
        allowContentAccess = true
        cacheMode = WebSettings.LOAD_DEFAULT
@@ -116,6 +116,10 @@ private fun WebView.configureGoogleOAuthWebView(

    webViewClient = object : WebViewClient() {
        override fun onPageFinished(view: WebView, url: String) {
            if (!GoogleOAuthCredentialsExtractor.isAllowedHost(url.toUri().host)) {
                return
            }

            val oauthToken = GoogleOAuthCredentialsExtractor.extractOauthToken(
                CookieManager.getInstance().getCookie(url),
            )