Files
biji/doc/security-analysis.md
ikmkj 6fdc3a491c docs: 添加项目安全架构分析文档
Co-authored-by: aider (deepseek/deepseek-chat) <aider@aider.chat>
2025-08-04 19:42:56 +08:00

46 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 安全架构分析文档
## 1. 认证与授权
- **JWT认证**:使用`JwtTokenUtil`实现基于HS512算法的令牌签发/验证
- **有效期检查**:令牌包含过期时间(`expiration`)
- **过滤器链**`JwtAuthenticationTokenFilter`拦截请求验证令牌
- **用户上下文**:通过`UserDetailsService`加载用户权限信息
## 2. 密码安全
- **BCrypt加密**:使用`PasswordUtils`进行密码哈希存储(工作因子10)
- **盐值机制**:每次加密生成随机盐值
- **防暴力破解**:无明文密码传输
## 3. 输入安全
- **XSS防护**
- `XSSInterceptor`拦截器过滤请求参数
- 使用`HtmlUtil.filter()`清理HTML内容
- **CSRF防护**:未显式配置(依赖JWT无状态特性)
## 4. API安全
- **CORS配置**:通过`WebConfig`控制跨域访问
- **生产环境保护**
- Knife4j文档仅在非生产环境启用(`@Profile("!prod")`)
- 敏感接口需要有效JWT
## 5. 注册安全
- **注册码机制**
- 使用`RegistrationCodeService`管理时效性注册码
- 每日自动清理过期注册码(`@Scheduled`)
- **注册开关**:可通过`SystemSettingService`动态关闭注册功能
## 6. 数据安全
- **敏感数据**
- 密码字段应始终加密存储
- JWT令牌不存储敏感信息
- **SQL防护**使用MyBatis参数绑定防止注入
## 改进建议
1. 增加密码强度策略
2. 实现JWT黑名单/刷新机制
3. 添加敏感操作日志审计
4. 配置HTTPS强制跳转
5. 增加API速率限制
> 文档最后更新2025-08-04