AWS Cloudfront 签名 Cookie 不适用于备用域

AWS Cloudfront Signed Cookie not working on alternate domain

问题

我有 Access Denied 使用固定策略和自定义策略对带有签名 cookie 的云端 GET 请求。

详情

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

```

$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. Cookie 是为 .example.com
  2. 设置的

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

提前致谢。

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