Skip to content

fix(auth): HttpOnly refresh cookie + centralized internal auth - #6

Merged
xiaoqianran merged 20 commits into
mainfrom
fix/security-hardening-20260818
Aug 18, 2026
Merged

fix(auth): HttpOnly refresh cookie + centralized internal auth#6
xiaoqianran merged 20 commits into
mainfrom
fix/security-hardening-20260818

Conversation

@xiaoqianran

Copy link
Copy Markdown
Owner

目标

彻底收紧浏览器认证和服务间接口边界,避免长期令牌暴露给 JavaScript,并消除 /internal/** 依赖 Controller 手工鉴权的脆弱约定。

主要改动

  • Refresh Token 不再出现在登录/刷新 JSON;仅写入 HttpOnly Cookie
  • Access Token 不再持久化到 localStorage;前端仅保存在页面内存
  • 新页面通过 HttpOnly refresh cookie 恢复会话,并复用现有 refresh rotation
  • 所有 fetch/XHR 开启 credentials
  • Gateway 统一使用精确 Origin + credentials CORS,禁止 wildcard
  • 对 login/refresh/logout 增加精确 Origin 校验,覆盖 SameSite=None 跨站部署下的 CSRF 风险
  • /internal/** 统一由 InternalServiceKeyFilter 鉴权,Controller 不再承担手工鉴权责任
  • 默认 Access Token 生命周期从 2h 降至 30min
  • 本地 profile 允许 HTTP Cookie;生产默认 Secure
  • 更新 GitHub Pages + Caddy 部署文档

回归测试

  • HttpOnly/Secure/SameSite Cookie 属性
  • 不可信浏览器 Origin 拒绝
  • 任意未来 /internal/** 路径缺少 service key 都会在 Filter 层拒绝
  • 原 InternalUserController 集成测试继续覆盖真实内部 API

合并顺序

本 PR 与 #5 职责分离:#5 处理 Spring 依赖/供应链扫描/SQL 日志/IP 清理;本 PR 处理认证与服务边界。建议两边 CI 均绿后先合并 #5,再将本 PR 更新到最新 main 后合并。

Copilot AI lite review requested due to automatic review settings August 18, 2026 10:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@xiaoqianran
xiaoqianran merged commit 8b6626d into main Aug 18, 2026
5 checks passed
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.

2 participants