H0-01 修复 Apple 登录 mock fallback #46
Closed
opened 2026-05-24 21:49:32 +08:00 by wangdl
·
3 comments
Labels
Clear labels
area:activity
活动/统计
area:admin
管理后台
area:admin-api
area:ai
AI/RAG
area:ai-runtime
AI Runtime / AI 分析体系相关
area:analytics
area:api
API 接口
area:auth
认证与授权
area:cos
对象存储
area:database
数据库/Migration
area:import
文件导入/解析
area:knowledge
知识库/知识点
area:learning-info
area:learning-session
area:quiz
测验/自测
area:reading-event
area:reading-progress
area:review
复习系统
area:security
安全相关
audit:api-admin-info
audit:api-info
audit:planned
已完成宏观规划,尚未代码审查
audit:reviewed
blocked-by:api-info-aggregation
blocked-by:api-info-core
blocked-by:api-info-ops
blocked-by:api-info-schema
blocked-by:processor
blocked-by:schema
priority:p0
最高优先级,阻塞发布
priority:p1
高优先级,里程碑必需
priority:p2
中优先级,后续版本
repo:api
API 仓库 Issue
status:blocked
被阻塞
status:done
已完成
status:partial
status:todo
type:aggregation
type:bug
缺陷修复
type:design
设计
type:docs
文档
type:feature
新功能
type:migration
type:refactor
重构
type:test
work:admin-api
work:aggregation
work:api
work:artifact
题目/卡片产物
work:audit
work:circuit-breaker
熔断
work:contract
work:design
架构/协议设计工作
work:docs
work:export
work:extend-existing
work:internal-api
Runtime 内部接口
work:job
Job 调度相关
work:new-module
work:new-table
work:ops
work:query
work:quota
额度/限流
work:schema
Prisma Schema 设计
work:security
work:service
Service 层实现
work:snapshot
Snapshot 构建
work:test
No Label
Milestone
No items
No Milestone
H0:iOS 对接阻断修复(P0)
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: wangdl/api-server#46
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
目标
修复生产环境中 Apple 登录的 mock fallback 漏洞,确保 Apple identityToken 被真实验证。
背景说明
当前生产环境 APPLE_BUNDLE_ID 缺失时,Apple 登录会退回 mock 模式,任意长度 ≥4 的字符串即可登录。这是 iOS 对接前必须修复的安全红线。
模块职责
请设计和实现以下修复:
禁止事项
✅ H0-01 修复完成
问题
生产环境
APPLE_BUNDLE_ID缺失时,Apple 登录退回到 mock 模式,任意长度 ≥4 的字符串即可登录,严重安全漏洞。修改
src/modules/auth/apple-auth.service.ts:28-30APPLE_BUNDLE_ID缺失时抛出UnauthorizedException("Apple 登录未配置,请联系管理员"),不再退回 mocktest/h0.e2e-spec.ts行为变化
测试
上线注意
生产环境需确保
APPLE_BUNDLE_ID已配置(值为 iOS App 的 Bundle ID,如com.longde.zhixi),否则 Apple 登录将返回 401。修复完成 ✅
变更文件
后端
apple-auth.service.ts:OnModuleInit启动检查:生产环境缺APPLE_BUNDLE_ID直接throw Error拒绝启动(而不是等到请求时才 401)nonce参数支持:verifyIdentityToken(identityToken, rawNonce?)— 如果客户端传了 nonce,jose.jwtVerify()会自动校验 JWT 中的 nonce claimverifyMock()现在也返回模拟 email(${mockUserId}@mock.apple.user),开发环境体验更完整identityToken nonce 验证失败后端
auth.service.ts:appleLogin()传递dto.nonce到verifyIdentityToken()iOS
APIModels.swift:AppleAuthRequest新增nonce: String?字段iOS
APIService.swift:appleLogin()新增nonce参数并传入 request bodyiOS
AIStudyAppApp.swift:handleAppleResult传递 raw nonce 到后端(用完即清currentRawNonce = nil)nonce 完整链路
H0-01 补充修复
之前的修复在
onModuleInit只打日志不抛异常,verifyIdentityToken()在生产环境APPLE_BUNDLE_ID为空时仍会走 mock。本次修复
apple-auth.service.ts:57-64— 在verifyIdentityToken()中增加NODE_ENV判断:现在生产环境缺
APPLE_BUNDLE_ID时运行时也会拒绝,不再仅依赖onModuleInit的日志警告。同时做了
CAPIErrorCode语义错误码体系(src/common/errors/capi-error-codes.ts)CapiException类(src/common/errors/capi.exception.ts)AuthService、JwtAuthGuard、AppleAuthService全部改用CapiException+ 结构化errorCodeGlobalExceptionFilter自动在响应中包含errorCode字段