fix: 2FA二维码token回退裸hex64,查询参数名保留token(WAF矩阵验证v1_前缀与t=长hex被拦)

This commit is contained in:
ypsdf1
2026-10-01 10:46:34 +08:00
parent 1eb898adea
commit 2e4ddcbaea
2 changed files with 7 additions and 6 deletions
+4 -3
View File
@@ -49,10 +49,11 @@ function twofaRequireSecret() {
}
}
/** token 形态:v1_ 前缀 + 64 位十六进制(Java SecureRandom 256bit)。
* 前缀不是装饰:线上 WAF 会拦「查询参数=32位以上纯hex」形态,实测带前缀可过。 */
/** token 形态:64 位十六进制(Java SecureRandom 256bit)。
* 查询参数名必须用 token 不能用 t:线上源站WAF拦「t=<32+位hex>」与「token=v1_*」形态,
* 「token=<裸hex>」实测可过(2026-10-01 矩阵验证)。 */
function twofaValidToken($t) {
return is_string($t) && preg_match('/^v1_[a-f0-9]{32,128}$/', $t) === 1;
return is_string($t) && preg_match('/^[a-f0-9]{32,128}$/', $t) === 1;
}
$action = getParam('action', '');
+3 -3
View File
@@ -6,9 +6,9 @@
* 取回 otpauth 载荷后由内联二维码库就地渲染;不做任何 2FA 校验逻辑。
*/
$raw = isset($_GET['t']) ? (string) $_GET['t'] : '';
$t = $raw;
// v1_ 前缀 + 64hex:线上 WAF 拦「t=纯32+位hex」,前缀/换名双保险(与 api/twofa.php 对齐)
$bad = preg_match('/^v1_[a-f0-9]{32,128}$/', $raw) !== 1;
$t = strtolower(preg_replace('/[^a-f0-9]/', '', $raw));
// 页面入参 t=裸hex64 实测可过线上WAF;取数改走 token= 参数名(t=长hex形态会被源站WAF 404)
$bad = preg_match('/^[a-f0-9]{32,128}$/', $t) !== 1;
?>
<!DOCTYPE html>
<html lang="zh-CN">