跳转到正文
报告库
用途分类 / 内容写作

Workers Best Practices Skill 安全审计

作者说它能做什么(原文)

Cloudflare Workers best practices for production applications. Use when writing, reviewing, or configuring Workers.

第三方安全检查结论

发现安全风险

已检查文件
4
发现的风险
1
会不会运行危险命令?检查是否下载程序后直接运行、让他人远程控制电脑,或藏起要运行的命令。未发现风险
会不会泄露文件和密钥?检查是否发送含密码或密钥的文件,以及代码里是否直接写了密钥。发现 1 项风险
中风险

默认启用生产日志和追踪可能记录敏感请求或错误信息

原文依据:5 处
发现了什么

该 Skill 要求生产 Worker 启用日志和追踪,并提供记录请求路径及原始错误消息的结构化日志示例。路径可能包含用户或资源标识,异常消息也可能包含输入、内部服务信息或其他敏感数据;正文没有要求脱敏、访问限制或保留期限。

为什么需要注意

若代理照此修改处理敏感流量的 Worker,Cloudflare 日志系统及有权查看日志的人可能获得原本不应长期保存的请求或错误数据。全量日志采样还可能增加可观测性费用。

该要求属于正常的生产可观测性配置,并非秘密收集机制;但风险有实际依据:Skill 要求在生产部署前启用日志和追踪,并示例把请求路径和原始异常消息写入日志。如果路径含用户/资源标识,或异常消息回显输入、令牌及内部信息,这些内容会进入 Cloudflare 日志;所示指导未同时要求脱敏、限制访问或设置保留期。用户可要求作者明确敏感字段过滤、日志访问权限、采样和保留策略。

SKILL.md:26来自说明文档打开原文件
## Enable ObservabilityEnable [Workers Logs](https://developers.cloudflare.com/workers/observability/logs/workers-logs/) and [Traces](https://developers.cloudflare.com/workers/observability/traces/) when creating or preparing a Worker for production. Set `observability.enabled` and `observability.traces.enabled` to `true`; the top-level setting alone does not enable traces. Use structured JSON logging and configure sampling for the workload. During reviews, flag missing logs or traces. See the [configuration example](references/configuration.md#enable-workers-logs-and-traces).
查看另外 4 个位置
references/configuration.md:111来自说明文档打开原文件
Enable Workers Logs and Traces in Wrangler config before deploying to production. Set `observability.enabled` and `observability.traces.enabled` to `true`; the top-level setting alone does not enable traces. Use `head_sampling_rate` to control volume and cost. Use structured JSON logging — `console.log(JSON.stringify({...}))` — so logs are searchable. Use `console.error` for errors (appears at error severity in the dashboard).**Check**: logs and traces are enabled in the target deployment environment, with neither disabled by an environment override. Check `observability.enabled`, `observability.logs.enabled`, and `observability.traces.enabled`, accounting for their defaults. Logging uses structured JSON, not string concatenation.
references/configuration.md:125来自说明文档打开原文件
```ts// Structured JSON — searchable and filterableconsole.log(JSON.stringify({ message: "incoming request", method: request.method, path: url.pathname }));// Error severityconsole.error(JSON.stringify({ message: "request failed", error: e instanceof Error ? e.message : String(e) }));```
references/configuration.md:117来自说明文档打开原文件
{  "observability": {    "enabled": true,    "logs": { "enabled": true, "head_sampling_rate": 1 },    "traces": { "enabled": true, "head_sampling_rate": 0.01 }  }}
references/runtime-patterns.md:301来自说明文档打开原文件
    return Response.json(result);  } catch (error) {    const message = error instanceof Error ? error.message : "Unknown error";    console.error(JSON.stringify({ message: "unhandled error", error: message, path: new URL(request.url).pathname }));    return Response.json({ error: "Internal server error" }, { status: 500 });  }
会不会删除文件或一直在后台运行?检查是否大范围删除文件、改写磁盘,或设置自动启动。未发现风险
会不会绕过安全保护?检查是否跳过网站安全验证、开放过多文件权限,或取消操作前的确认。未发现风险
会不会误导 AI 或隐藏内容?检查工作说明是否要求 AI 忽略你的指令、干扰检查结果,或夹带看不见的文字。未发现风险
会不会偷偷改推广链接或收款方?检查是否强制替换推广链接或收款对象,同时要求隐瞒更改。未发现风险

Skill 逻辑拆解

6 个说明模块

该 Skill 用于编写或审查 Cloudflare Workers,并要求以项目现有 Wrangler 配置、生成类型和兼容性设置为基准,再通过 Cloudflare 文档核实不确定的 API 与运行时行为。

查看原文
SKILL.md:6来自说明文档打开原文件
Your knowledge of Cloudflare Workers APIs, types, and configuration may be outdated. **Prefer retrieval over pre-training** when writing or reviewing Workers code.Use the project's installed versions, generated types, and Wrangler compatibility settings as the baseline for existing code. Retrieve relevant Cloudflare documentation to verify API, configuration, runtime behavior, and limit claims.

它要求检查受影响行为的类型和运行时测试,并明确表示局部修改不需要全面审计,限制了验证范围。

