From e9f9860fe177f6c9c5ced32f3cc2e86179bfd00c Mon Sep 17 00:00:00 2001 From: qing <1776177662@qq.com> Date: Thu, 30 Jul 2026 08:38:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(dnfs):=20review=5Fcontent=20=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E5=B8=83=E5=B0=94/=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E7=BB=93=E6=9E=9C=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=AE=89=E5=85=A8=E5=86=85=E5=AE=B9=E8=AF=AF=E6=8B=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 仅明确判定安全(布尔 false 或字符串 "false")才放行,其余一律拦截, 保持 fail-closed;同时消除 invalid 字段缺失时的 KeyError。 --- dnfs/dnfs.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/dnfs/dnfs.py b/dnfs/dnfs.py index d317e2c..cf10c37 100755 --- a/dnfs/dnfs.py +++ b/dnfs/dnfs.py @@ -85,11 +85,9 @@ def review_content(content: str, timeout: int = 10) -> Dict[str, Any]: try: with urllib.request.urlopen(req, timeout=timeout) as resp: resp_data = resp.read().decode("utf-8") - data = json.loads(resp_data) - invalid: bool = data['invalid'] - return invalid == False - #invalid = data - #return invalid + data = json.loads(resp_data) + # 兼容布尔/字符串两种返回类型:仅明确判定安全才放行,其余一律拦截(fail-closed) + return data.get('invalid') in (False, 'false') except urllib.error.HTTPError as e: # 服务端返回 4xx/5xx 错误时,尝试解析错误正文