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 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?