【问题标题】:AWS Cloudfront Signed Cookie not working on alternate domainAWS Cloudfront 签名 Cookie 在备用域上不起作用
【发布时间】:2017-08-16 17:00:03
【问题描述】:

问题

我有 Access Denied 向云端发出 GET 请求,其中包含使用预设和自定义策略的签名 cookie。

详情

  1. cdn.example.comabc.cloudfront.net 的备用域,CNAME 设置在 cloudfront 和 cloudflare 上。
  2. 我希望在abc.example.com/authorize 之后,cdn.example.com 可以访问。
  3. 我在abc.example.com/authroize后面用的是PHP和Laravel,代码如下。

```

$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. cookies 设置为.example.com

  1. 当我转到cdn.example.com 时,显示以下消息

提前致谢。

【问题讨论】:

  • 你发现了吗?有同样的问题
  • 如果我没记错的话,问题是由于加密的 cookie。您可能需要检查:laravel.com/api/5.2/Illuminate/Cookie/… 如果您使用的是 Laravel 5.2,请确保在使用中间件加密时添加了异常。

标签: php amazon-web-services cookies amazon-cloudfront


【解决方案1】:

原来问题出在加密的 cookie 上。您可能需要检查:https://laravel.com/api/5.2/Illuminate/Cookie/CookieJar.html#method_make 如果您使用的是 Laravel 5.2,请确保在使用中间件加密时添加了异常。

【讨论】:

  • 不要将链接发布为答案,而是添加一些文本来解释此答案如何帮助 OP 解决当前问题。谢谢
猜你喜欢
  • 2017-10-23
  • 1970-01-01
  • 2019-04-24
  • 2021-01-31
  • 2017-04-02
  • 2020-09-11
  • 2019-01-24
  • 2016-01-26
  • 2018-09-17
相关资源
最近更新 更多