校验request id,避免可能存在的注入攻击风险
This commit is contained in:
parent
d720fb8c70
commit
d511241fcf
@ -37,8 +37,8 @@ fn init() -> Router {
|
|||||||
.get("x-request-id")
|
.get("x-request-id")
|
||||||
.and_then(|value| value.to_str().ok())
|
.and_then(|value| value.to_str().ok())
|
||||||
{
|
{
|
||||||
Some(v) => v.to_string(),
|
Some(v) if v.chars().all(|c| c.is_alphanumeric()) => v.to_string(),// 确保请求ID只包含字母和数字
|
||||||
None => String::from("unknown"),
|
_ => String::from("unknown"),
|
||||||
};
|
};
|
||||||
tracing::error_span!("request_id", id = req_id)
|
tracing::error_span!("request_id", id = req_id)
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user