Skip to content

Support configuring secure session cookies. - #7798

Open
xiewxin wants to merge 3 commits into
hyperf:masterfrom
xiewxin:fix/session-cookie-secure
Open

Support configuring secure session cookies.#7798
xiewxin wants to merge 3 commits into
hyperf:masterfrom
xiewxin:fix/session-cookie-secure

Conversation

@xiewxin

@xiewxin xiewxin commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

修改内容

  • 新增 session.options.cookie_secure 配置,用于显式控制 Session Cookie 的 Secure 属性。
  • 配置为 truefalse 时使用显式值。
  • 配置为 null 或未配置时,继续根据请求 URI 的 scheme 自动判断,保持现有行为不变。
  • 发布配置默认值为 null

问题原因

当前 Session Cookie 的 Secure 属性只根据请求 URI 是否为 HTTPS 判断。
当 TLS 在反向代理终止、应用层接收到 HTTP 请求时,使用者无法强制为 Session Cookie 设置 Secure 属性。

本次修改只增加显式配置能力,不解析代理请求头,也不因 SameSite=None 自动强制开启 Secure

测试

  • 新增 HTTP 下强制开启 Secure 的测试。
  • 新增 HTTPS 下显式关闭 Secure 的测试。
  • 新增配置为 null 和未配置时保留原有自动判断行为的测试。
  • 已运行 Session 组件测试:23 个测试,91 个断言全部通过。
  • PHP CS Fixer 和针对性 PHPStan 检查通过。

Fixes #7301.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

无法给session id的set-cookie设置secure属性

1 participant