security

A baseline of security practices for applications, covering threat modeling, input checks, login and permissions, tokens, encryption, injection risks, and browser or network attacks.

In plain words
What is it for?
Use it when reviewing APIs, file uploads, JSON or XML handling, database queries, sessions, secrets, logs, and access controls. It also covers protections against CSRF, XSS, SSRF, and denial-of-service attacks.
Why use it?
It helps identify ways an application could be attacked and provides rules for reducing risks such as stolen credentials, unsafe input, data exposure, and unauthorized access.

Cursor rule for Cursor

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/mywand/cusrsor-do-it/security
Clone the repo
git clone --depth 1 https://github.com/mywand/cusrsor-do-it

Made for: Cursor.

Per session 2,091 This file is loaded in full into every session.
When invoked 2,091 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.02091 $0.02091
Opus 5 $0.01045 $0.01045
Sonnet 5 $0.00418 $0.00418
Haiku 4.5 $0.00209 $0.00209

Measured 2d ago against content hash bc89c5b3c133, 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 2d ago.

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.

.cursor/rules/tools/security.mdc · 140 lines

How it starts

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

最近更新: 2025-09-18

Security Baseline & Practices

1. Threat Modeling (威胁建模)

  • 识别资产:用户数据 / 密钥 / 交易记录 / 配置。
  • 识别攻击面:API 入口 / 消息队列 / 管理端 / 文件上传 / 定时任务。
  • STRIDE(可选):Spoofing / Tampering / Repudiation / Information Disclosure / DoS / Elevation of Privilege。
  • 输出:高风险场景 -> 缓解措施 -> 剩余风险。

2. 输入验证 & 数据清理

类型 策略
字符串 长度限制 / 白名单字符 / 去除控制字符
数字 范围校验 / 类型严格解析
枚举 固定值集合校验
文件 扩展名 + MIME 双重校验;限制大小;随机化文件名
JSON/XML Schema 校验;禁用外部实体 (XXE)

3. 鉴权与认证

  • 认证:JWT / OAuth2 / Session;访问令牌有效期 + 刷新机制。
  • 鉴权:RBAC(角色) + ABAC(属性) -> 关键资源显式权限检查。
  • 最小权限原则:服务账号、数据库账号权限最小化。
  • 禁止硬编码凭证;统一 Secret 管理(Vault / KMS / 环境变量)。

4. 会话与令牌

  • JWT:签名算法 HS256/RS256;声明最小化,不放敏感;设置过期 exp
  • 防重放:nonce 或一次性 token;关键变更加二次校验。
  • 退出/吊销:刷新令牌黑名单或版本号策略。

5. 加密与敏感数据

场景 建议
传输 HTTPS(TLS1.2+) 强制;HSTS;禁用弱套件
存储 敏感字段加密(AES-256-GCM)或哈希(bcrypt/argon2)
密钥管理 不写入代码库;周期轮换;访问审计
日志 掩码显示(只保留 3~4 位脱敏)

6. 防注入与序列化风险

  • 参数化查询(PreparedStatement / 参数绑定)。
  • 禁用拼接 SQL / Shell / LDAP / NoSQL 动态语句。
  • JSON 反序列化:限制类型 / 使用白名单;禁用未知多态。
  • XML:禁用外部实体 DOCTYPE

7. CSRF / XSS / SSRF

风险 缓解
CSRF SameSite=Lax/Strict Cookie;CSRF Token;幂等设计
XSS 输出编码;输入清理;内容安全策略(CSP)
SSRF 目标地址白名单;禁止访问 127.* / 内网段
点击劫持 X-Frame-Options / CSP frame-ancestors

8. 上传与文件处理

  • 隔离存储(非应用执行目录)。
  • 病毒扫描(可异步)。
  • EXIF / 隐藏数据清理(图片)。
  • 强制 Content-Type 与扩展名匹配。

9. 访问控制与多租户

  • 租户隔离:数据过滤(tenantId)防止越权。
  • 管理操作与用户操作日志分离审计。
  • 横向权限:资源所有者校验;纵向权限:角色/策略判断。

10. 安全日志与审计

  • 记录:登录 / 登出 / 权限变更 / 敏感资源访问 / 配置调整。
  • 不记录:密码、密钥、完整 Token、个人敏感内容。
  • 提供 traceId + actorId + action + resource + result + ip。

11. 依赖与供应链安全

  • 组件升级前扫描(OWASP Dependency Check / Snyk)。
  • 锁定版本;避免引用不明镜像/仓库。
  • CI 加入许可证合规检查(GPL、AGPL 评估)。

12. Rate Limit / Abuse 防护

  • 策略:IP + 用户 + Token 维度限流。
  • 黑名单/灰度:异常高频行为加入观察列表。
  • 指标:限流命中率 / 拒绝数 / 延迟分布。

13. 可用性与 DoS 防护

  • 读写隔离 + 缓存保护后端。
  • 分页/流式接口限制最大条数。
  • 复杂计算/导出作业:异步 + 队列 + 进度查询。

14. Secret Rotation & Key Lifecycle

  • 记录:创建时间 / 上次轮换 / 使用范围。
  • 自动轮换策略(每 90 天或高风险后)。
  • 吊销:发现泄漏 -> 即刻标记失效 + 强制刷新下游。

Read the full file on GitHub · 140 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. 2d ago First seen · 140 lines · 2,091 tokens per session scan A bc89c5b3c133

Subscribe to this mod's changes

security is a cursor rule published in the GitHub repository mywand/cusrsor-do-it (2 stars, last pushed 7mo ago), licensed Apache-2.0. It adds 2,091 tokens to every session, about $0.0105 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.