问题标签 [cookie-session]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
45 浏览

express - 如何防止 session 和 session.sig cookie 在使用 cookie-session 中间件的快速应用程序中获得同意之前设置?

我有一个基于 express 构建的 javascript 应用程序,并且我使用 cookie-session 中间件。session并且session.sigcookie 是在同意之前设置的,我想阻止它。我该怎么做呢?

0 投票
2 回答
458 浏览

express - 当 SameSite 设置为“无”且安全设置为 true 时,Express cookie-session 不保存 cookie

我正在使用 cookie-session 和 passportjs 来验证我的快速应用程序中的用户。当我像这样初始化我的 cookieSession 时:

我的 cookie 已成功保存到客户端。但是,我正在进行的项目需要跨站点请求。因此,cookie 的secure 属性必须设置为true,SameSite 属性必须设置为none。在文档中,这些值可以设置如下:

但是,当我这样做时,cookie 无法保存到客户端。我想知道是否有人知道如何解决此问题或为什么会发生这种情况?

先感谢您。

0 投票
0 回答
23 浏览

express - 如何在本地子域之间共享 cookie (locahost)

我正在尝试在本地子域之间共享 cookie。

我有localhost:2000我登录的地方,然后我去,dashboard.localhost:2000但我没有任何 cookie。

我已经尝试了几件事,但没有任何效果。

现在我的代码是这样的:

当我登录时,我创建了 cookie(仅当我在 LOCALHOST 中创建 url 时)

我已经添加了会话、cookie 会话和任何有效的方法。

);

我已经将 localhost 的 """name""" 更改myapplicationdev.comdashboard.myapplicationdev.com:2000

我不知道发生了什么...有人可以帮助我吗?

0 投票
0 回答
60 浏览

node.js - 在测试中使用 jwt.verify 指定 expiresIn 时未设置 JWT Cookie

我在使用 jest 和 supertest 测试 node.js API 中的端点时遇到问题。我正在尝试使用新的 jwt 令牌更新会话。会话结构如下所示:

下面是在会话 (endpoint.ts) 上设置新令牌的代码:

下面是查看是否设置了标头的测试代码(test.ts):

奇怪的是,只要我没有设置 jwt 的到期时间(在 endpoint.ts 中),测试就可以正常工作。如果我删除 expiresIn,则测试通过。但是如果我设置 expiresIn 测试偶尔会通过(平均 1/6 次),否则测试会失败。

任何帮助或见解或希望将不胜感激。太感谢了!

更新:我发现如果我删除现有有效负载上的“iat”和“exp”属性并创建一个新的 cookie,它会起作用。

0 投票
0 回答
30 浏览

node.js - Cookie 会话,使用秘密而不是密钥

我的 cookie 会话设置如下:

我正在阅读文档,示例设置如下:

文档还说秘密是:

如果未提供键,则将用作单个键的字符串。

我对键数组的工作方式感到困惑。当它是单个秘密时,服务器知道该秘密并使用相同的秘密来解密请求。

关于键数组,文档说:

用于签署和验证 cookie 值的密钥列表,或配置的 Keygrip 实例。设置的 cookie 始终使用 keys[0] 签名,而其他密钥对验证有效,允许密钥轮换。

如果随机选择keys数组中的项目来加密密钥,服务器如何知道使用哪个密钥?如果不同的响应需要不同的密钥来解密怎么办?

0 投票
0 回答
114 浏览

node.js - cookie-session 未显示在浏览器 Cookie 上


我正在尝试使用 npm cookie-session 从 ExpressJs 服务器保存令牌,但无法在浏览器上获取 cookie,但它出现在 Set-Cookie 请求中。在邮递员中,我可以使用令牌。

服务器代码

邮递员的令牌答案

前端登录请求

前端请求Set-Cookie

缺少令牌

0 投票
0 回答
17 浏览

ios - 在 iOS 上,节点服务器的会话 cookie 被初始化

显示webview的IOS版本为14,接收请求的服务器节点版本为10.0.0。

关于 webview 模拟器 : (Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148)

在Android中,session值传递的很好,但是在IOS中用WKWebview打开网页时,中间会初始化cookie中的session值。

节点服务器使用cookie-session库发送和接收会话信息,网页前端是用vue开发的。

我不确定到底是什么问题,所以我在问。

日志附在下面。首先,将会话值正确输入到请求标头中,如下所示并交付。

但是,在接下来的 API 调用中,会话值在请求中传递得很好,但是

0 投票
0 回答
39 浏览

express - 使用 cookie-session npm 库在 cookie 中设置会话数据

描述 我目前正在尝试在我的节点后端实现一些会话身份验证逻辑,但是在我的开发环境中遇到了我似乎无法解决的问题。

后端:带有 express 库的节点:cookie-session

文档链接:https ://www.npmjs.com/package/cookie-session

设置 在 EC2 实例中运行服务器(不安全)。但是在 ec2 实例上通过 https 指向 ngrok 代理服务器。

服务器.js

预期的行为 会话 ID 反序列化并提供对会话属性进行测试的最后请求值。

当前行为 会话上未设置任何内容

0 投票
0 回答
88 浏览

javascript - cookie-session 和 JWT 令牌有什么区别?

这个库在这里将您的会话数据存储在客户端https://www.npmjs.com/package/cookie-session上。但这不是使其成为 JWT 令牌(而不是“会话”)吗?

cookie-session 将数据存储在 cookie 中,与 JWT 令牌通常存储在 localStorage 中的区别是什么?

只是对这里的术语感到困惑,谢谢。

0 投票
1 回答
117 浏览

express - Express signed cookie vs JWT as cookie for Authentication

First let me start by saying, this is not a question of client token vs server-side session reference. I understand the differences and I've already decided on a session-less implementation.

I've also decided to use cookies for client-side persitance and transmission rather than localStorage, query param, auth headers, etc.

Ok, with that out of the way, I'm looking at two alternatives to save userID on the client. Both prevent tampering via signing of the data.

Express has a middleware which enables signed cookies, or I could use a JWT which also signs the data (which I would still send via a cookie).

So far, my thinking is to use signed cookies, it's got less processing overhead and does a specific thing and I don't necessarily need my data in nested json format. Also, I'm using it only for authentication of users on my webserver, not for API's or other authorization. I don't need a public/private asymmetric key validation.

JWTs are nice standards, and I will already be using it for OAUTH, but for my site auth, I don't need some of the benefits. For example, I don't need it for transferability. I will not have different sig algorithms or token types.

However I do appreciate that JWT's are a recognized standard and have lots of support/documentation.

Is there something I'm missing on why I should instead choose to use JWT's for website authorization and client identification?

BTW, I have done research on this before posting the question. Here is a very similar one, JWT vs cookies for token-based authentication

However the top voted answer doesn't apply for a few reasons. Chiefly, I've already decided to use cookies for JWT or not. I will be using cookies with options like sameSite to prevent CSRF attacks, along with: expires, secure, httpOnly, and signed (which is particular to express).