Skip to content

fix(DIS-158): Add security fix for findByIdAndUpdate and sanitize verification update data#158

Open
Whiskey-Taste wants to merge 10 commits intomainfrom
DIS-158-verification-security-fix
Open

fix(DIS-158): Add security fix for findByIdAndUpdate and sanitize verification update data#158
Whiskey-Taste wants to merge 10 commits intomainfrom
DIS-158-verification-security-fix

Conversation

@Whiskey-Taste
Copy link
Contributor

…ification update data## Changes

  • Fix findByIdAndUpdate to use safe query syntax to prevent MongoDB operator injection
  • Add sanitizeVerificationUpdate function to sanitize update data
  • Add type check for mobile field to ensure it's a string

Security Fix

This PR addresses security vulnerabilities in the verification service by:

  1. Preventing MongoDB operator injection attacks
  2. Sanitizing user input to only allow expected fields
  3. Adding type validation for mobile numbers

Files Changed:

  • src/modules/setting/verification.service.ts (32 insertions, 3 deletions)

Whiskey-Taste and others added 10 commits November 2, 2025 13:23
- Update verification controller routes to match frontend API expectations
- Add sendEmailVerification and sendSmsVerification endpoints
- Add verifyEmail and verifySms endpoints with code support
- Update verification service with stub implementations for code sending
- 创建接口抽象层 (IEmailVerificationService, ISmsVerificationService)
- 提取可复用工具函数 (verification-code.util, phone-number.util, email-template.util)
- 重构AWS SES和SNS服务实现接口
- 支持依赖注入,便于替换服务提供商
- 添加完整的README文档和使用示例
- 改进代码组织结构,遵循SOLID原则
- 移除不必要的 String() 类型转换
- 修复模板字符串中的 number 类型转换
- 修复不必要的转义字符
- 修复不必要的条件判断
- 移除未使用的导入
- 添加 moduleNameMapper 规则来解析 .js 扩展名
- 配置 Jest 支持 ESM 模块
- 修复测试中找不到模块的问题
- 所有单元测试和集成测试现在都能通过
- Fix findByIdAndUpdate in verification.service.ts: pass objectId directly instead of { _id: objectId }
- Fix TypeScript type error in call-processor.service.ts: use .toString() to convert ObjectId to string
- Resolves high-risk bug that prevented user data updates
- Resolves TypeScript compilation errors
- Resolve package.json conflicts: keep both @aws-sdk/client-ses (for legacy code) and @aws-sdk/client-sesv2/@aws-sdk/client-sns (for new verification features)
- Remove unused 'ses' package
- Regenerate pnpm-lock.yaml
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