返回 Skill 列表
extension
分类: 开发与工程无需 API Key

sanitizing-inputs-zod

使用Zod进行高级输入验证和清理。用于防止XSS攻击,并在将数据发送到Appwrite之前确保数据完整性。

person作者: jakexiaohubgithub

Input Sanitization and Zod (Advanced)

When to use this skill

  • Every form that accepts user input (Reviews, Profile updates, Booking special requests).
  • Before performing any database mutation in a Server Action.

Advanced Schema

import { z } from 'zod';

export const TourReviewSchema = z.object({
    rating: z.number().min(1).max(5),
    comment: z.string().trim()
        .min(10, "Comment too short")
        .max(500, "Comment too long")
        .refine(s => !s.includes('<script>'), { message: "Invalid characters" }),
});

Instructions

  • Server-Side Only: Validation MUST happen on the server (Server Action) even if you have client-side validation.
  • Type Inference: Use z.infer<typeof Schema> to generate TypeScript types from your validation logic.
  • Sanitization: Use .trim(), .toLowerCase(), and custom transforms to clean data before persistence.