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

Better Auth Best Practices Skill 安全审计

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

Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables. Use when users mention Better Auth, betterauth, auth.ts, or need to set up TypeScript authentication with email/password, OAuth, or plugin configuration.

第三方安全检查结论

发现安全风险

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

迁移和代码生成命令执行未固定版本的远程 CLI

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

工作流反复使用 `npx auth@latest`。`npx` 可能下载并执行当时发布的最新 CLI,而不是项目锁文件中的 Better Auth 版本。这也与本 Skill 自己要求匹配已安装版本的原则不一致。

为什么需要注意

若最新版被破坏、供应链受损或与项目版本不兼容,它会在开发者权限下执行,并可能生成错误架构或实施不兼容迁移。

Skill 要求文档与项目安装版本匹配,却在迁移和生成步骤中指定 `auth@latest`。这可能让最新版 CLI 针对旧版运行并修改数据库或生成文件。用户可要求所有 CLI 命令采用解析出的兼容版本,而不是 `latest`。

SKILL.md:10来自说明文档打开原文件
Use documentation that matches the Better Auth version installed in the project. APIs and plugin names can differ across maintained release lines.1. Prefer a version explicitly named by the user.2. Otherwise, inspect the resolved `better-auth` version in the lockfile, falling back to the package manifest when no lockfile is available.3. When the Better Auth MCP is available, call `get_doc` with `/llms.txt` to resolve that package version to a documentation identifier. Pass the identifier to every `search_docs` call and pass result paths to `get_doc` unchanged.4. Without MCP, start at [better-auth.com/llms.txt](https://better-auth.com/llms.txt) and follow the matching version index.5. Use the latest documentation only when the project version cannot be determined or the user explicitly asks about the latest release or an upgrade.
查看另外 3 个位置
SKILL.md:28来自说明文档打开原文件
4. Create route handler for your framework5. Run migrations:   - **Built-in adapter:** `npx auth@latest migrate`   - **Drizzle:** `npx auth@latest generate --output src/db/auth-schema.ts` then `npx drizzle-kit push` (dev) or `npx drizzle-kit generate && npx drizzle-kit migrate` (prod)   - **Prisma:** `npx auth@latest generate --output prisma/schema.prisma` then `npx prisma migrate dev`6. Verify: call `GET /api/auth/ok` — should return `{ status: "ok" }`
SKILL.md:13来自说明文档打开原文件
1. Prefer a version explicitly named by the user.2. Otherwise, inspect the resolved `better-auth` version in the lockfile, falling back to the package manifest when no lockfile is available.3. When the Better Auth MCP is available, call `get_doc` with `/llms.txt` to resolve that package version to a documentation identifier. Pass the identifier to every `search_docs` call and pass result paths to `get_doc` unchanged.
SKILL.md:29来自说明文档打开原文件
5. Run migrations:   - **Built-in adapter:** `npx auth@latest migrate`   - **Drizzle:** `npx auth@latest generate --output src/db/auth-schema.ts` then `npx drizzle-kit push` (dev) or `npx drizzle-kit generate && npx drizzle-kit migrate` (prod)   - **Prisma:** `npx auth@latest generate --output prisma/schema.prisma` then `npx prisma migrate dev`6. Verify: call `GET /api/auth/ok` — should return `{ status: "ok" }`
会不会泄露文件和密钥?检查是否发送含密码或密钥的文件,以及代码里是否直接写了密钥。未发现风险
会不会删除文件或一直在后台运行?检查是否大范围删除文件、改写磁盘,或设置自动启动。发现 1 项风险
中风险

工作流可直接改写数据库架构和生成的架构文件

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

指令把 `migrate`、Drizzle `push` 和 Prisma 开发迁移列为标准步骤,并指定覆盖或创建架构文件;没有要求先审阅迁移计划、确认目标数据库或备份。

为什么需要注意

如果连接指向错误数据库,或生成结果与现有模型冲突,可能造成持久的架构变化、认证服务中断,甚至数据丢失。

这些是标准工作流中的实际命令:`migrate`、Drizzle `push`/`migrate` 会更改数据库,生成命令会写入指定架构路径。可见指令没有要求确认连接的是哪个数据库、预览差异或备份。用户可限制为本地/测试数据库,并要求在任何写入前审阅生成文件和迁移 SQL。

SKILL.md:28来自说明文档打开原文件
4. Create route handler for your framework5. Run migrations:   - **Built-in adapter:** `npx auth@latest migrate`   - **Drizzle:** `npx auth@latest generate --output src/db/auth-schema.ts` then `npx drizzle-kit push` (dev) or `npx drizzle-kit generate && npx drizzle-kit migrate` (prod)   - **Prisma:** `npx auth@latest generate --output prisma/schema.prisma` then `npx prisma migrate dev`6. Verify: call `GET /api/auth/ok` — should return `{ status: "ok" }`
查看另外 1 个位置
SKILL.md:181来自说明文档打开原文件
6. **Change email flow** - Sends to current email first, then new email7. **Drizzle: db not initialized** - `drizzleAdapter(db, ...)` requires a `db` instance from `drizzle()`. See `create-auth` skill for setup examples (node-postgres, postgres.js, Neon).8. **Drizzle: missing drizzle.config.ts** - `drizzle-kit` commands require a `drizzle.config.ts` pointing to the generated schema file and DB credentials.
会不会绕过安全保护?检查是否跳过网站安全验证、开放过多文件权限,或取消操作前的确认。发现 2 项风险
低风险

安装命令没有固定依赖版本

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

安装命令没有指定依赖版本。同样的命令以后可能下载不同代码,你实际安装的内容可能与这次检查时不同。

为什么需要注意

即使命令和报告没变,以后安装时也可能下载到另一份代码。

这是实际安装步骤,`npm install better-auth` 未指定版本,可能在不同时间解析到不同发布版本,并运行其安装生命周期脚本。用户可要求作者使用与项目锁文件一致的明确版本,并在安装前审查包及锁文件变更。

`npx auth@latest migrate` 明确选择当时的最新版 CLI,并执行会修改数据库结构的迁移。它不保证与项目已安装的 Better Auth 版本一致。用户可要求固定兼容的 CLI 版本,并在执行前确认数据库目标及迁移内容。

Drizzle 流程首先通过 `npx auth@latest` 下载并执行未固定的最新版 CLI;后续 `npx drizzle-kit` 也未在命令中固定版本。开发环境的 `push` 会直接改动数据库。用户可限制为锁文件中已审核的本地版本,并要求先生成和审阅迁移。

Prisma 流程执行 `npx auth@latest`,因此实际运行的生成器会随最新版变化;后续迁移命令也可能修改开发数据库。用户可要求固定与已安装依赖兼容的版本,并先检查生成文件和迁移计划。

快速参考再次给出 `npx auth@latest migrate`。`latest` 会在执行时选择可变的远程版本,而该命令还会应用数据库结构变更。用户可要求固定版本、限定目标数据库并先预览迁移。

该生成命令使用未固定的 `auth@latest`,输出内容可能随发布时间改变,并可能改写项目中的 Prisma/Drizzle 架构文件。用户可要求使用锁定版本并在接受生成结果前审阅差异。

该命令使用未固定的最新版 CLI,并且用途是修改 AI 工具配置、为 Cursor 加入 MCP。风险不只是版本漂移,还包括配置和新增工具连接发生变化。用户可要求固定并审查 CLI 版本,同时先说明将修改的配置文件和端点。

SKILL.md:24来自说明文档打开原文件
1. Install: `npm install better-auth`2. Set env vars: `BETTER_AUTH_SECRET` and `BETTER_AUTH_URL`
查看另外 6 个位置
SKILL.md:29来自说明文档打开原文件
5. Run migrations:   - **Built-in adapter:** `npx auth@latest migrate`   - **Drizzle:** `npx auth@latest generate --output src/db/auth-schema.ts` then `npx drizzle-kit push` (dev) or `npx drizzle-kit generate && npx drizzle-kit migrate` (prod)
SKILL.md:30来自说明文档打开原文件
   - **Built-in adapter:** `npx auth@latest migrate`   - **Drizzle:** `npx auth@latest generate --output src/db/auth-schema.ts` then `npx drizzle-kit push` (dev) or `npx drizzle-kit generate && npx drizzle-kit migrate` (prod)   - **Prisma:** `npx auth@latest generate --output prisma/schema.prisma` then `npx prisma migrate dev`
SKILL.md:31来自说明文档打开原文件
   - **Drizzle:** `npx auth@latest generate --output src/db/auth-schema.ts` then `npx drizzle-kit push` (dev) or `npx drizzle-kit generate && npx drizzle-kit migrate` (prod)   - **Prisma:** `npx auth@latest generate --output prisma/schema.prisma` then `npx prisma migrate dev`6. Verify: call `GET /api/auth/ok` — should return `{ status: "ok" }`
SKILL.md:48来自说明文档打开原文件
### CLI Commands- `npx auth@latest migrate` - Apply schema (built-in adapter)- `npx auth@latest generate` - Generate schema for Prisma/Drizzle
SKILL.md:49来自说明文档打开原文件
- `npx auth@latest migrate` - Apply schema (built-in adapter)- `npx auth@latest generate` - Generate schema for Prisma/Drizzle- `npx auth@latest mcp --cursor` - Add MCP to AI tools
SKILL.md:50来自说明文档打开原文件
- `npx auth@latest generate` - Generate schema for Prisma/Drizzle- `npx auth@latest mcp --cursor` - Add MCP to AI tools
低风险

可通过 CLI 修改 AI 工具配置以加入 MCP

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

快速参考提供 `npx auth@latest mcp --cursor`,其说明是把 MCP 加入 AI 工具。来源没有说明它会修改哪些配置、启用哪些工具能力或连接哪些端点。

为什么需要注意

执行后可能持久改变 Cursor/AI 工具配置,并扩大代理可调用的集成范围;仅凭所给来源无法确定具体权限。

这是可执行的快速参考命令,明确用于把 MCP 加入 Cursor/AI 工具,但来源未说明会修改哪些配置、连接什么服务或授予哪些工具能力。用户可要求作者列明配置差异、端点及权限,并在明确批准前禁止运行。

SKILL.md:47来自说明文档打开原文件
### CLI Commands- `npx auth@latest migrate` - Apply schema (built-in adapter)- `npx auth@latest generate` - Generate schema for Prisma/Drizzle- `npx auth@latest mcp --cursor` - Add MCP to AI tools
会不会误导 AI 或隐藏内容?检查工作说明是否要求 AI 忽略你的指令、干扰检查结果,或夹带看不见的文字。未发现风险
会不会偷偷改推广链接或收款方?检查是否强制替换推广链接或收款对象,同时要求隐瞒更改。未发现风险

Skill 逻辑拆解

8 个说明模块

该 Skill 是 Better Auth 的集成指南,覆盖依赖安装、环境变量、认证配置、路由、数据库迁移和健康检查;提供的内容主要是操作指令,没有随附脚本。

查看原文
SKILL.md:22来自说明文档打开原文件
## Setup Workflow1. Install: `npm install better-auth`2. Set env vars: `BETTER_AUTH_SECRET` and `BETTER_AUTH_URL`3. Create `auth.ts` with database + config4. Create route handler for your framework5. Run migrations:   - **Built-in adapter:** `npx auth@latest migrate`   - **Drizzle:** `npx auth@latest generate --output src/db/auth-schema.ts` then `npx drizzle-kit push` (dev) or `npx drizzle-kit generate && npx drizzle-kit migrate` (prod)   - **Prisma:** `npx auth@latest generate --output prisma/schema.prisma` then `npx prisma migrate dev`6. Verify: call `GET /api/auth/ok` — should return `{ status: "ok" }`

它要求优先依据项目实际安装版本选择文档,并把当前版本与升级目标的指导分开。

查看原文
SKILL.md:10来自说明文档打开原文件
Use documentation that matches the Better Auth version installed in the project. APIs and plugin names can differ across maintained release lines.1. Prefer a version explicitly named by the user.2. Otherwise, inspect the resolved `better-auth` version in the lockfile, falling back to the package manifest when no lockfile is available.3. When the Better Auth MCP is available, call `get_doc` with `/llms.txt` to resolve that package version to a documentation identifier. Pass the identifier to every `search_docs` call and pass result paths to `get_doc` unchanged.4. Without MCP, start at [better-auth.com/llms.txt](https://better-auth.com/llms.txt) and follow the matching version index.5. Use the latest documentation only when the project version cannot be determined or the user explicitly asks about the latest release or an upgrade.When planning an upgrade, separate guidance for the currently installed version from guidance for the target version.

安全部分列出可强制安全 Cookie 的选项,并明确把关闭 CSRF 和来源检查标为风险;这些是参考说明,并未指示默认关闭检查。

查看原文
SKILL.md:119来自说明文档打开原文件
## Security**In `advanced`:**- `useSecureCookies` - Force HTTPS cookies- `disableCSRFCheck` - ⚠️ Security risk- `disableOriginCheck` - ⚠️ Security risk  - `crossSubDomainCookies.enabled` - Share cookies across subdomains- `ipAddress.ipAddressHeaders` - Custom IP headers for proxies- `database.generateId` - Custom ID generation or `"serial"`/`"uuid"`/`false`
从这里开始 · 工作说明SKILL.md
better-auth-best-practices
连线表示工作说明包含的模块,不是实际运行顺序。点击模块可查看原文。 另有 7 个章节,可在原文件中查看。
文件与检查记录1 个文件

检查范围与遗漏

逐文件查看涉及的内容

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

  • SKILL.md已纳入全文

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

  • SKILL.md工作说明

代码和说明中提到的操作

连接外部网站
SKILL.md:15来自说明文档打开原文件
3. When the Better Auth MCP is available, call `get_doc` with `/llms.txt` to resolve that package version to a documentation identifier. Pass the identifier to every `search_docs` call and pass result paths to `get_doc` unchanged.4. Without MCP, start at [better-auth.com/llms.txt](https://better-auth.com/llms.txt) and follow the matching version index.5. Use the latest documentation only when the project version cannot be determined or the user explicitly asks about the latest release or an upgrade.
SKILL.md:40来自说明文档打开原文件
- `BETTER_AUTH_SECRET` - Encryption secret (min 32 chars). Generate: `openssl rand -base64 32`- `BETTER_AUTH_URL` - Base URL (e.g., `https://example.com`)
SKILL.md:188来自说明文档打开原文件
- [Docs](https://better-auth.com/docs)- [Options Reference](https://better-auth.com/docs/reference/options)
安装其他软件包
SKILL.md:24来自说明文档打开原文件
1. Install: `npm install better-auth`2. Set env vars: `BETTER_AUTH_SECRET` and `BETTER_AUTH_URL`
SKILL.md:29来自说明文档打开原文件
5. Run migrations:   - **Built-in adapter:** `npx auth@latest migrate`   - **Drizzle:** `npx auth@latest generate --output src/db/auth-schema.ts` then `npx drizzle-kit push` (dev) or `npx drizzle-kit generate && npx drizzle-kit migrate` (prod)
SKILL.md:30来自说明文档打开原文件
   - **Built-in adapter:** `npx auth@latest migrate`   - **Drizzle:** `npx auth@latest generate --output src/db/auth-schema.ts` then `npx drizzle-kit push` (dev) or `npx drizzle-kit generate && npx drizzle-kit migrate` (prod)   - **Prisma:** `npx auth@latest generate --output prisma/schema.prisma` then `npx prisma migrate dev`
读取密钥或账号配置
SKILL.md:151来自说明文档打开原文件
**Popular plugins:** `twoFactor`, `organization`, `passkey`, `magicLink`, `emailOtp`, `username`, `phoneNumber`, `admin`, `apiKey`, `bearer`, `jwt`, `multiSession`, `sso`, `oauthProvider`, `oidcProvider`, `openAPI`, `genericOAuth`.
SKILL.md:182来自说明文档打开原文件
7. **Drizzle: db not initialized** - `drizzleAdapter(db, ...)` requires a `db` instance from `drizzle()`. See `create-auth` skill for setup examples (node-postgres, postgres.js, Neon).8. **Drizzle: missing drizzle.config.ts** - `drizzle-kit` commands require a `drizzle.config.ts` pointing to the generated schema file and DB credentials.
读取了多少行
193
文件校验值(用于核对版本)
402b523b36cc8cdd4efc83a1c8cb25c56c7327d08ecb168746456a0eaa2c1ea2