dongtan7418 2016-05-06 03:38
浏览 199
已采纳

AWS Cloudfront Signed Cookie无法在备用域上运行

Problem

I have Access Denied for GET request to cloudfront with signed cookies using both canned and custom policy.

Details

  1. cdn.example.com is the alternate domain of abc.cloudfront.net, and CNAME is set on both cloudfront and cloudflare.
  2. I expect after abc.example.com/authorize, cdn.example.com is accessible.
  3. I am using PHP with Laravel behind abc.example.com/authroize, and the code is as follows.

```

$cloudFront = new Aws\CloudFront\CloudFrontClient([
    'region'  => 'us-west-2',
    'version' => '2014-11-06'
]);

$resourceKey = 'http://cdn.example.com';
$expires = time() + 300;

$signedCookieCannedPolicy = $cloudFront->getSignedCookie([
        'url'         => $resourceKey,
        'expires'     => $expires,
        'private_key' => 'pk.pem',
        'key_pair_id' => 'XXXXXXXXXXXXXX',
]);

$response = Response::success();
foreach ($signedCookieCannedPolicy as $name => $value) {
    $response->withCookie(Cookie::make($name, $value, 360, null, 'example.com'));
}

return $response;

```

  1. The cookies are set for .example.com

enter image description here

  1. When I go to cdn.example.com, the following message is shown

enter image description here

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • drjv5597 2016-10-20 07:16
    关注

    Turns out the issue was due to the encrypted cookies. You might want to check: https://laravel.com/api/5.2/Illuminate/Cookie/CookieJar.html#method_make And if you are using Laravel 5.2, make sure you added exception if you used middleware to encrypt.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