Commit Graph

13 Commits

Author SHA1 Message Date
Abner
33b8e20440 ♻️ refactor: 抽取内部请求头构建并规范 Cookie 验证返回语义
- 新增共享模块 netlify/functions/_shared/internal-headers.js,集中构建内部函数互调请求头,统一 ACCESS_KEY 未配置时的 500 抛错逻辑
- 更新 giffgaff-graphql.js / giffgaff-mfa-challenge.js / giffgaff-mfa-validation.js,移除各自重复的 getInternalHeaders 实现,改为复用 getInternalHeaders
- 调整 verify-cookie.js 返回语义:以 success 表示 HTTP 层请求是否成功、以 valid 表示是否具备可用于后续 API 的 JWT 令牌
- 修正 verify-cookie.js 错误提示文案中的乱码问题,确保提示“无法通过Cookie获取访问令牌”表述正确
2026-05-31 20:30:31 +08:00
Abner
b815225845 🐛 fix(auth): 收紧 BFF 鉴权并保持内部路由兼容 2026-05-31 18:15:45 +08:00
Abner
7fd54dde39 ♻️ refactor: 修复安全漏洞并优化架构债务
安全修复:
- 修复 dom.js 和 simyo/app.js 中的 innerHTML XSS 注入风险
- 使用 HTMLSanitizer.escapeHtml/escapeAttr 替代直接模板拼接
- 将 onclick 内联事件替换为 data-* 属性 + addEventListener
- 移除 server.js 中硬编码的 Simyo X-Client-Token

