'bad file']); if (strpos($f, '..') !== false) json_out(400, ['error' => 'bad path']); // 只允许本站页面来取令牌,挡掉直接爬取。 // 优先看 Sec-Fetch-Site:由查看器页面发起的同源 fetch 恒为 same-origin(跨站 iframe // 嵌入也不受影响,且不会被父站点的 Referrer-Policy 剥掉);没有该头的旧浏览器 // 退回「Referer 含本站 host」的校验。直链/curl 两种都过不了。 $fetchSite = $_SERVER['HTTP_SEC_FETCH_SITE'] ?? ''; $referer = $_SERVER['HTTP_REFERER'] ?? ''; $host = $_SERVER['HTTP_HOST'] ?? ''; if ($fetchSite !== '') { if ($fetchSite !== 'same-origin' && $fetchSite !== 'same-site') json_out(403, ['error' => 'forbidden']); } elseif (!$host || strpos($referer, $host) === false) { json_out(403, ['error' => 'forbidden']); } $exp = time() + $TTL; $sig = substr(hash_hmac('sha256', $f . '|' . $exp, $SECRET), 0, 16); json_out(200, ['token' => $sig, 'expires' => $exp]);