sync update from LAN repo (source dhk-1 @ 3e87be55)

This commit is contained in:
gozeros committed 2026-10-21 15:06:08 +08:00
1 parent ab6068a7c1
commit 42f2a26fa8
1482 files changed
+227759 -9584

No files matched your search

@@ -11,6 +11,7 @@ Fine-grained permission checks remain in authz.py decorators.
import hashlib
import hmac
import os
import re
from collections.abc import Callable
@@ -109,6 +110,33 @@ def _authorize_external_llmwiki(request: Request) -> JSONResponse | None:
supplied.encode("utf-8")
).hexdigest()[:8]
return None
def _is_task_deeplink_external_write(request: Request, path: str) -> bool:
"""Whether this is the narrow key-authenticated integration write path."""
return request.method.upper() == "PUT" and path.startswith("/api/task-deeplink-details/")
def _authorize_task_deeplink_external_write(request: Request) -> JSONResponse | None:
"""Authorize the external system that stores b5-1 task details.
Browser reads still follow the normal login path. The key is only accepted
for PUT and only when explicitly configured, so an accidentally supplied
header can never weaken normal API authentication.
"""
supplied = request.headers.get("X-Integration-Key", "")
if not supplied:
return None
configured = os.getenv("DEERFLOW_TASK_DEEPLINK_INGEST_KEY", "")
if not configured or not hmac.compare_digest(supplied, configured):
return JSONResponse(status_code=401, content={"detail": "Invalid integration key"})
request.state.task_deeplink_external_writer = True
request.state.task_deeplink_external_key_fingerprint = hashlib.sha256(
supplied.encode("utf-8")
).hexdigest()[:8]
return None
def _is_weknora_embed_proxy_request(request: Request) -> bool:
@@ -171,6 +199,12 @@ class AuthMiddleware(BaseHTTPMiddleware):
if _is_external_llmwiki(relative_path):
rejected = _authorize_external_llmwiki(request)
return rejected if rejected is not None else await call_next(request)
if _is_task_deeplink_external_write(request, relative_path):
rejected = _authorize_task_deeplink_external_write(request)
if rejected is not None:
return rejected
if getattr(request.state, "task_deeplink_external_writer", False):
return await call_next(request)
if _is_public(relative_path):
return await call_next(request)
if _is_weknora_embed_proxy_request(request):