Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(auth): add bounded timeout to WaterCrawl credential validation (#39824)

Chester4557f127ff46
diff --git a/api/services/auth/watercrawl/watercrawl.py b/api/services/auth/watercrawl/watercrawl.py
index ac8ec24d893..2b2dd20641c 100644
--- a/api/services/auth/watercrawl/watercrawl.py
+++ b/api/services/auth/watercrawl/watercrawl.py
@@ -6,6 +6,10 @@ import httpx
from services.auth.api_key_auth_base import ApiKeyAuthBase, AuthCredentials
+# Explicit bounded timeout for credential-validation requests so a slow or
+# hanging WaterCrawl endpoint cannot block the worker indefinitely.
+_CREDENTIAL_TIMEOUT = httpx.Timeout(10.0)
+
class WatercrawlAuth(ApiKeyAuthBase):
def __init__(self, credentials: AuthCredentials):
@@ -33,7 +37,7 @@ class WatercrawlAuth(ApiKeyAuthBase):
return {"Content-Type": "application/json", "X-API-KEY": self.api_key}
def _get_request(self, url, headers):
- return httpx.get(url, headers=headers)
+ return httpx.get(url, headers=headers, timeout=_CREDENTIAL_TIMEOUT)
def _handle_error(self, response):
if response.status_code in {402, 409, 500}:
diff --git a/api/tests/unit_tests/services/auth/test_watercrawl_auth.py b/api/tests/unit_tests/services/auth/test_watercrawl_auth.py
index 6d76d046874..c8bc8414cd1 100644
--- a/api/tests/unit_tests/services/auth/test_watercrawl_auth.py
+++ b/api/tests/unit_tests/services/auth/test_watercrawl_auth.py
@@ -77,6 +77,7 @@ class TestWatercrawlAuth:
mock_get.assert_called_once_with(
"https://app.watercrawl.dev/api/v1/core/crawl-requests/",
headers={"Content-Type": "application/json", "X-API-KEY": "test_api_key_123"},
+ timeout=httpx.Timeout(10.0),
)
@pytest.mark.parametrize(