跳转到正文
报告库
用途分类 / 其他用途

Organization Best Practices Skill 安全审计

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

Configure multi-tenant organizations, manage members and invitations, define custom roles and permissions, set up teams, and implement RBAC using Better Auth's organization plugin. Use when users need org setup, team management, member roles, access control, or the Better Auth organization plugin.

第三方安全检查结论

先别安装或运行

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

安装步骤执行未固定版本的远程 CLI,并可直接迁移数据库

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

`npx auth@latest migrate` 会选择执行时的最新软件包代码,随后对数据库结构进行持久修改。指南没有要求先锁定并审核版本、查看迁移计划或备份数据库。

为什么需要注意

如果最新包被入侵、版本行为发生变化或迁移不兼容,CLI 可在开发者权限下执行代码,并可能导致数据库停机、结构损坏或数据不可用。

指南要求运行未固定版本的 `npx` CLI 来迁移数据库,并以新表是否存在作为验证,说明该步骤会改变数据库结构。来源没有提到预览迁移、备份或回滚。执行前可要求作者提供固定版本、生成的迁移 SQL、备份和回滚办法,并先对测试数据库运行。

SKILL.md:8来自说明文档打开原文件
1. Add `organization()` plugin to server config2. Add `organizationClient()` plugin to client config3. Run `npx auth@latest migrate` (built-in adapter) or generate + push for Drizzle/Prisma4. Verify: check that organization, member, invitation tables exist in your database
查看另外 2 个位置
SKILL.md:10来自说明文档打开原文件
2. Add `organizationClient()` plugin to client config3. Run `npx auth@latest migrate` (built-in adapter) or generate + push for Drizzle/Prisma4. Verify: check that organization, member, invitation tables exist in your database
SKILL.md:11来自说明文档打开原文件
3. Run `npx auth@latest migrate` (built-in adapter) or generate + push for Drizzle/Prisma4. Verify: check that organization, member, invitation tables exist in your database
会不会泄露文件和密钥?检查是否发送含密码或密钥的文件,以及代码里是否直接写了密钥。发现 1 项风险
中风险

邀请邮件把账户和组织名称直接插入原始 HTML

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

邮件模板将 `inviter.user.name` 和 `organization.name` 未经 HTML 转义直接放入 `html` 字符串。组织名称可在创建请求中设置;若这些名称包含攻击者提供的标记,邮件正文可能被篡改。

为什么需要注意

攻击者可能在可信应用发出的邀请邮件中插入误导性链接、图像或文字,从而诱导收件人访问钓鱼页面或披露敏感信息。实际结果取决于邮件发送器和客户端是否进行额外净化。

组织名称可由创建请求提供,而邀请邮件把该名称及邀请者姓名直接插入 HTML 字符串,示例未展示 HTML 转义或安全模板编码。若这些字段可包含 HTML,邮件显示内容或链接周边文字可能被注入或伪造。来源没有证明邮件客户端会执行脚本,因此风险应限于 HTML 内容篡改。用户可要求作者说明字段约束,并使用默认转义的邮件模板或对所有插值做上下文相关编码。

