reviewing-server-actions

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Review: Server Actions

审查:Server Actions

Security Checklist

安全检查清单

Input Validation

输入验证

  • All inputs validated with schema (zod, yup, etc.)
  • Type coercion handled correctly (FormData.get returns strings)
  • Length limits enforced
  • No SQL injection vulnerabilities
For runtime validation patterns and type safety, use the using-runtime-checks skill from the typescript plugin.
If reviewing Zod schema validation patterns, use the validating-schema-basics skill for type-safe Zod v4 schema patterns.
  • 所有输入均通过Schema(如zod、yup等)验证
  • 正确处理类型转换(FormData.get返回字符串类型)
  • 强制执行长度限制
  • 无SQL注入漏洞
如需运行时验证模式和类型安全方案,可使用typescript插件中的using-runtime-checks技能。
若审查Zod Schema验证模式,可使用validating-schema-basics技能获取类型安全的Zod v4 Schema模式。

Authentication & Authorization

身份验证与授权

  • Session/auth checked before mutations
  • User permissions verified
  • Resource ownership validated
  • No unauthorized access possible
For secure credential handling, use the SECURITY-credentials skill from the typescript plugin.
  • 执行数据变更前检查会话/身份验证状态
  • 验证用户权限
  • 确认资源归属权
  • 避免未授权访问的可能
如需安全凭证处理方案,可使用typescript插件中的SECURITY-credentials技能。

Data Sanitization

数据清理

  • User input sanitized before storage
  • No XSS vulnerabilities
  • File uploads validated (type, size, content)
  • Dangerous operations require confirmation
  • 用户输入在存储前经过清理处理
  • 无XSS漏洞
  • 验证文件上传(类型、大小、内容)
  • 危险操作需确认

Best Practices

最佳实践

Error Handling

错误处理

  • Try-catch blocks for async operations
  • Specific error messages for users
  • No sensitive data in error messages
  • Logging for debugging
  • 异步操作使用try-catch块
  • 为用户提供明确的错误提示
  • 错误信息中不包含敏感数据
  • 记录日志用于调试

Return Values

返回值

  • Return serializable objects only
  • Consistent response format
  • Success and error states handled
  • Field-specific errors when needed
  • 仅返回可序列化对象
  • 保持响应格式一致
  • 正确处理成功与错误状态
  • 必要时返回字段级错误信息

Performance

性能

  • Database queries optimized
  • No N+1 query problems
  • Appropriate use of transactions
  • Rate limiting where needed
  • 优化数据库查询
  • 避免N+1查询问题
  • 合理使用事务
  • 必要时添加速率限制

Anti-Patterns to Flag

需要标记的反模式

  • ❌ No validation (trusting client input)
  • ❌ No authentication checks
  • ❌ Returning non-serializable values (functions, classes)
  • ❌ Missing error handling
  • ❌ Exposing sensitive data
  • ❌ Direct database queries without sanitization
  • ❌ No rate limiting on critical actions
For comprehensive Server Actions security, see:
research/react-19-comprehensive.md
lines 723-729, 1808-1942.
  • ❌ 未做任何验证(信任客户端输入)
  • ❌ 未做身份验证检查
  • ❌ 返回不可序列化的值(如函数、类)
  • ❌ 缺少错误处理
  • ❌ 暴露敏感数据
  • ❌ 未经过清理直接执行数据库查询
  • ❌ 关键操作未设置速率限制
如需了解全面的Server Actions安全内容,请查看:
research/react-19-comprehensive.md
第723-729行、1808-1942行。