From 9c6113d671ccbab1e7a1d110847247f07dbb5a2b Mon Sep 17 00:00:00 2001 From: udhayarajan Date: Tue, 27 Jun 2023 10:36:13 +0530 Subject: [PATCH] fix(Facebook): cookie validation --- build.gradle.kts | 2 +- .../mugames/vidsnapkit/extractor/Facebook.kt | 24 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 56434690..66fb26f8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -27,7 +27,7 @@ plugins { } group = "io.github.udhayarajan" -version = "5.3.15" +version = "5.3.16" //Version Naming incremented if ".." //Priority on incrementing Feature > BugFix > Beta diff --git a/src/commonMain/kotlin/com/mugames/vidsnapkit/extractor/Facebook.kt b/src/commonMain/kotlin/com/mugames/vidsnapkit/extractor/Facebook.kt index f1606235..da4323b6 100644 --- a/src/commonMain/kotlin/com/mugames/vidsnapkit/extractor/Facebook.kt +++ b/src/commonMain/kotlin/com/mugames/vidsnapkit/extractor/Facebook.kt @@ -21,6 +21,8 @@ import com.mugames.vidsnapkit.* import com.mugames.vidsnapkit.Util.Companion.decodeHTML import com.mugames.vidsnapkit.dataholders.* import com.mugames.vidsnapkit.network.HttpRequest +import io.ktor.client.statement.* +import io.ktor.http.* import org.json.JSONArray import org.json.JSONException import org.json.JSONObject @@ -46,14 +48,22 @@ class Facebook internal constructor(url: String) : Extractor(url) { private suspend fun isCookieValid(): Boolean { if (cookies.isNullOrEmpty()) return false - val res = HttpRequest("https://www.facebook.com/", headers).getResponse(false) ?: return false - val restrictedKeywords = listOf("Create new account", "log in or sign up", "Forgotten password") - val containsRestrictedKeyword = restrictedKeywords.any { keyword -> - res.contains(keyword, ignoreCase = true) + val res = HttpRequest("https://www.facebook.com/", headers).getRawResponse(false) ?: return false + if (res.status == HttpStatusCode.OK) { + val restrictedKeywords = listOf("Create new account", "log in or sign up", "Forgotten password") + val containsRestrictedKeyword = restrictedKeywords.any { keyword -> + res.bodyAsText().contains(keyword, ignoreCase = true) + } + logger.info("Check cookie containsRestrictedKeyword=${containsRestrictedKeyword} ") + return !containsRestrictedKeyword } - - logger.info("Check cookie containsRestrictedKeyword=${containsRestrictedKeyword} ") - return !containsRestrictedKeyword + if (res.status == HttpStatusCode.Found){ + logger.info("Oops! redirection found for ${res.headers["location"]}") + if (res.call.request.url.toString().contains("checkpoint")){ + return false + } + } + return true } override suspend fun analyze(payload: Any?) {