input-validation

A guide for checking and cleaning data received from outside a program, such as API requests, forms, uploads, webhooks, or queues. It covers types, ranges, formats, required fields, and safe allowlists.

In plain words
What is it for?
Use it when building APIs, processing forms or files, consuming external messages, handling webhooks, or reviewing input-safety boundaries.
Why use it?
It helps prevent crashes, malformed data, and injection attacks caused by passing untrusted input directly into application logic.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/wade-devcode/awesome-coding-skills-cn/input-validation
Any agent
npx skills add Wade-DevCode/awesome-coding-skills-cn --skill input-validation
Clone the repo
git clone --depth 1 https://github.com/Wade-DevCode/awesome-coding-skills-cn

Made for: Claude Code, Codex.

Per session 24 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,953 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00024 $0.02953
Opus 5 $0.00012 $0.01477
Sonnet 5 $0.00005 $0.00591
Haiku 4.5 $0.00002 $0.00295

Measured 2d ago against content hash 1dad929cb32f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

input-validation scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

**为什么:** AI 生成全栈应用时,有时只在前端加 `required`、`maxlength`、`pattern` 等 HTML 属性,然后后端直接信任前端送来的数据。任何人用 `curl`、Postman 或浏览器开发者工具都能绕过前端校验,直接发送任意数据到后端。这类漏洞在 AI 代码审查中极为常见,因为 AI 看到前端"已有校验"就不再在后端重复。
skills/input-validation/SKILL.md · 243 lines

How it starts

The opening of the file, as written. The whole thing — 243 lines — stays where its author put it; the contents beside it link to each section on GitHub.

输入校验

何时用

  • 编写 API 接口、表单处理、文件上传等接收外部数据的代码时。
  • 处理来自消息队列、第三方 Webhook、数据库读回等任何外部数据源时。
  • 发现生产环境出现类型错误、字段缺失崩溃、注入攻击等问题时。
  • 做安全审查时检查系统边界的防御是否完整。

核心规则

1. 在系统边界集中校验:类型、范围、格式、必填

规则: 在 API 入口(controller/route handler)对所有外部输入做统一校验,覆盖类型是否正确、数值是否在合法范围内、字符串格式是否符合预期、必填字段是否存在;校验通过后的数据才传入业务逻辑层。

为什么: AI 生成 API 接口时最常见的模式是直接把 request.json 传进业务函数,让业务函数自己处理字段缺失或类型错误。这导致两个问题:一是 AttributeError/KeyError 在内层崩溃,堆栈信息可能暴露内部结构;二是相同的校验逻辑散落在各处,维护困难,容易漏掉。AI 还经常只校验"快乐路径",完全忽略 age=-1quantity=99999999email=""等边界值。

怎么做:

from pydantic import BaseModel, Field, field_validator
from typing import Literal

class CreateOrderRequest(BaseModel):
    product_id: int = Field(gt=0)                    # ✅ 类型 + 范围
    quantity: int = Field(ge=1, le=100)              # ✅ 1~100 之间
    email: str = Field(pattern=r'^[\w.+-]+@[\w-]+\.[a-z]{2,}$')  # ✅ 格式
    channel: Literal["web", "app", "api"]            # ✅ 枚举白名单

@app.post("/orders")
def create_order(body: CreateOrderRequest):          # ✅ 入口即校验
    return order_service.create(body)                # 业务层拿到的已是合法数据
  • 使用 Pydantic(Python)、Zod(TypeScript)、Joi(Node.js)等成熟校验库,不手写正则堆砌。

2. 白名单优先于黑名单;枚举/路径/文件名严格限定

规则: 对枚举值用白名单(只接受已知合法值),不用黑名单(拒绝已知危险值);文件名和路径做规范化后校验,防止路径穿越(../../../etc/passwd);用户可控的文件名只允许 [a-zA-Z0-9._-]

为什么: AI 实现文件操作时惯用黑名单:if ".." in filename: reject。这类黑名单极容易被绕过——URL 编码 %2e%2e、双重编码 %252e%252e、Unicode 等价字符都能轻易规避。路径穿越漏洞至今仍是 OWASP Top 10 常见漏洞之一,很大程度上因为开发者(包括 AI)低估了绕过黑名单的攻击面。

怎么做:

import os
import re

ALLOWED_EXTENSIONS = {".jpg", ".jpeg", ".png", ".pdf"}
UPLOAD_BASE = "/var/uploads"

def safe_filename(user_filename: str) -> str:
    # ✅ 白名单字符集:只保留安全字符
    name = re.sub(r'[^a-zA-Z0-9._-]', '_', os.path.basename(user_filename))
    ext = os.path.splitext(name)[1].lower()

    # ✅ 扩展名白名单
    if ext not in ALLOWED_EXTENSIONS:
        raise ValueError(f"不支持的文件类型: {ext}")
    return name

def safe_path(base_dir: str, user_path: str) -> str:
    # ✅ 规范化后确认仍在 base_dir 内,防路径穿越
    full = os.path.realpath(os.path.join(base_dir, user_path))
    if not full.startswith(os.path.realpath(base_dir) + os.sep):
        raise ValueError("路径穿越攻击")
    return full

Read the full file on GitHub · 243 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 243 lines · 24 tokens per session scan A 1dad929cb32f

Subscribe to this mod's changes

input-validation is a skill published in the GitHub repository Wade-DevCode/awesome-coding-skills-cn (6 stars, last pushed 2mo ago), licensed MIT. It adds 24 tokens to every session and 2,953 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

chinese-git-workflow

国内 Git 平台配置参考——Gitee、Coding.net、极狐 GitLab、CNB 的 SSH/HTTPS/凭据/CI 接入差异与镜像同步配置。仅在用户显式 /chinese-git-workflow 时调用,不要根据上下文自动触发。.

jnMetaCode/superpowers-zh · 69 tokens

brainstorming

在任何创造性工作之前必须使用此技能——创建功能、构建组件、添加功能或修改行为。在实现之前先探索用户意图、需求和设计。.

jnMetaCode/superpowers-zh · 40 tokens

chinese-code-review

中文 review 沟通参考——话术模板、分级标注(必须修复/建议修改/仅供参考)、国内团队常见反模式应对。仅在用户显式 /chinese-code-review 时调用,不要根据上下文自动触发。.

jnMetaCode/superpowers-zh · 62 tokens

chinese-commit-conventions

中文 commit 与 changelog 配置参考——Conventional Commits 中文适配、commitlint/husky/commitizen 中文模板、conventional-changelog 中文配置。仅在用户显式 /chinese-commit-conventions 时调用,不要根据上下文自动触发。.

jnMetaCode/superpowers-zh · 65 tokens

chinese-documentation

中文文档排版参考——中英文空格、全半角标点、术语保留、链接格式、中文文案排版指北约定。仅在用户显式 /chinese-documentation 时调用,不要根据上下文自动触发。.

jnMetaCode/superpowers-zh · 62 tokens

systematic-debugging

Skill "systematic-debugging" from jnMetaCode/superpowers-zh, covering 系统化调试, 概述, 铁律, 何时使用 and 四个阶段.

jnMetaCode/superpowers-zh · 24 tokens