mirror of
https://github.com/langgenius/dify.git
synced 2026-10-04 13:47:55 +08:00
fix(api): skip unrelated bodies in app access error hook
This commit is contained in:
1 parent
e4a2c433ea
commit
4e1b63cda1
2 files changed
+100
-3
No files matched your search
@@ -53,16 +53,34 @@ def register_app_access_error_metadata(blueprint: Blueprint, *, surface: Literal
|
||||
|
||||
@blueprint.after_request
|
||||
def add_app_access_error_metadata(response: Response) -> Response:
|
||||
# Most responses cannot be changed by this hook. Avoid decoding successful
|
||||
# payloads (including large application data) or unrelated error bodies.
|
||||
status = response.status_code
|
||||
if status != 404 and (surface != "web" or status not in (400, 403)):
|
||||
return response
|
||||
if response.is_streamed or response.direct_passthrough or not response.is_json or request.url_rule is None:
|
||||
return response
|
||||
|
||||
rule = request.url_rule.rule
|
||||
is_app_identity = request.method == "GET" and rule in identity_rules
|
||||
is_hitl = rule.startswith((prefix + "/form/human_input/", prefix + "/human-input-forms/"))
|
||||
if is_hitl:
|
||||
if surface != "web" or not (
|
||||
(status == 404 and rule.startswith(prefix + "/form/human_input/"))
|
||||
or (status == 403 and rule == prefix + "/human-input-forms/files")
|
||||
):
|
||||
return response
|
||||
elif status != 404 and not (surface == "web" and status == 400 and is_app_identity):
|
||||
return response
|
||||
|
||||
# Non-HITL 404s still need inspection outside the identity allowlist:
|
||||
# typed app_not_found errors can originate from invocation/resource routes.
|
||||
payload = response.get_json(silent=True)
|
||||
if not isinstance(payload, dict):
|
||||
return response
|
||||
rule = request.url_rule.rule
|
||||
# Preserve HITL's dedicated expiry/token UI and do not expose an App IP
|
||||
# or policy-specific marker through these capability endpoints.
|
||||
if rule.startswith((prefix + "/form/human_input/", prefix + "/human-input-forms/")):
|
||||
if is_hitl:
|
||||
if (
|
||||
surface == "web"
|
||||
and rule.startswith(prefix + "/form/human_input/")
|
||||
@@ -81,7 +99,6 @@ def register_app_access_error_metadata(blueprint: Blueprint, *, surface: Literal
|
||||
{"code": "invalid_upload_token", "message": "Upload token is invalid or expired.", "status": 403},
|
||||
)
|
||||
return response
|
||||
is_app_identity = request.method == "GET" and request.url_rule.rule in identity_rules
|
||||
if (
|
||||
surface == "web"
|
||||
and is_app_identity
|
||||
|
||||
Reference in new issue
Block a user