修复:严格校验测试批次请求头

This commit is contained in:
焦龙言
2026-09-22 15:30:28 +08:00
parent 763ea1efcc
commit e396fff790
2 changed files with 8 additions and 4 deletions
@@ -14,10 +14,9 @@ def parse_optional_positive_batch_id(raw: str | None) -> int | None:
"""解析可选的测试批次请求头。"""
if raw is None:
return None
try:
batch_id = int(raw)
except (TypeError, ValueError):
raise ServiceWarning('', '测试批次标识必须为正整数') from None
if not isinstance(raw, str) or not raw or not raw.isascii() or not raw.isdigit():
raise ServiceWarning('', '测试批次标识必须为正整数')
batch_id = int(raw)
if batch_id <= 0:
raise ServiceWarning('', '测试批次标识必须为正整数')
return batch_id