查看原文
SKILL.md:50来自说明文档打开原文件
## ValidationUse the project's existing checks for affected Workers behavior: type-check binding or handler contract changes, and run relevant runtime tests for behavior changes. Preserve required repository checks; a narrow edit does not require a full Workers audit.

该 Skill 建议通过 Wrangler secrets 管理凭据,并检查源码、配置和本地环境文件,目的是避免凭据进入版本控制。

查看原文
references/configuration.md:63来自说明文档打开原文件
### Store secrets with wrangler secretSecrets must never appear in wrangler config or source code. Use `wrangler secret put` and access via `env` at runtime. Non-secret config goes in `vars`.**Check**: no string literals that look like API keys, tokens, or credentials. Verify `.env` is in `.gitignore` for local dev.

文档中的网络请求、令牌和可预测随机数代码被明确标为示例或反模式,不是要求执行或使用其中的占位凭据。

查看原文
references/runtime-patterns.md:103来自说明文档打开原文件
Anti-pattern:```ts// REST API from inside a Worker — unnecessary overheadconst response = await fetch(  "https://api.cloudflare.com/client/v4/accounts/.../r2/buckets/.../objects/my-file",  { headers: { Authorization: `Bearer ${env.CF_API_TOKEN}` } });```
从这里开始 · 工作说明SKILL.md
workers-best-practices
连线表示工作说明包含的模块,不是实际运行顺序。点击模块可查看原文。

文件引用关系图

4 处引用
哪些文件发起引用引用了什么
连线表示真实的文件引用,不是运行顺序。点击节点可高亮相关连线,并查看具体文件和原文位置。虚线表示还有文件需要定位。
文件与检查记录4 个文件

检查范围与遗漏

逐文件查看涉及的内容

下方列出本次涉及的原文范围;纳入检查不代表已查清所有问题。

  • SKILL.md已纳入全文
  • references/configuration.md已纳入全文
  • references/platform-apis.md已纳入全文
  • references/runtime-patterns.md已纳入全文

这份报告只针对上方版本。我们看了拿到的代码和说明文件,没有实际运行 Skill,也没有检查它另外安装的软件包。因此,这不是“保证安全”的承诺;换了版本或使用环境,结果也可能不同。

  • SKILL.md工作说明
  • references/configuration.md配套文件
  • references/platform-apis.md配套文件
  • references/runtime-patterns.md配套文件

代码和说明中提到的操作

连接外部网站
SKILL.md:20来自说明文档打开原文件
For missing evidence, consult [Workers best practices](https://developers.cloudflare.com/workers/best-practices/workers-best-practices/) or find the affected product in the [Cloudflare docs directory](https://developers.cloudflare.com/directory/). Use the installed Wrangler schema for config fields. A newer type package does not supersede the project's configured target.
SKILL.md:28来自说明文档打开原文件
Enable [Workers Logs](https://developers.cloudflare.com/workers/observability/logs/workers-logs/) and [Traces](https://developers.cloudflare.com/workers/observability/traces/) when creating or preparing a Worker for production. Set `observability.enabled` and `observability.traces.enabled` to `true`; the top-level setting alone does not enable traces. Use structured JSON logging and configure sampling for the workload. During reviews, flag missing logs or traces. See the [configuration example](references/configuration.md#enable-workers-logs-and-traces).
SKILL.md:59来自说明文档打开原文件
- **Durable Objects**: load the `durable-objects` skill- **Workflows**: see [Rules of Workflows](https://developers.cloudflare.com/workflows/build/rules-of-workflows/)- **Wrangler CLI commands**: load the `wrangler` skill
读取密钥或账号配置
SKILL.md:35来自说明文档打开原文件
| `await response.text()` or similar buffering on unbounded data | Can exhaust Worker memory; [stream large or unbounded bodies](references/runtime-patterns.md#stream-request-and-response-bodies). || Hardcoded secrets in source or config | Leaks credentials through version control; use Wrangler secrets. || `Math.random()` for security-sensitive tokens or IDs | Predictable values; use `crypto.randomUUID()` or `crypto.getRandomValues()`. |
SKILL.md:46来自说明文档打开原文件
| `as unknown as T` to force a platform type match | Hides incompatibilities; fix the underlying contract. || `implements` used in place of extending a platform base class | Does not inherit runtime behavior, `this.ctx`, or `this.env`; use the appropriate base class. || Unbound `env.X` in a platform class method | Bindings are available through `this.env.X`; see [binding access patterns](references/platform-apis.md#binding-access--the-most-common-error). |
SKILL.md:47来自说明文档打开原文件
| `implements` used in place of extending a platform base class | Does not inherit runtime behavior, `this.ctx`, or `this.env`; use the appropriate base class. || Unbound `env.X` in a platform class method | Bindings are available through `this.env.X`; see [binding access patterns](references/platform-apis.md#binding-access--the-most-common-error). || Applying one serialization rule across Queues, Workflow steps, storage, and WebSockets | Can reject valid payloads or accept unsupported ones; check the [specific API and encoding](references/platform-apis.md#serialization-boundaries). |
读取了多少行
593
文件校验值(用于核对版本)
5a92d5c9b7644d34eb38779de22364b8524861f3c536a9d4329aae18e30f5b45