校验request id,避免可能存在的注入攻击风险

This commit is contained in:
李运家 2024-10-31 19:58:58 +08:00
parent d720fb8c70
commit d511241fcf

View File

@ -37,8 +37,8 @@ fn init() -> Router {
.get("x-request-id")
.and_then(|value| value.to_str().ok())
{
Some(v) => v.to_string(),
None => String::from("unknown"),
Some(v) if v.chars().all(|c| c.is_alphanumeric()) => v.to_string(),// 确保请求ID只包含字母和数字
_ => String::from("unknown"),
};
tracing::error_span!("request_id", id = req_id)
});