@claude-flow/security

中文文档
3.0.7发布于 2026/11/09TypeScriptES Module近 30 天下载 20.1万

安全模块 - CVE 修正,输入验证,路径安全

中文使用文档
文档目录19 节
  1. 特征
  2. 安装
  3. 独立使用(没有 Ruflo CLI)
  4. 道具 — 验证输入, 散列密码, 生成 API 密钥
  5. 道具 — 拒绝命令注射+路径转弯
  6. 快速启动
  7. API 参考
  8. 密码搜索( CVE-2 Fix)
  9. 证书生成( CVE-3 Fix)
  10. 安全命令执行(HIGH-1 Fix)
  11. 路径验证( HIGH-2 Fix)
  12. 输入验证
  13. 脚本生成
  14. 安全常数
  15. 安保审计
  16. 验证Schemas
  17. 依赖关系
  18. 相关软件包
  19. 许可证

@ claude- flow/ 安全

npm version npm downloads License: MIT TypeScript Security Audit

Claude Flow V3 - CVE修正,输入验证,路径安全,以及安全证书管理的综合安全模块.

特征

  • CVE 补救 - 修理CVE-2(微软密码哈兴)、CVE-3(硬码证书)、HH-1(指令注射)、HH-2(Path Traversal)
  • 密码显示 - 使用可配置弹(建议12发以上)进行安全、基于bcrypt的密码散开
  • 证书生成 - 加密安全证书和API密钥生成
  • 安全命令执行 - 基于允许列表的命令执行,防止注射攻击
  • 路径验证 - 防止道路交叉和连锁攻击
  • 输入验证 - 所有输入类型的基于Zod的系统验证
  • 脚本生成 - 使用 HMAC 签名创建安全标志

安装

npm install @claude-flow/security

独立使用(没有 Ruflo CLI)

