请求Cookie具有针对Cookie Attirbutes的N / A设置

时间:2016-10-29 17:30:53

标签: node.js express cookies setcookie

我正在努力在我的ExpressJS应用程序中修复我的Cloudfront(CF)Cookie设置,并且我的Cloudfront发行版成功设置并识别了Cookie,但我注意到当我不成功时(大量的从分发中访问内容的时间似乎可能是由于CF Request Cookies的域,路径和过期值N/ARequest Cookies如何运作?在ExpressJS中,能够Set-Cookie,这就是我所做的,并且在Response Cookies部分中正确显示,但我不确定导致Request Cookies出现的原因是什么他们开始做的。我还注意到请求和响应cookie之间的CloudFront-Signature cookie不同。这会导致这个问题吗?

页面加载时我的HTTP请求的屏幕截图

HTTP

代码设置cookie:

var express = require('express');
var router  = express.Router();
var session = require('express-session');
var passport = require('passport');
var crypto = require('crypto');
var moment = require('moment');
var path = require('path');
var fs = require('fs');
var cf = require('aws-cloudfront-sign');
var metaTags = require('./meta-routes');

router.use('/app', isLoggedIn, require('./app-routes'));

var cfPK = path.join(__dirname + process.env.CF_PRIVATE_KEY);

var cfOptions = {
    keypairId: process.env.CF_KEY_ID,
    expireTime: null,
    privateKeyPath: cfPK
}

var signedCookies = cf.getSignedCookies(process.env.CF_CNAME, cfOptions);

function isLoggedIn(req, res, next) {

    if (req.isAuthenticated())

        for(var cookieId in signedCookies) {
            res.cookie(cookieId, signedCookies[cookieId], { httpOnly: true, domain: process.env.DOMAIN_NAME || 'localhost', secure: true });
        }

        return next();
    res.redirect('/login');
}

0 个答案:

没有答案