Skip to content

Commit 893706f

Browse files
authored
Merge pull request #2982 from python-discord/vivek/fix-phishing-button
Fix case sensitivity bug in phishing button
2 parents dfb5800 + 1780886 commit 893706f

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

bot/exts/filtering/_filter_lists/domain.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
if typing.TYPE_CHECKING:
1414
from bot.exts.filtering.filtering import Filtering
1515

16-
URL_RE = re.compile(r"https?://(\S+)", flags=re.IGNORECASE)
16+
# Matches words that start with the http(s) protocol prefix
17+
# Will not include, if present, the trailing closing parenthesis
18+
URL_RE = re.compile(r"https?://(\S+)(?=\)|\b)", flags=re.IGNORECASE)
1719

1820

1921
class DomainsList(FilterList[DomainFilter]):
@@ -56,7 +58,7 @@ async def actions_for(
5658

5759
triggers = await self[ListType.DENY].filter_list_result(new_ctx)
5860
ctx.notification_domain = new_ctx.notification_domain
59-
unknown_urls = urls - {filter_.content for filter_ in triggers}
61+
unknown_urls = urls - {filter_.content.lower() for filter_ in triggers}
6062
if unknown_urls:
6163
ctx.potential_phish[self] = unknown_urls
6264

bot/exts/filtering/_ui/ui.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from pydis_core.utils import scheduling
1717
from pydis_core.utils.logging import get_logger
1818
from pydis_core.utils.members import get_or_fetch_member
19+
from pydis_core.utils.regex import DISCORD_INVITE
1920

2021
import bot
2122
from bot.constants import Colours
@@ -617,6 +618,10 @@ class AlertView(discord.ui.View):
617618
def __init__(self, ctx: FilterContext, triggered_filters: dict[FilterList, list[str]] | None = None):
618619
super().__init__(timeout=ALERT_VIEW_TIMEOUT)
619620
self.ctx = ctx
621+
if "banned" in self.ctx.action_descriptions:
622+
# If the user has already been banned, do not attempt to add phishing button since the URL or guild invite
623+
# is probably already added as a filter
624+
return
620625
phishing_content, target_filter_list = self._extract_potential_phish(triggered_filters)
621626
if phishing_content:
622627
self.add_item(PhishHandlingButton(ctx.author, phishing_content, target_filter_list))
@@ -681,12 +686,14 @@ def _extract_potential_phish(
681686
if len(content_list) > 1:
682687
return "", None
683688
if content_list:
684-
content = next(iter(content_list))
685-
if filter_list.name == "domain" and "discord" in content: # Leave invites to the invite filterlist.
689+
current_content = next(iter(content_list))
690+
if filter_list.name == "domain" and re.fullmatch(DISCORD_INVITE, current_content):
691+
# Leave invites to the invite filterlist.
686692
continue
687693
if encountered:
688694
return "", None
689695
target_filter_list = filter_list
696+
content = current_content
690697
encountered = True
691698

692699
if encountered:

0 commit comments

Comments
 (0)