application-security

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Application Security

应用安全

Use this capability whenever you write or review code that handles untrusted input, secrets, outbound requests, rendered content, or third-party dependencies. It runs in two modes over the same set of rules:
  • Build — write the code secure by default. Choose the construction that is safe by shape (parse at the boundary, encode at the sink, allowlist the host) rather than the one you must remember to guard later.
  • Review — read a change for the risk it introduces and flag it with a severity, so the fix lands before merge. The review rules name a severity (Critical / Major / Minor) for each risk; align them to the host project's review severity vocabulary when it defines one.
The framing is the OWASP Top 10:2025. Each reference below carries both modes for one risk. The references are written against a common web-application shape — a framework with a public/client-exposed env-var prefix, a content renderer, an image optimizer, metadata routes. When your project differs, apply the same rule to your project's equivalent surface rather than skipping it; when a rule depends on another discipline (dependency justification, review scoping), it points to that discipline in words, so this capability stays usable on its own.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
当你编写或审查处理不可信输入、密钥、出站请求、渲染内容或第三方依赖的代码时,可使用此能力。它基于同一套规则提供两种运行模式:
  • 构建模式 — 编写默认安全的代码。选择从本质上安全的实现方式(在边界处解析、在输出点编码、对主机进行白名单管控),而非后续需要额外添加防护的实现。
  • 审查模式 — 检查代码变更所引入的风险,并标记风险级别,确保问题在合并前得到修复。审查规则会为每种风险标注严重程度(Critical / Major / Minor);若项目自身定义了审查严重程度术语,需与之对齐。
本能力以OWASP Top 10:2025为框架。以下每个参考项都包含针对某一风险的两种模式。参考内容基于通用Web应用架构编写——包含带有公开/客户端暴露环境变量前缀的框架、内容渲染器、图片优化器、元数据路由。若你的项目架构不同,请将规则应用到项目对应的等效层面,而非直接跳过;当某条规则依赖其他规范(如依赖合理性验证、审查范围界定)时,文档会以文字形式指向对应规范,确保本能力可独立使用。
本文档中的关键词「MUST」「MUST NOT」「REQUIRED」「SHALL」「SHALL NOT」「SHOULD」「SHOULD NOT」「RECOMMENDED」「MAY」和「OPTIONAL」,其释义遵循RFC 2119中的定义。

OWASP Top 10:2025 Coverage

OWASP Top 10:2025 覆盖范围

Two 2025 relocations matter for routing: SSRF is no longer its own category — it folded into A01 Broken Access Control — and vulnerable/outdated components expanded into the new A03 Software Supply Chain Failures.
Risk topicPrimary OWASP Top 10:2025 categoryReference
Secrets & environment varsA04 Cryptographic Failures, A02 Security Misconfiguration
secret-handling
Input validationA05 Injection
input-validation
Injection & output encodingA05 Injection
injection-and-output-encoding
SSRF & outbound fetchA01 Broken Access Control
ssrf-and-embeds
Access control & data exposureA01 Broken Access Control, A02 Security Misconfiguration
privacy-and-exposure
Supply chainA03 Software Supply Chain Failures
supply-chain
2025版中的两项分类调整需要注意:SSRF不再作为独立分类——被归入A01 访问控制失效;而易受攻击/过时组件分类扩展为新的A03 软件供应链故障
风险主题对应OWASP Top 10:2025主分类参考项
密钥与环境变量A04 加密失效、A02 安全配置错误
secret-handling
输入验证A05 注入
input-validation
注入与输出编码A05 注入
injection-and-output-encoding
SSRF与出站fetchA01 访问控制失效
ssrf-and-embeds
访问控制与数据暴露A01 访问控制失效、A02 安全配置错误
privacy-and-exposure
供应链A03 软件供应链故障
supply-chain

Secret and Environment-Variable Handling

密钥与环境变量处理

See secret-handling.md for:
  • writing code that reads secrets through one env boundary and keeps them out of logs, telemetry, and client bundles
  • reviewing a diff for a committed credential, a
    process.env
    access outside the whitelist, or a secret exposed through a client-prefixed env var
  • keeping example env files and
    .env.example
    documentation honest without real values