SKILL.md:43来自说明文档打开原文件
```tsconst createOrg = async () => {  const { data, error } = await authClient.organization.create({    name: "My Company",    slug: "my-company",    logo: "https://example.com/logo.png",    metadata: { plan: "pro" },  });};
查看另外 3 个位置
SKILL.md:164来自说明文档打开原文件
    organization({      sendInvitationEmail: async (data) => {        const { email, organization, inviter, invitation } = data;        await sendEmail({          to: email,          subject: `Join ${organization.name}`,          html: `            <p>${inviter.user.name} invited you to join ${organization.name}</p>            <a href="https://yourapp.com/accept-invite?id=${invitation.id}">              Accept Invitation            </a>          `,        });      },
SKILL.md:45来自说明文档打开原文件
const createOrg = async () => {  const { data, error } = await authClient.organization.create({    name: "My Company",    slug: "my-company",    logo: "https://example.com/logo.png",    metadata: { plan: "pro" },  });
SKILL.md:165来自说明文档打开原文件
      sendInvitationEmail: async (data) => {        const { email, organization, inviter, invitation } = data;        await sendEmail({          to: email,          subject: `Join ${organization.name}`,          html: `            <p>${inviter.user.name} invited you to join ${organization.name}</p>            <a href="https://yourapp.com/accept-invite?id=${invitation.id}">              Accept Invitation            </a>          `,        });
会不会删除文件或一直在后台运行?检查是否大范围删除文件、改写磁盘,或设置自动启动。未发现风险
会不会绕过安全保护?检查是否跳过网站安全验证、开放过多文件权限,或取消操作前的确认。发现 3 项风险
高风险

服务器端管理示例未展示调用者授权检查

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

示例使用服务器 API 代表任意 `userId` 创建组织并直接把任意用户加入指定组织,但代码没有验证当前调用者是否为系统管理员,或是否有权管理目标组织。文字称调用者为管理员并不能强制执行该权限。

为什么需要注意

如果开发者把这些调用封装成可由普通用户触发的接口,攻击者可能为自己或他人创建组织、绕过邀请流程,或把账户加入不应访问的租户。

这段证据能说明什么

文档称代建组织功能仅供管理员在服务端使用,但示例本身没有展示如何验证管理员身份;加成员示例也直接接受用户、角色和组织 ID。若这些调用被放进未受保护的路由,调用者可能创建组织、指定 owner 或篡改成员关系。不过来源未展示外层路由,也未证明 Better Auth API 内部没有权限检查,因此不能断定任意调用者实际可执行。用户应要求作者明确展示服务端鉴权和目标组织权限检查。

这项判断针对展示的代码和适用条件,不表示风险已经实际发生。
SKILL.md:70来自说明文档打开原文件
### Creating Organizations on Behalf of UsersAdministrators can create organizations for other users (server-side only):```tsawait auth.api.createOrganization({  body: {    name: "Client Organization",    slug: "client-org",    userId: "user-id-who-will-be-owner", // `userId` is required  },});```**Note**: The `userId` parameter cannot be used alongside session headers.
查看另外 4 个位置
SKILL.md:105来自说明文档打开原文件
### Adding Members (Server-Side)```tsawait auth.api.addMember({  body: {    userId: "user-id",    role: "member",    organizationId: "org-id",  },});```For client-side member additions, use the invitation system instead.
SKILL.md:72来自说明文档打开原文件
Administrators can create organizations for other users (server-side only):
SKILL.md:75来自说明文档打开原文件
```tsawait auth.api.createOrganization({  body: {    name: "Client Organization",    slug: "client-org",    userId: "user-id-who-will-be-owner", // `userId` is required  },});
SKILL.md:108来自说明文档打开原文件
```tsawait auth.api.addMember({  body: {    userId: "user-id",    role: "member",    organizationId: "org-id",  },});
中风险

依赖会话中的活动组织可能把操作发送到错误租户

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

活动组织存储在会话中,且邀请成员等端点在省略 `organizationId` 时会使用它。指南的邀请示例正好省略了组织标识;在多标签页、共享会话或切换组织后,代码可能使用过期或意外的活动租户。

为什么需要注意

有多个组织管理权限的用户可能将邀请或其他管理操作误发到错误组织,造成错误成员访问、隐私暴露或租户配置变更。插件自身的权限检查只能确认用户可管理该活动组织,无法判断这是不是用户此次想操作的组织。

指南说明活动组织保存在会话中,并且省略 `organizationId` 时,邀请成员等端点会使用该活动组织;其邀请示例确实省略了组织 ID。因此,只要会话中的活动组织不是界面所显示或用户预期的租户,邀请就可能发往错误组织。来源未证明多标签页必然触发问题,但这种隐式作用域是可信风险。用户可要求敏感写操作显式传入并在服务端核对组织 ID。

SKILL.md:87来自说明文档打开原文件
## Active OrganizationsStored in the session and scopes subsequent API calls. Set after user selects one.```tsconst setActive = async (organizationId: string) => {  const { data, error } = await authClient.organization.setActive({    organizationId,  });};```Many endpoints use the active organization when `organizationId` is not provided (`listMembers`, `listInvitations`, `inviteMember`, etc.).
查看另外 4 个位置
SKILL.md:183来自说明文档打开原文件
### Sending Invitations```tsawait authClient.organization.inviteMember({  email: "newuser@example.com",  role: "member",});```
SKILL.md:89来自说明文档打开原文件
Stored in the session and scopes subsequent API calls. Set after user selects one.
SKILL.md:99来自说明文档打开原文件
Many endpoints use the active organization when `organizationId` is not provided (`listMembers`, `listInvitations`, `inviteMember`, etc.).
SKILL.md:186来自说明文档打开原文件
```tsawait authClient.organization.inviteMember({  email: "newuser@example.com",  role: "member",});```
低风险

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

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

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

为什么需要注意

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

该安装步骤明确使用 `@latest`,因此每次执行可能取得不同版本的远程包代码。若上游版本发生破坏性变更或被污染,用户会在未固定、未复核具体版本的情况下运行它。可要求作者给出经过验证的固定版本,并在受限环境中先检查包和迁移内容。

SKILL.md:10来自说明文档打开原文件
2. Add `organizationClient()` plugin to client config3. Run `npx auth@latest migrate` (built-in adapter) or generate + push for Drizzle/Prisma4. Verify: check that organization, member, invitation tables exist in your database
会不会误导 AI 或隐藏内容?检查工作说明是否要求 AI 忽略你的指令、干扰检查结果,或夹带看不见的文字。未发现风险
会不会偷偷改推广链接或收款方?检查是否强制替换推广链接或收款对象,同时要求隐瞒更改。未发现风险

Skill 逻辑拆解

8 个说明模块

这是面向 Better Auth organization 插件的配置指南;提供的内容是需要复制到应用中的示例,而不是仓库内自动运行的实现。

查看原文
SKILL.md:2来自说明文档打开原文件
---name: organization-best-practicesdescription: Configure multi-tenant organizations, manage members and invitations, define custom roles and permissions, set up teams, and implement RBAC using Better Auth's organization plugin. Use when users need org setup, team management, member roles, access control, or the Better Auth organization plugin.---

指南涵盖创建组织、直接添加成员、邀请、角色权限、团队、生命周期钩子及组织删除;这些操作可能改变租户成员关系和持久数据。

查看原文
SKILL.md:103来自说明文档打开原文件
## Members### Adding Members (Server-Side)```tsawait auth.api.addMember({  body: {    userId: "user-id",    role: "member",    organizationId: "org-id",  },});```
SKILL.md:406来自说明文档打开原文件
### Organization DeletionDeleting an organization removes all associated data (members, invitations, teams). Prevent accidental deletion:

指南正确区分了仅用于界面显示的静态角色检查与动态权限端点,并说明组织删除可被禁用。

查看原文
SKILL.md:232来自说明文档打开原文件
Use `checkRolePermission({ role, permissions })` for client-side UI rendering (static only). For dynamic access control, use the `hasPermission` endpoint.
SKILL.md:410来自说明文档打开原文件
```tsorganization({  disableOrganizationDeletion: true, // Disable via config});```
从这里开始 · 工作说明SKILL.md
organization-best-practices
连线表示工作说明包含的模块,不是实际运行顺序。点击模块可查看原文。 另有 4 个章节,可在原文件中查看。
文件与检查记录1 个文件

检查范围与遗漏

逐文件查看涉及的内容

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

  • SKILL.md已纳入全文

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

  • SKILL.md工作说明

代码和说明中提到的操作

安装其他软件包
SKILL.md:10来自说明文档打开原文件
2. Add `organizationClient()` plugin to client config3. Run `npx auth@latest migrate` (built-in adapter) or generate + push for Drizzle/Prisma4. Verify: check that organization, member, invitation tables exist in your database
连接外部网站
SKILL.md:48来自说明文档打开原文件
    slug: "my-company",    logo: "https://example.com/logo.png",    metadata: { plan: "pro" },
SKILL.md:172来自说明文档打开原文件
            <p>${inviter.user.name} invited you to join ${organization.name}</p>            <a href="https://yourapp.com/accept-invite?id=${invitation.id}">              Accept Invitation
SKILL.md:198来自说明文档打开原文件
  role: "member",  callbackURL: "https://yourapp.com/dashboard",});
读取了多少行
480
文件校验值(用于核对版本)
1fa18fa9554155e1b1b2c866f7c2a1cbc0d363425bdaa98afd05ada1fcf9a2e0