架构优化:
- 新增 _shared/rate-limiter.js 分布式限流模块 (Netlify Blobs)
- verify-cookie.js 内存限流替换为 KV 跨实例共享方案
- giffgaff/utils.js debounce/throttle 改为委托共享实现
- simyo/app.js 会话存储迁移至 SecureStorage (自动 TTL 过期)
- 合并 notifications-internal.js 至 notifications.js 消除双维护路径
2026-04-25 16:30:19 +08:00
Abner
4a0fcc94fe feat: 重构Netlify Functions架构并增强代码质量
- 新增统一的中间件模块,提供鉴权、CORS和错误处理功能
- 重构所有Functions使用withAuth中间件简化代码结构
- 添加安全存储模块替代localStorage,防御XSS攻击
- 引入HTML清理工具,自动转义特殊字符和验证URL安全性
- 创建代码质量检查脚本,验证语法、环境变量和依赖完整性
- 添加构建日志工具和重构脚本,统一替换console.log为Logger
- 引入ESLint配置,提升代码质量和一致性
- 重构Giffgaff相关API,统一错误处理和验证逻辑
- 优化构建脚本,添加压缩和图片优化功能
- 新增健康检查端点,用于服务监控和状态报告
2025-11-23 22:20:02 +08:00
Abner
5a29e64ec7 feat: 重构部署流程并移除 Service Worker
- 新增部署工具脚本:添加 `build-static.js`、`deploy-prepare.js`、`deploy-analyze.js` 和 `test-deploy-config.js` 标准化构建部署流程
- 配置 Netlify 发布目录:修改 `netlify.toml` 将 `publish` 从根目录切换到 `dist` 目录以增强安全性
- 移除 Service Worker 相关代码:删除 `sw.js` 并清理相关注册逻辑,简化性能优化策略
- 增强服务器静态文件服务:重构静态资源中间件,增加环境检查和错误处理
- 改进 API 密钥处理逻辑:统一 Netlify Functions 的密钥验证流程,增加配置缺失提示
- 添加 Serena AI 配置文件:包含项目元数据、语言服务器设置和常用命令记忆
- 重构 HTML 页面路由:使用配置化的路由表替代硬编码路径,提高可维护性
2025-11-23 19:44:45 +08:00
Abner
d1d440621e feat(security): 添加访问控制和身份验证机制 2025-08-11 00:31:51 +08:00
Abner
106737e7c9 feat(netlify): 优化 Cookie 验证和 MFA 验证流程
- 添加 Dashboard 预热步骤,提高 MFA 接口成功率
- 获取并使用 CSRF 令牌,提升 MFA 接口通过率
- 优化 Cookie 合并逻辑,处理 Set-Cookie 覆盖
- 改进 verify-cookie 函数,增加 JWT 检查
- 更新前端界面,支持短信验证码选项
2025-08-11 00:05:20 +08:00
Abner
a656663ba8 feat(giffgaff): 增加手动输入激活码功能并优化相关流程
- 新增"我已完成申请(已有激活码/SSN)"快捷入口
- 实现手动输入激活码和SSN功能
- 优化自动激活流程,提高成功率
- 调整请求头参数,提升兼容性
2025-08-10 22:00:24 +08:00
Abner
5d65ffe8bb feat(cors): 放宽跨域访问限制
- 将 Access-Control-Allow-Origin 从特定域名修改为允许所有域名
- 移除了对请求来源的校验逻辑
- 此修改适用于 /api/simyo/*、/api/giffgaff/*、/api/giffgaff-id/*、/api/giffgaff-public/*、giffgaff-graphql、giffgaff-mfa-challenge、giffgaff-mfa-validation 和 verify-cookie 函数
2025-08-10 20:42:58 +08:00
Abner
251da627ad docs(security): 更新内容安全策略并移除冗余代码
- 更新内容安全策略以允许 Google Tag Manager
- 移除 verify_cookie.php 文件
- 优化 Service Worker 注册和缓存逻辑
- 更新时间检查逻辑以使用国际时区
- 调整 OAuth 2.0 PKCE 配置,移除前端的 clientSecret
2025-08-09 17:43:44 +08:00
Abner
f97d8339e4 feat(auth): 增加 OAuth 2.0 PKCE 令牌交换功能
- 新增 giffgaff-token-exchange.js 函数,用于交换 authorization code 和 access token
- 更新 verify-cookie.js 函数,增加对 cookie 中 access token 的提取和验证
- 修改 giffgaff-graphql.js、giffgaff-mfa-challenge.js 和 giffgaff-mfa-validation.js 函数,支持使用 access token 或 cookie 进行身份验证
- 更新 README.md 和 COOKIE_LOGIN_SETUP.md 文档,说明新的身份验证流程和安全注意事项
2025-08-09 14:39:29 +08:00
Abner
fbdae9d166 refactor(auth): 重构 Cookie 验证逻辑
- 修改 API 调用 URL 为 Giffgaff Dashboard 页面
- 更新请求头以模拟真实浏览器访问
- 通过页面内容判断登录状态,提高验证准确性
- 增加对关键认证 Cookie 的检查和使用
- 优化临时 token 生成逻辑,基于 Cookie 信息
2025-08-02 17:17:36 +08:00
Abner
ab8f0c05d8 🚀 Major upgrade: Convert to Node.js architecture with Netlify Functions
🔄 Complete Architecture Transformation:
- Migrated from PHP to Node.js backend
- Implemented Netlify Functions for serverless deployment
- Added Express.js server for local development
- Full compatibility with modern deployment platforms

🛠️ New Netlify Functions:
- giffgaff-mfa-challenge.js: Handles MFA email verification with proper headers
- giffgaff-mfa-validation.js: Processes MFA code validation
- verify-cookie.js: Cookie authentication converted from PHP to Node.js

 MFA 403 Error Resolution:
- Proper Origin and Referer headers in server-side requests
- Comprehensive error logging for debugging
- Timeout handling and robust error responses
- Should completely resolve MFA authentication issues

🍪 Enhanced Cookie Login:
- Full Node.js implementation replacing PHP dependency
- Works on all deployment platforms (Netlify, Vercel, traditional servers)
- Intelligent cookie parsing and validation
- Secure API calls with proper headers

�� Development Experience:
- package.json with all necessary dependencies
- Local development server (server.js)
- Environment configuration (env.example)
- Hot reload support with nodemon

🌐 Deployment Improvements:
- Netlify Functions integration
- Updated netlify.toml configuration
- Automatic dependency installation
- Zero-config deployment process

🎯 Key Benefits:
-  Resolves MFA 403 errors through proper server-side handling
-  Cookie login works on all platforms (no PHP dependency)
-  Better error handling and logging
-  Modern serverless architecture
-  Improved development experience
-  Full compatibility with static hosting platforms

📋 Technical Stack:
- Frontend: Pure HTML/CSS/JavaScript (unchanged)
- Backend: Node.js + Express.js (local) / Netlify Functions (production)
- Dependencies: axios, cors, helmet, morgan, dotenv
- Deployment: Netlify with automatic function deployment

This major upgrade modernizes the entire backend architecture while maintaining full frontend compatibility. The MFA 403 error should now be completely resolved through proper server-side request handling.
2025-08-01 21:03:25 +08:00