security

A set of coding rules for protecting applications, including checks on user input, login security, database queries, and browser output. The examples and instructions are written in Chinese and use tools such as Zod, JWT, bcrypt, and argon2.

In plain words
What is it for?
Guiding secure input validation, authentication, password hashing, multi-factor authentication, rate limiting, database access, and protection against cross-site scripting.
Why use it?
It gives developers concrete rules for avoiding common security defects such as injection attacks, unsafe output, weak password storage, and excessive login attempts.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/bestcarly/opc-coding-guide/security
Clone the repo
git clone --depth 1 https://github.com/bestcarly/opc-coding-guide
Per session 1,355 This file is loaded in full into every session.
When invoked 1,355 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.01355 $0.01355
Opus 5 $0.00678 $0.00678
Sonnet 5 $0.00271 $0.00271
Haiku 4.5 $0.00136 $0.00136

Measured yesterday against content hash bf87188f05cf, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

security scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/cursor-rules/security.mdc · 186 lines

How it starts

The opening of the file, as written. The whole thing — 186 lines — stays where its author put it; the contents beside it link to each section on GitHub.

安全规则(2026 年版)

补充人:墨铃 (Mori)
补充日期:2026-02-28
参考章节:第八章 8.2 节、第十一章 11.5 节


输入验证

  • 所有用户输入必须验证,不信任任何外部数据
  • 使用 Zod 或 Joi 进行 schema 验证
  • 防止 SQL 注入:使用参数化查询 / ORM
  • 防止 XSS:转义输出,使用 Content Security Policy
  • 防止命令注入:避免 shell 命令拼接,使用安全 API
// ✅ 正确:使用 Zod 验证
import { z } from "zod";

const UserInputSchema = z.object({
  email: z.string().email(),
  password: z.string().min(12).max(128),
  name: z.string().min(1).max(100).regex(/^[\p{L}\s'-]+$/u),
});

// ❌ 错误:直接使用未验证输入
const user = await db.query(`SELECT * FROM users WHERE id = ${req.params.id}`);

认证授权

  • 使用 JWT 认证,Access Token 过期时间:15 分钟
  • Refresh Token 过期时间:7 天,存储在 HttpOnly Cookie
  • 密码用 bcrypt 或 argon2 加密(bcrypt salt rounds ≥ 12)
  • 敏感操作需要二次验证(MFA / TOTP)
  • 登录限流:5 次失败后锁定 15 分钟
// ✅ 正确:密码哈希 + 登录限流
import bcrypt from "bcrypt";
import { RateLimiter } from "limiter";

const limiter = new RateLimiter({ tokensPerInterval: 5, interval: "minute" });

async function login(email: string, password: string, ip: string) {
  if (!(await limiter.removeTokens(1))) {
    throw new Error("登录尝试过多,请 15 分钟后再试");
  }
  const user = await User.findByEmail(email);
  if (!user || !(await bcrypt.compare(password, user.passwordHash))) {
    throw new Error("邮箱或密码错误");
  }
  return generateTokens(user);
}

数据安全

  • 敏感数据加密存储(AES-256-GCM)
  • 日志中不记录敏感信息(密码、token、个人身份信息)
  • API 响应不泄露内部结构(错误堆栈、SQL、路径)
// ✅ 正确:敏感信息脱敏
const sanitizeForLog = (obj: Record<string, unknown>) => {
  const sensitive = ["password", "token", "apiKey", "ssn", "creditCard"];
  return Object.fromEntries(
    Object.entries(obj).map(([k, v]) => [
      k,
      sensitive.includes(k) ? "[REDACTED]" : v,
    ])
  );
};

logger.info("User login", sanitizeForLog({ email, password, ip }));
// 输出: User login { email: "[email protected]", password: "[REDACTED]", ip: "..." }

安全扫描(2026 新增)

  • 每次提交前运行 AI 安全扫描(Claude Code Security)
  • Critical 问题必须修复后才能合并
  • 扫描记录写入 security-audit.md
  • 定期重新扫描历史代码(每月一次)
# 安全扫描命令
claude-code security scan ./src --severity critical,high

# 输出到审计文件
claude-code security scan ./src --report markdown >> security-audit.md

Read the full file on GitHub · 186 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 186 lines · 1,355 tokens per session scan A bf87188f05cf

Subscribe to this mod's changes

security is a cursor rule published in the GitHub repository bestcarly/opc-coding-guide (7 stars, last pushed 5mo ago), licensed MIT. It adds 1,355 tokens to every session, about $0.0068 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.