Security: Session cookie defaults to secure=false and no sameSite attribute
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- javascript, node.js
调研方向
先从 session/cookie.js lines 25-44 开始,了解当前的默认属性,然后检查 session/memory.js lines 40-43,了解单独的 MemoryStore 问题。明确不同部署中安全 cookie 的预期行为以及 MemoryStore 的限制;当这两个问题都有明确且兼容的行为和相应的测试时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
Summary
express-session defaults cookie.secure to undefined (falsy) and does not set sameSite, meaning session cookies are sent over plaintext HTTP and are vulnerable to CSRF in older browsers.
Affected Code
session/cookie.js:25-44:
var Cookie = module.exports = function Cookie(options) {
this.path = '/';
this.maxAge = null;
this.httpOnly = true;
// NOTE: no this.secure = true; no this.sameSite = 'lax';
};
Default cookie attributes:
- httpOnly: true ✅
- secure: undefined (falsy) ❌ — cookie sent over HTTP
- sameSite: undefined (not set) ❌ — browser defaults vary
Impact
- Session cookies transmitted over plaintext HTTP enable network sniffing (WiFi, MITM proxies)
- Missing sameSite leaves CSRF protection to browser defaults — older browsers default to SameSite=None
- Every deployment that does not explicitly set these options is affected
Additional Issue: MemoryStore unbounded DoS
MemoryStore (session/memory.js:40-43) has no session count limit, no max-size check, no eviction policy. With saveUninitialized default behavior, an attacker sending cookieless requests creates unlimited sessions until OOM.
I understand the README warns MemoryStore is for development only, but the cookie security defaults affect ALL store backends including production Redis/Mongo stores.
Suggested Fix
Default to secure cookie settings when possible:
this.sameSite = 'lax';
// And warn when secure is not explicitly set in production
- 主要语言
- JavaScript
- 星标
- 6.4k
- 派生
- 1k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
expressjs/session 的其他 Issue
-
Update the var keyword in README to const可能已有人在做 @Hashim1999164 于 120 天前认领。 未关闭future
难度 1/5 1 小时以内 新手友好度 62/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
discuss
难度 5/5 一周以上 新手友好度 25/100
-
discuss v2
难度 5/5 一周以上 新手友好度 25/100
-
question
难度 5/5 一周以上 新手友好度 25/100
查看 expressjs/session 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 63/100
anothaDev/luci-theme-vantage#143 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
kingcharleslzy-ai/dsh-purge#282 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 72/100
-
a-corriger bug
难度 2/5 1-3 小时 新手友好度 86/100
christian-raj/S-Aloha#340 ·
-
area:image documentation good first issue
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复