这是一个平坦的图书馆——每一个原始的(PasswordHasher, (中文(简体) ), PathValidator, (中文(简体) ), SafeExecutor, (中文(简体) ), InputValidator, (中文(简体) ), CredentialGenerator(中文(简体) ) 可独立导入。 没有CLI,没有MCP服务器,没有守护进程. 这个 原始人关闭了CVE-2(弱散列),CVE-3(默认证书), HH-1(指令注射)和HH-2(路径转弯)——放下 输入任何需要在系统边界验证的节点应用程序.

道具 — 验证输入, 散列密码, 生成 API 密钥

// recipe.mjs
import {
  InputValidator,
  EmailSchema,
  PasswordHasher,
  createCredentialGenerator,
} from '@claude-flow/security';

// 1. Validate user input at the boundary (Zod schemas, no surprises)
const email = InputValidator.validate(EmailSchema, '[email protected]');
//             ↳ throws if invalid; returns the typed value otherwise

// 2. Hash a password with bcrypt at the recommended cost (CVE-2)
//    Default policy: ≥8 chars, ≥1 upper, ≥1 lower, ≥1 digit.
//    Tune with new PasswordHasher({ rounds, requireUppercase, ... }).
const hasher = new PasswordHasher({ rounds: 12 });
const hash   = await hasher.hash('CorrectHorseBatteryStaple9');
const ok     = await hasher.verify('CorrectHorseBatteryStaple9', hash); // true

// 3. Generate a high-entropy API key (CVE-3) — uses crypto.randomBytes
//    under the hood and refuses to emit keys below 32 bytes of entropy.
const creds = createCredentialGenerator();
const apiKey = creds.generateApiKey('ck_live_');
console.log(apiKey.keyId, apiKey.key.slice(0, 16) + '…');
// → 7e2b1a9c-…  ck_live_xX9aQ…

道具 — 拒绝命令注射+路径转弯

import {
  createDevelopmentExecutor,
  createProjectPathValidator,
} from '@claude-flow/security';

// SafeExecutor — only the allow-listed commands ever run (HIGH-1)
const exec = createDevelopmentExecutor({ projectRoot: process.cwd() });
const { stdout } = await exec.execute('git', ['status', '--porcelain']);

// PathValidator — refuses traversal and symlinks out of the project (HIGH-2)
const paths = createProjectPathValidator(process.cwd());
const result = await paths.validate('../../etc/passwd');
if (!result.isValid) console.log('blocked:', result.errors.join('; '));
// → blocked: Path traversal pattern detected

快速启动

import { createSecurityModule } from '@claude-flow/security';

// Create a complete security module
const security = createSecurityModule({
  projectRoot: '/workspaces/project',
  hmacSecret: process.env.HMAC_SECRET!,
  bcryptRounds: 12,
  allowedCommands: ['git', 'npm', 'node']
});

// Hash a password
const hash = await security.passwordHasher.hash('userPassword123');

// Validate a path
const pathResult = await security.pathValidator.validate('/workspaces/project/src/file.ts');

// Execute command safely
const output = await security.safeExecutor.execute('git', ['status']);

// Generate secure credentials
const creds = await security.credentialGenerator.generate();

API 参考

密码搜索( CVE-2 Fix)

import { PasswordHasher, createPasswordHasher } from '@claude-flow/security';

const hasher = createPasswordHasher({ rounds: 12 });

// Hash password
const hash = await hasher.hash('password');

// Verify password
const isValid = await hasher.verify('password', hash);

// Check if hash needs rehashing
const needsRehash = hasher.needsRehash(hash);

证书生成( CVE-3 Fix)

import { CredentialGenerator, generateCredentials } from '@claude-flow/security';

const generator = new CredentialGenerator();

// Generate API key
const apiKey = await generator.generateApiKey({
  prefix: 'cf',
  length: 32
});

// Generate complete credentials
const creds = generateCredentials({
  includeApiKey: true,
  includeSecret: true
});

安全命令执行(HIGH-1 Fix)

import { SafeExecutor, createDevelopmentExecutor } from '@claude-flow/security';

const executor = createDevelopmentExecutor();

// Execute allowed command
const result = await executor.execute('git', ['status']);

// With timeout
const result2 = await executor.execute('npm', ['install'], {
  timeout: 60000,
  cwd: '/workspaces/project'
});

路径验证( HIGH-2 Fix)

import { PathValidator, createProjectPathValidator } from '@claude-flow/security';

const validator = createProjectPathValidator('/workspaces/project');

// Validate path
const result = await validator.validate('../../../etc/passwd');
// { valid: false, reason: 'Path traversal detected' }

// Safe path
const result2 = await validator.validate('/workspaces/project/src/index.ts');
// { valid: true, normalized: '/workspaces/project/src/index.ts' }

输入验证

import {
  InputValidator,
  SafeStringSchema,
  EmailSchema,
  PasswordSchema,
  SpawnAgentSchema
} from '@claude-flow/security';

// Validate email
const email = EmailSchema.parse('[email protected]');

// Validate password
const password = PasswordSchema.parse('SecurePass123!');

// Validate agent spawn request
const agentRequest = SpawnAgentSchema.parse({
  type: 'coder',
  name: 'code-agent-1'
});

// Sanitize HTML
import { sanitizeHtml } from '@claude-flow/security';
const safe = sanitizeHtml('<script>alert("xss")</script>Hello');
// 'Hello'

脚本生成

import { TokenGenerator, quickGenerate } from '@claude-flow/security';

const generator = new TokenGenerator({
  hmacSecret: process.env.HMAC_SECRET!
});

// Generate signed token
const token = await generator.generate({
  type: 'session',
  expiresIn: 3600
});

// Verify token
const verified = await generator.verify(token);

// Quick generation
const sessionToken = quickGenerate.sessionToken();
const verificationCode = quickGenerate.verificationCode();

安全常数

import {
  MIN_BCRYPT_ROUNDS,      // 12
  MAX_BCRYPT_ROUNDS,      // 14
  MIN_PASSWORD_LENGTH,    // 8
  MAX_PASSWORD_LENGTH,    // 72 (bcrypt limit)
  DEFAULT_TOKEN_EXPIRATION,   // 3600 (1 hour)
  DEFAULT_SESSION_EXPIRATION  // 86400 (24 hours)
} from '@claude-flow/security';

安保审计

import { auditSecurityConfig } from '@claude-flow/security';

const warnings = auditSecurityConfig({
  bcryptRounds: 10,
  hmacSecret: 'short'
});

// ['bcryptRounds (10) below recommended minimum (12)',
//  'hmacSecret should be at least 32 characters']

验证Schemas

司马说明
SafeStringSchema带长度限制的基本安全字符串
IdentifierSchema数字标识符
FilenameSchema安全文件名
EmailSchema电子邮件地址
PasswordSchema安全密码
UUIDSchemaUUID v4 格式
HttpsUrlSchema仅限 HTTPS URL
SemverSchema语义版本
PortSchema有效端口号
IPv4SchemaIPv4 地址
SpawnAgentSchema代理产卵请求
TaskInputSchema任务定义
SecurityConfigSchema安全配置

依赖关系

  • bcrypt - 密码散开
  • zod - Schema验证

许可证

麻省理工学院

版本与发布记录

@claude-flow/security 共发布 15 个版本,首次发布于 2026/01/07;过去 12 个月发布了 15 个版本。

版本发布日期距今
3.0.7latest2026/11/09今天
3.0.62026/11/019 天前
3.0.52026/10/1328 天前
3.0.42026/10/1130 天前
3.0.32026/10/091 个月前
3.0.22026/10/081 个月前

其他发布通道:alpha → 3.0.1,v3alpha → 3.0.1。

关于 @claude-flow/security 的常见问题

@claude-flow/security 是什么?

安全模块 - CVE 修正,输入验证,路径安全

如何安装 @claude-flow/security?

在项目目录运行 npm install @claude-flow/security,或使用 pnpm add / yarn add / bun add。

@claude-flow/security 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@claude-flow/security 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@claude-flow/security 可以商用吗?

@claude-flow/security 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@claude-flow/security 的下载量有多少?

根据 npm 官方下载统计,@claude-flow/security 在 2026/10/10 – 2026/11/08 这 30 天内被下载 200,901 次,日均约 6,697 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@claude-flow/security 还在维护吗?

最新版本 3.0.7 发布于 2026/11/09(今天);至今共发布 15 个版本,其中过去 12 个月发布了 15 个;首次发布于 2026/01/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。