security-patterns by yonatangross/orchestkit
npx skills add https://github.com/yonatangross/orchestkit --skill security-patterns包含钩子
此技能使用 Claude 钩子,可自动响应事件执行代码。安装前请仔细审查。
用于构建加固应用程序的全面安全模式。每个类别在 rules/ 目录下都有按需加载的独立规则文件。
| 类别 | 规则数量 | 影响级别 | 使用场景 |
|---|---|---|---|
| 身份验证 | 3 | 关键 | JWT 令牌、OAuth 2.1/PKCE、RBAC/权限 |
| 纵深防御 | 2 | 关键 | 多层安全、零信任架构 |
| 输入验证 | 3 | 高 | 模式验证 (Zod/Pydantic)、输出编码、文件上传 |
| OWASP 十大风险 | 2 | 关键 | 注入防护、修复身份验证漏洞 |
| LLM 安全 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 3 |
| 高 |
| 提示注入防御、输出护栏、内容过滤 |
| PII 脱敏 | 2 | 高 | 使用 Presidio、Langfuse、LLM Guard 进行 PII 检测/编辑 |
| 扫描 | 3 | 高 | 依赖项审计、SAST (Semgrep/Bandit)、密钥检测 |
| 高级护栏 | 2 | 关键 | NeMo/Guardrails AI 验证器、红队测试、OWASP LLM |
总计:8 个类别共 20 条规则
# Argon2id 密码哈希
from argon2 import PasswordHasher
ph = PasswordHasher()
password_hash = ph.hash(password)
ph.verify(password_hash, password)
# JWT 访问令牌 (15分钟有效期)
import jwt
from datetime import datetime, timedelta, timezone
payload = {
'sub': user_id, 'type': 'access',
'exp': datetime.now(timezone.utc) + timedelta(minutes=15),
}
token = jwt.encode(payload, SECRET_KEY, algorithm='HS256')
// Zod v4 模式验证
import { z } from 'zod';
const UserSchema = z.object({
email: z.string().email(),
name: z.string().min(2).max(100),
role: z.enum(['user', 'admin']).default('user'),
});
const result = UserSchema.safeParse(req.body);
# 使用 Langfuse 进行 PII 脱敏
import re
from langfuse import Langfuse
def mask_pii(data, **kwargs):
if isinstance(data, str):
data = re.sub(r'\b[\w.-]+@[\w.-]+\.\w+\b', '[REDACTED_EMAIL]', data)
data = re.sub(r'\b\d{3}-\d{2}-\d{4}\b', '[REDACTED_SSN]', data)
return data
langfuse = Langfuse(mask=mask_pii)
使用 OAuth 2.1、Passkeys/WebAuthn、JWT 令牌和基于角色的访问控制实现安全身份验证。
| 规则 | 描述 |
|---|---|
auth-jwt.md | JWT 创建、验证、过期、刷新令牌轮换 |
auth-oauth.md | 使用 PKCE、DPoP、Passkeys/WebAuthn 的 OAuth 2.1 |
auth-rbac.md | 基于角色的访问控制、权限装饰器、MFA |
关键决策: Argon2id > bcrypt | 访问令牌 15 分钟 | 必需 PKCE | Passkeys > TOTP > SMS
多层安全架构,无单点故障。
| 规则 | 描述 |
|---|---|
defense-layers.md | 8 层安全架构 (边缘到可观测性) |
defense-zero-trust.md | 不可变请求上下文、租户隔离、审计日志 |
关键决策: 不可变数据类上下文 | 查询级租户过滤 | LLM 提示中不使用 ID
使用 Zod v4 和 Pydantic 验证和清理所有不受信任的输入。
| 规则 | 描述 |
|---|---|
validation-input.md | 使用 Zod v4 和 Pydantic 进行模式验证、类型强制转换 |
validation-output.md | HTML 清理、输出编码、XSS 防护 |
validation-schemas.md | 判别联合类型、文件上传验证、URL 白名单 |
关键决策: 白名单优于黑名单 | 始终在服务端验证 | 验证魔数而非扩展名
针对最关键的 Web 应用程序安全风险提供防护。
| 规则 | 描述 |
|---|---|
owasp-injection.md | SQL/命令注入、参数化查询、SSRF 防护 |
owasp-broken-auth.md | JWT 算法混淆、CSRF 防护、时序攻击 |
关键决策: 仅使用参数化查询 | 硬编码 JWT 算法 | SameSite=Strict cookies
用于 LLM 集成的安全模式,包括上下文分离和输出验证。
| 规则 | 描述 |
|---|---|
llm-prompt-injection.md | 上下文分离、提示审计、禁止模式 |
llm-guardrails.md | 输出验证管道:模式、溯源、安全性、大小 |
llm-content-filtering.md | LLM 前过滤、LLM 后归因、三阶段模式 |
关键决策: ID 围绕 LLM 流动,绝不通过 LLM | 归因是确定性的 | 审计每个提示
敏感 ID 和数据围绕 LLM 流动,绝不通过 LLM。LLM 仅看到内容 —— 在之后确定性地映射回实体。
# 正确:ID 绕过 LLM
context = {"user_id": user_id, "tenant_id": tenant_id} # 保存在服务端
llm_input = f"Summarize this document:\n{doc_text}" # 提示中无 ID
llm_output = call_llm(llm_input)
result = {"summary": llm_output, **context} # 之后重新附加 ID
每个 LLM 响应在到达用户之前必须通过 4 阶段护栏管道:
def validate_llm_output(raw_output: str, schema, sources: list[str]) -> str:
# 1. 模式 — 是否符合预期结构?
parsed = schema.parse(raw_output)
# 2. 溯源 — 声明是否有源文档支持?
assert_grounded(parsed, sources)
# 3. 安全性 — 毒性、PII 泄露、提示泄露
assert_safe(parsed, max_toxicity=0.5)
# 4. 大小 — 防止令牌炸弹响应
assert len(parsed.text) < MAX_OUTPUT_CHARS
return parsed.text
用于 LLM 可观测性管道和日志记录的 PII 检测与脱敏。
| 规则 | 描述 |
|---|---|
pii-detection.md | Microsoft Presidio、正则表达式模式、LLM Guard Anonymize |
pii-redaction.md | Langfuse 掩码回调、structlog/loguru 处理器、Vault 去匿名化 |
关键决策: 企业级使用 Presidio | 替换为类型令牌 | 在初始化时使用掩码回调
针对依赖项、代码和密钥的自动化安全扫描。
| 规则 | 描述 |
|---|---|
scanning-dependency.md | npm audit、pip-audit、Trivy 容器扫描、CI 门控 |
scanning-sast.md | Semgrep 和 Bandit 静态分析、自定义规则、预提交钩子 |
scanning-secrets.md | Gitleaks、TruffleHog、带基线管理的 detect-secrets |
关键决策: 使用预提交钩子实现左移 | 阻止关键/高风险 | Gitleaks + detect-secrets 基线
使用 NeMo Guardrails、Guardrails AI 验证器和 DeepTeam 红队测试实现生产级 LLM 安全。
| 规则 | 描述 |
|---|---|
guardrails-nemo.md | NeMo Guardrails、Colang 2.0 流程、Guardrails AI 验证器、分层验证 |
guardrails-llm-validation.md | DeepTeam 红队测试 (40+ 漏洞)、OWASP LLM Top 10 合规性 |
关键决策: 流程用 NeMo,验证器用 Guardrails AI | 毒性阈值 0.5 | 发布前红队测试 + 季度测试
插件设置遵循 3 层优先级:
| 层级 | 来源 | 可覆盖? |
|---|---|---|
1. 托管 (插件 settings.json) | 插件作者提供的默认值 | 是,用户可覆盖 |
2. 项目 (.claude/settings.json) | 仓库配置 | 是,用户可覆盖 |
3. 用户 (~/.claude/settings.json) | 个人偏好 | 最终决定权 |
OrchestKit 提供的安全钩子是托管默认值 —— 用户可以禁用它们但会收到警告。企业管理员可以通过托管配置文件锁定设置。
# 身份验证
user.password = request.form['password'] # 明文密码存储
response_type=token # 隐式 OAuth 授权 (已弃用)
return "Email not found" # 信息泄露
# 输入验证
"SELECT * FROM users WHERE name = '" + name + "'" # SQL 注入
if (file.type === 'image/png') {...} # 信任 Content-Type 头部
# LLM 安全
prompt = f"Analyze for user {user_id}" # 提示中包含 ID
artifact.user_id = llm_output["user_id"] # 信任 LLM 生成的 ID
# PII
logger.info(f"User email: {user.email}") # 日志中包含原始 PII
langfuse.trace(input=raw_prompt) # 未脱敏的可观测性数据
使用 Read("${CLAUDE_SKILL_DIR}/references/<file>") 按需加载:
| 文件 | 内容 |
|---|---|
oauth-2.1-passkeys.md | OAuth 2.1、PKCE、DPoP、Passkeys/WebAuthn |
request-context-pattern.md | 用于身份流转的不可变请求上下文 |
tenant-isolation.md | 租户作用域的仓库、向量/全文搜索 |
audit-logging.md | 已清理的结构化日志记录、合规性 |
zod-v4-api.md | Zod v4 类型、强制转换、转换、精炼 |
vulnerability-demos.md | OWASP 漏洞代码与安全代码示例 |
context-separation.md | LLM 上下文分离架构 |
output-guardrails.md | 输出验证管道实现 |
pre-llm-filtering.md | 租户作用域的检索、内容提取 |
post-llm-attribution.md | 确定性归因模式 |
prompt-audit.md | 提示审计模式、安全提示构建器 |
presidio-integration.md | Microsoft Presidio 设置、自定义识别器 |
langfuse-mask-callback.md | Langfuse SDK 掩码实现 |
llm-guard-sanitization.md | 使用 Vault 的 LLM Guard Anonymize/Deanonymize |
logging-redaction.md | structlog/loguru 预日志记录脱敏 |
api-design-framework - API 安全模式ork:rag-retrieval - 需要租户作用域检索的 RAG 管道模式llm-evaluation - 输出质量评估,包括幻觉检测关键词: password, hashing, JWT, token, OAuth, PKCE, passkey, WebAuthn, RBAC, session 解决的问题:
关键词: defense in depth, security layers, multi-layer, request context, tenant isolation 解决的问题:
关键词: schema, validate, Zod, Pydantic, sanitize, HTML, XSS, file upload 解决的问题:
关键词: OWASP, sql injection, broken access control, CSRF, XSS, SSRF 解决的问题:
关键词: prompt injection, context separation, guardrails, hallucination, LLM output 解决的问题:
关键词: PII, masking, Presidio, Langfuse, redact, GDPR, privacy 解决的问题:
每周安装次数
123
仓库
GitHub 星标数
132
首次出现
2026年2月14日
安全审计
安装于
opencode118
gemini-cli112
codex111
cursor110
github-copilot109
kimi-cli101
Contains Hooks
This skill uses Claude hooks which can execute code automatically in response to events. Review carefully before installing.
Comprehensive security patterns for building hardened applications. Each category has individual rule files in rules/ loaded on-demand.
| Category | Rules | Impact | When to Use |
|---|---|---|---|
| Authentication | 3 | CRITICAL | JWT tokens, OAuth 2.1/PKCE, RBAC/permissions |
| Defense-in-Depth | 2 | CRITICAL | Multi-layer security, zero-trust architecture |
| Input Validation | 3 | HIGH | Schema validation (Zod/Pydantic), output encoding, file uploads |
| OWASP Top 10 | 2 | CRITICAL | Injection prevention, broken authentication fixes |
| LLM Safety | 3 | HIGH | Prompt injection defense, output guardrails, content filtering |
| PII Masking | 2 | HIGH | PII detection/redaction with Presidio, Langfuse, LLM Guard |
| Scanning | 3 | HIGH | Dependency audit, SAST (Semgrep/Bandit), secret detection |
| Advanced Guardrails | 2 | CRITICAL | NeMo/Guardrails AI validators, red-teaming, OWASP LLM |
Total: 20 rules across 8 categories
# Argon2id password hashing
from argon2 import PasswordHasher
ph = PasswordHasher()
password_hash = ph.hash(password)
ph.verify(password_hash, password)
# JWT access token (15-min expiry)
import jwt
from datetime import datetime, timedelta, timezone
payload = {
'sub': user_id, 'type': 'access',
'exp': datetime.now(timezone.utc) + timedelta(minutes=15),
}
token = jwt.encode(payload, SECRET_KEY, algorithm='HS256')
// Zod v4 schema validation
import { z } from 'zod';
const UserSchema = z.object({
email: z.string().email(),
name: z.string().min(2).max(100),
role: z.enum(['user', 'admin']).default('user'),
});
const result = UserSchema.safeParse(req.body);
# PII masking with Langfuse
import re
from langfuse import Langfuse
def mask_pii(data, **kwargs):
if isinstance(data, str):
data = re.sub(r'\b[\w.-]+@[\w.-]+\.\w+\b', '[REDACTED_EMAIL]', data)
data = re.sub(r'\b\d{3}-\d{2}-\d{4}\b', '[REDACTED_SSN]', data)
return data
langfuse = Langfuse(mask=mask_pii)
Secure authentication with OAuth 2.1, Passkeys/WebAuthn, JWT tokens, and role-based access control.
| Rule | Description |
|---|---|
auth-jwt.md | JWT creation, verification, expiry, refresh token rotation |
auth-oauth.md | OAuth 2.1 with PKCE, DPoP, Passkeys/WebAuthn |
auth-rbac.md | Role-based access control, permission decorators, MFA |
Key Decisions: Argon2id > bcrypt | Access tokens 15 min | PKCE required | Passkeys > TOTP > SMS
Multi-layer security architecture with no single point of failure.
| Rule | Description |
|---|---|
defense-layers.md | 8-layer security architecture (edge to observability) |
defense-zero-trust.md | Immutable request context, tenant isolation, audit logging |
Key Decisions: Immutable dataclass context | Query-level tenant filtering | No IDs in LLM prompts
Validate and sanitize all untrusted input using Zod v4 and Pydantic.
| Rule | Description |
|---|---|
validation-input.md | Schema validation with Zod v4 and Pydantic, type coercion |
validation-output.md | HTML sanitization, output encoding, XSS prevention |
validation-schemas.md | Discriminated unions, file upload validation, URL allowlists |
Key Decisions: Allowlist over blocklist | Server-side always | Validate magic bytes not extensions
Protection against the most critical web application security risks.
| Rule | Description |
|---|---|
owasp-injection.md | SQL/command injection, parameterized queries, SSRF prevention |
owasp-broken-auth.md | JWT algorithm confusion, CSRF protection, timing attacks |
Key Decisions: Parameterized queries only | Hardcode JWT algorithm | SameSite=Strict cookies
Security patterns for LLM integrations including context separation and output validation.
| Rule | Description |
|---|---|
llm-prompt-injection.md | Context separation, prompt auditing, forbidden patterns |
llm-guardrails.md | Output validation pipeline: schema, grounding, safety, size |
llm-content-filtering.md | Pre-LLM filtering, post-LLM attribution, three-phase pattern |
Key Decisions: IDs flow around LLM, never through | Attribution is deterministic | Audit every prompt
Sensitive IDs and data flow AROUND the LLM, never through it. The LLM sees only content — mapping back to entities happens deterministically after.
# CORRECT: IDs bypass the LLM
context = {"user_id": user_id, "tenant_id": tenant_id} # kept server-side
llm_input = f"Summarize this document:\n{doc_text}" # no IDs in prompt
llm_output = call_llm(llm_input)
result = {"summary": llm_output, **context} # IDs reattached after
Every LLM response MUST pass a 4-stage guardrail pipeline before reaching the user:
def validate_llm_output(raw_output: str, schema, sources: list[str]) -> str:
# 1. Schema — does it match expected structure?
parsed = schema.parse(raw_output)
# 2. Grounding — are claims supported by source documents?
assert_grounded(parsed, sources)
# 3. Safety — toxicity, PII leakage, prompt leakage
assert_safe(parsed, max_toxicity=0.5)
# 4. Size — prevent token-bomb responses
assert len(parsed.text) < MAX_OUTPUT_CHARS
return parsed.text
PII detection and masking for LLM observability pipelines and logging.
| Rule | Description |
|---|---|
pii-detection.md | Microsoft Presidio, regex patterns, LLM Guard Anonymize |
pii-redaction.md | Langfuse mask callback, structlog/loguru processors, Vault deanonymization |
Key Decisions: Presidio for enterprise | Replace with type tokens | Use mask callback at init
Automated security scanning for dependencies, code, and secrets.
| Rule | Description |
|---|---|
scanning-dependency.md | npm audit, pip-audit, Trivy container scanning, CI gating |
scanning-sast.md | Semgrep and Bandit static analysis, custom rules, pre-commit |
scanning-secrets.md | Gitleaks, TruffleHog, detect-secrets with baseline management |
Key Decisions: Pre-commit hooks for shift-left | Block on critical/high | Gitleaks + detect-secrets baseline
Production LLM safety with NeMo Guardrails, Guardrails AI validators, and DeepTeam red-teaming.
| Rule | Description |
|---|---|
guardrails-nemo.md | NeMo Guardrails, Colang 2.0 flows, Guardrails AI validators, layered validation |
guardrails-llm-validation.md | DeepTeam red-teaming (40+ vulnerabilities), OWASP LLM Top 10 compliance |
Key Decisions: NeMo for flows, Guardrails AI for validators | Toxicity 0.5 threshold | Red-team pre-release + quarterly
Plugin settings follow a 3-tier precedence:
| Tier | Source | Overridable? |
|---|---|---|
1. Managed (plugin settings.json) | Plugin author ships defaults | Yes, by user |
2. Project (.claude/settings.json) | Repository config | Yes, by user |
3. User (~/.claude/settings.json) | Personal preferences | Final authority |
Security hooks shipped by OrchestKit are managed defaults — users can disable them but are warned. Enterprise admins can lock settings via managed profiles.
# Authentication
user.password = request.form['password'] # Plaintext password storage
response_type=token # Implicit OAuth grant (deprecated)
return "Email not found" # Information disclosure
# Input Validation
"SELECT * FROM users WHERE name = '" + name + "'" # SQL injection
if (file.type === 'image/png') {...} # Trusting Content-Type header
# LLM Safety
prompt = f"Analyze for user {user_id}" # ID in prompt
artifact.user_id = llm_output["user_id"] # Trusting LLM-generated IDs
# PII
logger.info(f"User email: {user.email}") # Raw PII in logs
langfuse.trace(input=raw_prompt) # Unmasked observability data
Load on demand with Read("${CLAUDE_SKILL_DIR}/references/<file>"):
| File | Content |
|---|---|
oauth-2.1-passkeys.md | OAuth 2.1, PKCE, DPoP, Passkeys/WebAuthn |
request-context-pattern.md | Immutable request context for identity flow |
tenant-isolation.md | Tenant-scoped repository, vector/full-text search |
audit-logging.md | Sanitized structured logging, compliance |
zod-v4-api.md | Zod v4 types, coercion, transforms, refinements |
vulnerability-demos.md |
api-design-framework - API security patternsork:rag-retrieval - RAG pipeline patterns requiring tenant-scoped retrievalllm-evaluation - Output quality assessment including hallucination detectionKeywords: password, hashing, JWT, token, OAuth, PKCE, passkey, WebAuthn, RBAC, session Solves:
Keywords: defense in depth, security layers, multi-layer, request context, tenant isolation Solves:
Keywords: schema, validate, Zod, Pydantic, sanitize, HTML, XSS, file upload Solves:
Keywords: OWASP, sql injection, broken access control, CSRF, XSS, SSRF Solves:
Keywords: prompt injection, context separation, guardrails, hallucination, LLM output Solves:
Keywords: PII, masking, Presidio, Langfuse, redact, GDPR, privacy Solves:
Weekly Installs
123
Repository
GitHub Stars
132
First Seen
Feb 14, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode118
gemini-cli112
codex111
cursor110
github-copilot109
kimi-cli101
Azure RBAC 权限管理工具:查找最小角色、创建自定义角色与自动化分配
135,700 周安装
PPTX文档自动化技能:使用Python和Node.js编程创建编辑PowerPoint演示文稿
81 周安装
project-discover:AI辅助项目逆向工程与知识沉淀工具,一键建立项目SSOT
81 周安装
Angular 17+ 现代开发规范:独立组件、Signal 状态管理与原生控制流最佳实践
81 周安装
Tailwind CSS 官方插件详解:排版与表单样式优化,提升前端开发效率
81 周安装
机器学习模型训练指南:从数据准备到模型评估的完整流程与最佳实践
81 周安装
WebSocket实时通信系统实现 - Socket.IO服务器与客户端完整代码示例
81 周安装
| OWASP vulnerable vs secure code examples |
context-separation.md | LLM context separation architecture |
output-guardrails.md | Output validation pipeline implementation |
pre-llm-filtering.md | Tenant-scoped retrieval, content extraction |
post-llm-attribution.md | Deterministic attribution pattern |
prompt-audit.md | Prompt audit patterns, safe prompt builder |
presidio-integration.md | Microsoft Presidio setup, custom recognizers |
langfuse-mask-callback.md | Langfuse SDK mask implementation |
llm-guard-sanitization.md | LLM Guard Anonymize/Deanonymize with Vault |
logging-redaction.md | structlog/loguru pre-logging redaction |