pub trait TokenLog: Send + Sync {
// Required method
fn check_and_insert(
&self,
nonce: u128,
issued: SystemTime,
lifetime: Duration,
) -> Result<(), TokenReuseError>;
}展开描述
负责限制客户端复用校验 token 的能力
攻击者可以重放令牌以将服务器用作 DDoS 攻击中的放大器。为防御此类攻击,服务器必须确保令牌的回放被阻止或受限。服务器应当确保 Retry 数据包中发送的令牌仅在短时间内被接受,因为它们会被立即返回 by clients. Tokens that are provided in NEW_TOKEN frames (Section 19.7) need to be valid for longer but SHOULD NOT be accepted multiple times. Servers are encouraged to allow tokens to be used only once, if possible; tokens MAY include additional information about clients to further narrow applicability or reuse.
TokenLog 仅涉及 NEW_TOKEN 帧中提供的令牌。
必需方法§
源代码fn check_and_insert(
&self,
nonce: u128,
issued: SystemTime,
lifetime: Duration,
) -> Result<(), TokenReuseError>
fn check_and_insert( &self, nonce: u128, issued: SystemTime, lifetime: Duration, ) -> Result<(), TokenReuseError>
记录该令牌已被使用,并在理想情况下当令牌可能曾被使用时返回令牌重用错误
误报与漏报都是允许的。在客户端使用地址验证令牌时调用。
参数:
nonce:服务器为该令牌生成的随机唯一值。issued:服务器签发该令牌的时间。lifetime:通过 NEW_TOKEN 帧发送的地址验证令牌的过期时间,由ServerValidationTokenConfig::lifetime配置。
§安全与性能
在攻击者能够反复触发漏报(即对已被重用的令牌仍返回 Ok)的范围内,攻击者可能借此对服务器发起 放大攻击。QUIC 规范要求将该风险限制在一定范围内,即使不能完全避免。
误报(对从未被使用过的令牌返回 Err)并非安全漏洞;TokenLog 始终返回 Err 也是允许的。误报会导致该令牌被忽略,从而使部分 0.5-RTT 数据——若已发送了足够多的 0.5-RTT 数据——需要等到握手完成后才能继续传输。