详见secret-handling.md
  • 编写通过统一环境边界读取密钥的代码,确保密钥不会出现在日志、遥测数据和客户端包中
  • 审查代码差异,检查是否存在提交的凭证、白名单外的
    process.env
    访问,或通过客户端前缀环境变量暴露的密钥
  • 确保示例环境文件和
    .env.example
    文档仅包含示例值,不涉及真实密钥

Input Validation

输入验证

See input-validation.md for:
  • parsing and coercing every request input at the boundary before it reaches the data layer, an outbound
    fetch
    , or a rendering pipeline
  • treating route params, query params, bodies, and stored records as untrusted regardless of their static types
  • reviewing a handler, server action, data-access function, or file upload for a missing runtime check
详见input-validation.md
  • 在请求输入进入数据层、出站
    fetch
    或渲染管道前,在边界处完成所有输入的解析与强制转换
  • 无论静态类型如何,都将路由参数、查询参数、请求体和存储记录视为不可信内容
  • 审查处理器、服务器动作、数据访问函数或文件上传功能,检查是否缺少运行时校验

Injection and Output Encoding

注入与输出编码

See injection-and-output-encoding.md for:
  • encoding untrusted content per output context and rendering it only through the framework's safe sinks
  • allowlisting URL schemes and sanitizing rich-text HTML when the format permits it
  • reviewing a render component, custom node, or pipeline change for a raw-HTML sink or a bypassed encoding path
详见injection-and-output-encoding.md
  • 根据输出上下文对不可信内容进行编码,仅通过框架的安全输出点渲染内容
  • 当格式允许时,对URL协议进行白名单管控,并清理富文本HTML
  • 审查渲染组件、自定义节点或管道变更,检查是否存在原始HTML输出点或绕过编码的路径

SSRF and Outbound Fetch

SSRF与出站Fetch

See ssrf-and-embeds.md for:
  • fetching a user- or CMS-controlled URL safely: allowlist over denylist, resolve-and-validate against reserved ranges, redirect and DNS-rebinding handling, tight timeouts
  • the outbound-fetch triage diagram and the reserved-range / cloud-metadata reference table
  • reviewing a new fetch caller, image host entry, metadata route, or mutation endpoint for an SSRF or CSRF gap
详见ssrf-and-embeds.md
  • 安全地获取用户或CMS控制的URL:优先使用白名单而非黑名单,解析并验证地址是否属于保留范围,处理重定向和DNS绑定问题,设置严格超时
  • 出站fetch分类流程图及保留范围/云元数据参考表
  • 审查新的fetch调用方、图片主机条目、元数据路由或突变端点,检查是否存在SSRF或CSRF漏洞

Access Control and Data Exposure

访问控制与数据暴露

See privacy-and-exposure.md for:
  • defaulting to the least data on public surfaces and gating unpublished, preview, and admin content behind an explicit check
  • keeping internal identifiers, storage keys, and environment-derived values out of public responses, metadata, and analytics
  • reviewing a diff for a public route, metadata generator, or localhost-gated path that leaks non-public data
详见privacy-and-exposure.md
  • 公共界面默认返回最少数据,未发布内容、预览内容和管理员内容需通过显式校验才能访问
  • 避免在公共响应、元数据和分析数据中泄露内部标识符、存储密钥和环境衍生值
  • 审查代码差异,检查公共路由、元数据生成器或本地主机受限路径是否泄露非公开数据

Supply Chain

供应链

See supply-chain.md for:
  • admitting a dependency deliberately: justified, maintained, platform-agnostic, lockfile-pinned, and installed without unvetted lifecycle scripts
  • preferring a standard-library or platform API over a thin new dependency
  • reviewing a manifest or lockfile change for an unjustified, heavyweight, or risky addition
详见supply-chain.md
  • 审慎引入依赖:确保依赖具备合理性、得到维护、平台无关、已锁定版本,且安装过程中不包含未审核的生命周期脚本
  • 优先使用标准库或平台API,而非新增轻量依赖
  • 审查清单或锁文件变更,检查是否引入不合理、重量级或高风险的依赖