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

Allow port numbers to be used in local host names. e.g. localhost:8888 #6448

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 21 additions & 25 deletions autogpts/forge/forge/sdk/abilities/web/web_selenium.py
Expand Up @@ -150,35 +150,31 @@ def check_local_file_access(url: str) -> bool:
Returns:
bool: True if the URL is a local file, False otherwise
"""
local_prefixes = [
# List of local file prefixes
local_file_prefixes = [
"file:///",
"file://localhost/",
"file://localhost",
"http://localhost",
"http://localhost/",
"https://localhost",
"https://localhost/",
"http://2130706433",
"http://2130706433/",
"https://2130706433",
"https://2130706433/",
"http://127.0.0.1/",
"http://127.0.0.1",
"https://127.0.0.1/",
"https://127.0.0.1",
"https://0.0.0.0/",
"https://0.0.0.0",
"http://0.0.0.0/",
"http://0.0.0.0",
"http://0000",
"http://0000/",
"https://0000",
"https://0000/",
]
return any(url.startswith(prefix) for prefix in local_prefixes)


if any(url.startswith(prefix) for prefix in local_file_prefixes):
return True

# Parse the URL
parsed = urlparse(url)

# List of local hostnames/IPs without considering ports
local_domains = [
"localhost",
"2130706433", # IP representation of 127.0.0.1
"127.0.0.1",
"0.0.0.0",
"0000" # Not sure what this is for, but keeping it as in original
]
# Check if the domain part of the URL is in local_domains
if parsed.hostname in local_domains:
return False # We don't restrict localhost access on different ports

# Return True for anything else that is deemed "local"
return True

logger = logging.getLogger(__name__)

Expand Down