跳转到正文
报告库
用途分类 / 数据分析

Write Swift Skill 安全审计

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

How to write modern Swift well — modeling with value types, Swift 6 data-race safety and approachable concurrency (@concurrent, main-actor-by-default, actors, task groups), protocols and generics (some vs any), API design, performance and ARC, Swift Testing, macros, and the modern language features agents don't know about yet. Use when writing, reviewing, or migrating Swift, or when a concurrency

第三方安全检查结论

发现安全风险

已检查文件
1
发现的风险
1
会不会运行危险命令?检查是否下载程序后直接运行、让他人远程控制电脑,或藏起要运行的命令。发现 1 项风险
中风险

对 weak 引用使用强制解包可能把正常生命周期变化变成应用崩溃

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

文档称 weak 引用在强所有者最后一次使用后变为 nil 是合法行为,却同时表示可选绑定比强制解包“更糟”。若代理据此把安全的 nil 处理改成 `!`,对象正常释放就会触发运行时陷阱。

为什么需要注意

受影响进程可能立即崩溃;如果该路径可由请求、界面事件或外部输入反复触发,会形成拒绝服务或数据未保存风险。

该内容是面向实际编码的主动建议,不是警告、否定示例或测试。它先承认 `weak` 引用可能因对象正常释放而合法变为 `nil`,随后却宣称可选绑定比强制解包更差。若代理据此把安全的 nil 分支改成 `!`,对象在读取前释放时会触发运行时崩溃,造成拒绝服务或数据未保存。用户可要求作者保留显式 nil 处理,或仅在有可证明的强生命周期保证时允许强制解包。

SKILL.md:254来自说明文档打开原文件
- **An object's guaranteed lifetime ends at its last use, not at the closing brace.** Observed lifetimes are an emergent property of the optimizer and _will_ change. Code that depends on when a `deinit` runs is a latent bug.- **`weak`/`unowned` are for breaking reference cycles — nothing else.** Reading a `weak` reference after the strong owner's last use may legitimately give `nil`. Optional binding there is _worse_ than force-unwrap: it turns a loud crash into a silent wrong answer.
查看另外 2 个位置
SKILL.md:255来自说明文档打开原文件
- **An object's guaranteed lifetime ends at its last use, not at the closing brace.** Observed lifetimes are an emergent property of the optimizer and _will_ change. Code that depends on when a `deinit` runs is a latent bug.- **`weak`/`unowned` are for breaking reference cycles — nothing else.** Reading a `weak` reference after the strong owner's last use may legitimately give `nil`. Optional binding there is _worse_ than force-unwrap: it turns a loud crash into a silent wrong answer.- **Better than `weak`: don't build the cycle.** Factor the shared data into a third type both sides reference, turning the cycle into a tree.
SKILL.md:257来自说明文档打开原文件
- **Better than `weak`: don't build the cycle.** Factor the shared data into a third type both sides reference, turning the cycle into a tree.- **Next best: redesign the API** so the object is only reachable through a strong reference. `withExtendedLifetime` works but shifts correctness onto you and spreads through a codebase — treat it as a patch, not a design.- **Keep `deinit` side effects local.** Publishing metrics or firing a global effect from `deinit` sequences against optimizer decisions. Use `defer` at the call site instead, and leave `deinit` for verification.
会不会泄露文件和密钥?检查是否发送含密码或密钥的文件,以及代码里是否直接写了密钥。未发现风险
会不会删除文件或一直在后台运行?检查是否大范围删除文件、改写磁盘,或设置自动启动。未发现风险
会不会绕过安全保护?检查是否跳过网站安全验证、开放过多文件权限,或取消操作前的确认。未发现风险
会不会误导 AI 或隐藏内容?检查工作说明是否要求 AI 忽略你的指令、干扰检查结果,或夹带看不见的文字。未发现风险
会不会偷偷改推广链接或收款方?检查是否强制替换推广链接或收款对象,同时要求隐瞒更改。未发现风险

Skill 逻辑拆解

8 个说明模块

该 Skill 是面向 Swift 编写、审查、迁移和故障修复的指导文档;提供语言与设计建议,没有展示安装步骤、外部网络请求、凭据读取或自动执行脚本。

