fix(dnfs): review_content 兼容布尔/字符串审核结果,修复安全内容误拦
仅明确判定安全(布尔 false 或字符串 "false")才放行,其余一律拦截, 保持 fail-closed;同时消除 invalid 字段缺失时的 KeyError。
This commit is contained in:
1 parent
949d274c22
commit
e9f9860fe1
1 file changed
+3
-5
+3
-5
@@ -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 错误时,尝试解析错误正文
|
||||
|
||||
Reference in new issue
Block a user