Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feed to isMalicious return type and update error page with feed info #5564

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

CrisBarreiro
Copy link
Contributor

@CrisBarreiro CrisBarreiro commented Jan 30, 2025

Task/Issue URL: https://app.asana.com/0/1205008441501016/1209270355529418/f

Description

Add feed to isMalicious return type and update error page with feed info

Steps to test this PR

Feature 1

Feature 2

UI changes

Before After
!(Upload before screenshot) (Upload after screenshot)

@CrisBarreiro CrisBarreiro force-pushed the feature/cris/malicious-site-protection/add-feed-to-return-type branch from b6d3050 to 31ef2ac Compare January 31, 2025 09:50
@CrisBarreiro CrisBarreiro marked this pull request as ready for review January 31, 2025 10:04
@CrisBarreiro CrisBarreiro force-pushed the feature/cris/malicious-site-protection/add-feed-to-return-type branch 3 times, most recently from 37a2b10 to d297727 Compare January 31, 2025 11:29
Base automatically changed from feature/cris/malicious-site-protection/error-page to develop January 31, 2025 11:39
@CrisBarreiro CrisBarreiro force-pushed the feature/cris/malicious-site-protection/add-feed-to-return-type branch from d297727 to 31c9560 Compare January 31, 2025 12:02
@CrisBarreiro CrisBarreiro force-pushed the feature/cris/malicious-site-protection/add-feed-to-return-type branch from 3948aaa to a2affdd Compare February 3, 2025 15:29
@CrisBarreiro CrisBarreiro mentioned this pull request Feb 3, 2025
5 tasks
Copy link
Contributor

@cmonfortep cmonfortep left a comment

Choose a reason for hiding this comment

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

LGTM
just few comments, nothin blocking.
Test cases worked fine. I've found an issue but unsure if related to changes here, so will share directly in Asana to triage.

PHISHING -> MaliciousSiteStatus.PHISHING
}
if (!exempted) {
loadingViewState.postValue(currentLoadingViewState().copy(isLoading = false, url = url.toString()))
Copy link
Contributor

Choose a reason for hiding this comment

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

I've noticed we dropped progress = 100 in the diff. Intended?

url: Uri?,
) {
if (isMalicious is Malicious) {
handleSiteBlocked(webViewClientListener, url, isMalicious.feed, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

So, if I get this right, we have false here as exempted because this is the async callback. And we should assume the synchronous logic already checks if it's exempted, so any exempted url will never land in the async callback. Can we leave a comment about that in this line?

The second question, it's to validate why we need to pass it down. I assume if a site is exempted, we don't block, but we want to update the omnibar logo, right?

filterSet.filters.firstOrNull {
Pattern.compile(it.regex).matcher(url.toString()).find()
}?.let {
Timber.d("\uD83D\uDFE2 Cris: shouldBlock $url")
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: do we have a Tag/Prefix you want to use from now on for logs? Probably better to start using it now, in case we forget to clean the logs with Cris.

Maybe just use MaliciousSiteDetector or MaliciousSite`?

val result = matches(hashPrefix, url, hostname, hash)?.let { feed: Feed ->
Malicious(feed)
} ?: Safe
confirmationCallback(result)
} catch (e: Exception) {
Timber.e(e, "\uD83D\uDD34 Cris: shouldBlock $url")
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@@ -78,6 +78,7 @@ data class MatchResponse(
val url: String,
val regex: String,
val hash: String,
val category: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we call them Feed but category here? which one is how we refer to these in the objective?

@@ -197,9 +242,12 @@ class RealMaliciousSiteBlockerWebViewIntegration @Inject constructor(
processedUrls.clear()
}

override fun onSiteExempted(url: Uri) {
override fun onSiteExempted(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add some test to this method? it seems they are missing. I was wondering about for example: what if url is not a valid URI?

val convertedUrl = URLDecoder.decode(url.toString(), "UTF-8").lowercase()
exemptedUrlsHolder.exemptedMaliciousUrls.add(convertedUrl)
exemptedUrlsHolder.exemptedMaliciousUrls.add(ExemptedUrl(convertedUrl.toUri(), feed))
Copy link
Contributor

Choose a reason for hiding this comment

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

why receiving an url: Uri -> decoding to Url -> and converting to Uri again?

@SingleInstanceIn(AppScope::class)
class ExemptedUrlsHolder @Inject constructor() {
val exemptedMaliciousUrls = mutableSetOf<String>()
val exemptedMaliciousUrls = mutableSetOf<ExemptedUrl>()
Copy link
Contributor

Choose a reason for hiding this comment

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

When checking how we use this, I don't see we ever check feed, only url. Do we have plans to differentiate exemptedUrls per feed?

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