Skip to content

[安全] 建议:增加安全测试覆盖 #81

@evan-zhang11

Description

@evan-zhang11

背景

当前测试覆盖良好(API 契约、E2E 流程、单元测试),但缺少专门的安全测试。

建议添加的安全测试

1. SQL 注入测试

  • 测试文件 ID、slug 等参数中的恶意输入
  • 测试文件名中的特殊字符处理
  • 虽然当前使用参数化查询,但应该验证

2. 文件上传安全测试

  • 超大文件测试(已部分覆盖)
  • 恶意文件类型测试(伪装扩展名)
  • 路径遍历攻击测试(如 ../../../etc/passwd

3. 认证/授权测试

  • 无认证访问受保护端点
  • 跨用户数据访问尝试
  • Session 过期处理

4. 输入验证测试

  • 特殊字符、Unicode 字符处理
  • 超长输入处理
  • 空值/null 处理

实现建议

  1. 创建 tests/security/ 目录
  2. 添加安全测试到 CI 流程
  3. 考虑使用自动化安全扫描工具(如 OWASP ZAP)

示例测试用例

#[test]
fn test_sql_injection_in_file_id() {
    let malicious_ids = vec![
        "'; DROP TABLE files; --",
        "1' OR '1'='1",
        "1; DELETE FROM files WHERE 1=1",
    ];
    for id in malicious_ids {
        let response = get_file(state.clone(), id).await;
        assert_eq!(response.status(), StatusCode::BAD_REQUEST);
    }
}

优先级

P2 - 中优先级,安全测试应该是持续的过程

相关

  • 当前 CI 已有 security workflow(cargo audit, npm audit)
  • 需要扩展到应用层安全测试

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions