mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-08-03 21:52:29 +02:00
Double Check Files/URLs (#1344)
This commit is contained in:
@@ -42,6 +42,19 @@ class WEB_CONNECTOR_VALID_SETTINGS(str, Enum):
|
||||
UPLOAD = "upload"
|
||||
|
||||
|
||||
def protected_url_check(url: str) -> None:
|
||||
parse = urlparse(url)
|
||||
if parse.scheme == "file":
|
||||
raise ValueError("Not permitted to read local files via Web Connector.")
|
||||
if (
|
||||
parse.scheme == "localhost"
|
||||
or parse.scheme == "127.0.0.1"
|
||||
or parse.hostname == "localhost"
|
||||
or parse.hostname == "127.0.0.1"
|
||||
):
|
||||
raise ValueError("Not permitted to read localhost urls.")
|
||||
|
||||
|
||||
def check_internet_connection(url: str) -> None:
|
||||
try:
|
||||
response = requests.get(url, timeout=3)
|
||||
@@ -189,6 +202,8 @@ class WebConnector(LoadConnector):
|
||||
continue
|
||||
visited_links.add(current_url)
|
||||
|
||||
protected_url_check(current_url)
|
||||
|
||||
logger.info(f"Visiting {current_url}")
|
||||
|
||||
try:
|
||||
|
Reference in New Issue
Block a user