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

(bug) Fix subdomain import for subdomains with suffix more than 4 chars Fixes #1128 #1340

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions web/reNgine/common_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,29 @@ def get_domain_from_subdomain(subdomain):
Returns:
str: Domain name.
"""
ext = tldextract.extract(subdomain)
return '.'.join(ext[1:3])
# ext = tldextract.extract(subdomain)
# return '.'.join(ext[1:3])

if not validators.domain(subdomain):
return None

# Use tldextract to parse the subdomain
extracted = tldextract.extract(subdomain)

# if tldextract recognized the tld then its the final result
if extracted.suffix:
domain = f"{extracted.domain}.{extracted.suffix}"
else:
# Fallback method for unknown TLDs, like .clouds or .local etc
parts = subdomain.split('.')
if len(parts) >= 2:
domain = '.'.join(parts[-2:])
else:
return None

# Validate the domain before returning
return domain if validators.domain(domain) else None



def sanitize_url(http_url):
Expand Down
Loading