查看原文
SKILL.md:3来自说明文档打开原文件
name: write-swiftdescription: How to write modern Swift well — modeling with value types, Swift 6 data-race safety and approachable concurrency (@concurrent, main-actor-by-default, actors, task groups), protocols and generics (some vs any), API design, performance and ARC, Swift Testing, macros, and the modern language features agents don't know about yet. Use when writing, reviewing, or migrating Swift, or when a concurrency error, a hang, a data race, a retain cycle, or a performance problem needs fixing.---
SKILL.md:8来自说明文档打开原文件
How to write Swift the way the language wants to be written, current through Swift 6.4.

文档把 Swift 6.3 作为基线,并声称未特别标记的内容可在该版本编译;同时说明其并发规则不适用于 Swift 6.1 或更早版本。用户应让执行者先核对项目工具链。

查看原文
SKILL.md:10来自说明文档打开原文件
**Toolchain baseline: Swift 6.3** (current release as of August 2026). Everything here compiles on 6.3 unless marked ⚠, which flags unreleased Swift 6.4 features. Concurrency guidance assumes the Swift 6.2 model — if the project is on 6.1 or earlier, §3's rules about `async` and `@concurrent` do not apply.
SKILL.md:318来自说明文档打开原文件
**Rows marked ⚠ are Swift 6.4, which has not shipped.** The current release is 6.3.x. Their proposals are accepted and implemented in main, so they are safe to plan around and unsafe to write today — check the project's toolchain before using one, and prefer the older form if it targets 6.3 or earlier.

对不安全内存操作,文档建议优先使用安全 API、缩小指针操作范围并启用 Address Sanitizer;这会限制而不是扩大内存访问风险。

查看原文
SKILL.md:307来自说明文档打开原文件
- **"Unsafe" means the API cannot fully validate its input, so violating its preconditions is undefined behavior** — not that it crashes. Safe APIs _do_ trap deliberately; a clean fatal error is the safe outcome.- **Prefer `Span` over `Unsafe*Pointer`.** Since Swift 6.2 there is a safe, non-escaping, equally fast way to get at contiguous storage. Reserve raw pointers for C interop.- If you must use pointers: keep the unsafe region as small as possible, use **buffer** pointers (address + count) rather than bare pointers so bounds are tracked, never let a pointer escape the closure that vends it, and run the **Address Sanitizer**.
SKILL.md:308来自说明文档打开原文件
- **Prefer `Span` over `Unsafe*Pointer`.** Since Swift 6.2 there is a safe, non-escaping, equally fast way to get at contiguous storage. Reserve raw pointers for C interop.- If you must use pointers: keep the unsafe region as small as possible, use **buffer** pointers (address + count) rather than bare pointers so bounds are tracked, never let a pointer escape the closure that vends it, and run the **Address Sanitizer**.- Enable **strict memory safety** in security-critical modules — it forces every unsafe use to be acknowledged in source, which is what makes an audit possible. Swift 6.4's `@diagnose` attribute (unreleased) lets you turn it on for individual functions.
从这里开始 · 工作说明SKILL.md
write-swift
连线表示工作说明包含的模块,不是实际运行顺序。点击模块可查看原文。 另有 9 个章节,可在原文件中查看。
文件与检查记录1 个文件

检查范围与遗漏

逐文件查看涉及的内容

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

  • SKILL.md已纳入全文

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

  • SKILL.md工作说明

代码和说明中提到的操作

运行命令
SKILL.md:327来自说明文档打开原文件
| `NotificationCenter` with stringly-typed `userInfo`                   | concrete notification types (`MainActorMessage` / `AsyncMessage`)                                        | 6.2   || `Process` + pipes for scripting                                       | the **Subprocess** package (`AsyncBufferSequence.strings()` for line-by-line output; 1.0 lands with 6.4) | 6.2+  || Hand-rolled string index math                                         | **Swift Regex** — literals for brevity, `RegexBuilder` for structure                                     | 5.7   |
读取了多少行
389
文件校验值(用于核对版本)
6fb7ef4dd4a424f32fa532b1b0c43085dbdc09cde1d574786cbb848c67e4d982