简体   繁体   English

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

[英]AWS Cloudfront Signed Cookie not working on alternate domain

Problem 问题

I have Access Denied for GET request to cloudfront with signed cookies using both canned and custom policy. 我使用自定义策略和自定义策略,使用已签名的Cookie对Cloudfront GET请求Access Denied

Details 细节

  1. cdn.example.com is the alternate domain of abc.cloudfront.net , and CNAME is set on both cloudfront and cloudflare. cdn.example.com是的交替域abc.cloudfront.net ,和CNAME被设置在两个CloudFront的和的CloudFlare。
  2. I expect after abc.example.com/authorize , cdn.example.com is accessible. 我希望在abc.example.com/authorize cdn.example.com可以访问cdn.example.com
  3. I am using PHP with Laravel behind abc.example.com/authroize , and the code is as follows. 我使用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. The cookies are set for .example.com Cookie是为.example.com设置的

在此输入图像描述

  1. When I go to cdn.example.com , the following message is shown 当我转到cdn.example.com ,会显示以下消息

在此输入图像描述

Thanks in advance. 提前致谢。

Turns out the issue was due to the encrypted cookies. 事实证明这个问题是由于加密的cookie。 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. 您可能需要检查: https ://laravel.com/api/5.2/Illuminate/Cookie/CookieJar.html#method_make如果您使用的是Laravel 5.2,请确保在使用中间件加密时添加了例外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM