fix(dnfs): review_content 兼容布尔/字符串审核结果,修复安全内容误拦
仅明确判定安全(布尔 false 或字符串 "false")才放行,其余一律拦截, 保持 fail-closed;同时消除 invalid 字段缺失时的 KeyError。
This commit is contained in:
1 parent
949d274c22
commit
e9f9860fe1
1 file changed
+2
-4
+2
-4
@@ -86,10 +86,8 @@ def review_content(content: str, timeout: int = 10) -> Dict[str, Any]:
|
|||||||
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
||||||
resp_data = resp.read().decode("utf-8")
|
resp_data = resp.read().decode("utf-8")
|
||||||
data = json.loads(resp_data)
|
data = json.loads(resp_data)
|
||||||
invalid: bool = data['invalid']
|
# 兼容布尔/字符串两种返回类型:仅明确判定安全才放行,其余一律拦截(fail-closed)
|
||||||
return invalid == False
|
return data.get('invalid') in (False, 'false')
|
||||||
#invalid = data
|
|
||||||
#return invalid
|
|
||||||
|
|
||||||
except urllib.error.HTTPError as e:
|
except urllib.error.HTTPError as e:
|
||||||
# 服务端返回 4xx/5xx 错误时,尝试解析错误正文
|
# 服务端返回 4xx/5xx 错误时,尝试解析错误正文
|
||||||
|
|||||||
Reference in new issue
Block a user