feat: Update URL extraction to preserve case sensitivity (#2550)

Bug 2491, which stated that the URLs were being converted to lowercase, which potentially caused issues for URLs with uppercase characters.

Co-authored-by: Sai Prathik R <[email protected]>
This commit is contained in:
Sai Prathik R
2025-12-07 20:37:58 -08:00
committed by GitHub
co-authored by Sai Prathik R
parent 9b6e0f0fe4
commit e3e539cd59
3 changed files with 6 additions and 5 deletions
+4 -3
View File
@@ -27,17 +27,18 @@ logger = logging.getLogger(__name__)
def extract_urls_domains_emails(checksum, data):
"""Extract URLs, Domains and Emails."""
# URL Extraction
urls = re.findall(URL_REGEX, data.lower())
urls = re.findall(URL_REGEX, data)
if urls:
urls = list(set(urls))
else:
urls = []
# Domain Extraction and Malware Check
logger.info('Performing Malware check on extracted domains')
# For domain extraction, use lowercased URLs
domains = MalwareDomainCheck().scan(
checksum,
urls)
# Email Etraction Regex
[u.lower() for u in urls if isinstance(u, str)])
# Email Extraction Regex
emails = set()
for email in EMAIL_REGEX.findall(data.lower()):
if email.startswith('//'):
+1 -1
View File
@@ -55,7 +55,7 @@ URL_REGEX = re.compile(
r'file://|javascript:|data:|www\d{0,3}[.])'
r'[\w().=/;,#:@?&~*+!$%\'{}-]+)'
),
re.UNICODE)
re.UNICODE | re.IGNORECASE)
EMAIL_REGEX = re.compile(r'[\w+.-]{1,20}@[\w-]{1,20}\.[\w]{2,10}')
USERNAME_REGEX = re.compile(r'^\w[\w\-\@\.]{1,35}$')
GOOGLE_API_KEY_REGEX = re.compile(r'AIza[0-9A-Za-z-_]{35}$')
@@ -358,7 +358,7 @@ def url_n_email_extract(dat, relative_path):
url_n_file = []
email_n_file = []
# URL Extraction
urllist = URL_REGEX.findall(dat.lower())
urllist = URL_REGEX.findall(dat)
for url in urllist:
urls.add(url)
if urls: