因此,在我的网站 (https://example.com) 上,我有一个页面可以解析 last.fm API 并从他们的 akamai CDN 中提取图像并将它们显示在页面上。
问题是所有图像都仅在 HTTP 上提供,不支持 https。
例如:http ://userserve-ak.last.fm/serve/64s/76030502.png
我有一个用 php 编写的图像代理:
<?php
header('Content-Type: image/png');
if(isset($_GET['img'])){echo file_get_contents($_GET['img']);}
?>
这完美地工作,但是,根本不安全,我想要它,以便只有我的服务器可以使用图像代理,因此 URL 中的哈希可能是最好的选择?
https://example.com/proxy.php?url=http://last.fm/image.jpg&hash=hashhere
我曾想过使用:
md5($_GET['img']."privatekeyhere");
然后我的问题转向了,如何在全世界都无法访问的情况下将私钥放入 javascript 代码中?
非常感谢任何帮助。
从那以后,我编写了这个脚本,它有点有效,但仍然可以被规避:
<?php
$args = $_GET['q'];
$date = date('m-d-Y-h-i', time());
list($hash,$img,$auth) = explode("/", $args);
if($hash=="need" && $auth=="key"){
$checksum = md5($img.$date);
echo $checksum;
}
if($hash==md5($img.$date))
{
header('Content-Type: image/png');
echo file_get_contents('http://userserve-ak.last.fm/serve/64s/' . $img);
}
?>
这可以这样调用:https://www.mylesgray.com/lastfm/need/76030502.png/key
然后可以插入身份验证代码以显示图像:https://www.mylesgray.com/lastfm/{code-here}/76030502.png
然而,很快就会有人发现他们可以设置一个脚本来每分钟轮询一个密钥——有什么建议吗?