semgrep-rule-variant-creator
它能做什么
这个工具可以帮你把代码安全规则(即 Semgrep 规则)改编到不同的编程语言上。如果你已经有一条适用于某种语言的规则,它可以帮你为其他语言生成对应的版本。
适用场景
- ✓将已有的安全规则改编到新的语言上时。
- ✓在项目中为多种语言创建同一种安全检查的不同版本时。
- ✓把代码的安全覆盖范围扩展到之前没有涉及的语言时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/semgrep-rule-variant-creator/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“把“sql-injection”规则改编到 Go 和 Java 上。”
每周 5 个新技能,1 分钟读完。
工作原理
工具会先分析原规则在新语言中是否合理,然后生成代码示例用于测试规则,最后输出新规则及其测试。每条新规则都会单独测试,确保其正确运行。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Semgrep Rule Variant Creator
Port existing Semgrep rules to new target languages with proper applicability analysis and test-driven validation.
When to Use
Ideal scenarios:
- Porting an existing Semgrep rule to one or more target languages
- Creating language-specific variants of a universal vulnerability pattern
- Expanding rule coverage across a polyglot codebase
- Translating rules between languages with equivalent constructs
When NOT to Use
Do NOT use this skill for:
- Creating a new Semgrep rule from scratch (use
semgrep-rule-creatorinstead) - Running existing rules against code
- Languages where the vulnerability pattern fundamentally doesn't apply
- Minor syntax variations within the same language
Input Specification
This skill requires:
- Existing Semgrep rule - YAML file path or YAML rule content
- Target languages - One or more languages to port to (e.g., "Golang and Java")
Output Specification
For each applicable target language, produces:
<original-rule-id>-<language>/
├── <original-rule-id>-<language>.yaml # Ported Semgrep rule
└── <original-rule-id>-<language>.<ext> # Test file with annotations
Example output for porting sql-injection to Go and Java:
sql-injection-golang/
├── sql-injection-golang.yaml
└── sql-injection-golang.go
sql-injection-java/
├── sql-injection-java.yaml
└── sql-injection-java.java
Rationalizations to Reject
When porting Semgrep rules, reject these common shortcuts:
| Rationalization | Why It Fails | Correct Approach |
|---|---|---|
| "Pattern structure is identical" | Different ASTs across languages | Always dump AST for target language |
| "Same vulnerability, same detection" | Data flow differs between languages | Analyze target language idioms |
| "Rule doesn't need tests since original worked" | Language edge cases differ | Write NEW test cases for target |
| "Skip applicability - it obviously applies" | Some patterns are language-specific | Complete applicability analysis first |
| "I'll create all variants then test" | Errors compound, hard to debug | Complete full cycle per language |
| "Library equivalent is close enough" | Surface similarity hides differences | Verify API semantics match |
| "Just translate the syntax 1:1" | Languages have different idioms | Research target language patterns |
Strictness Level
This workflow is strict - do not skip steps:
- Applicability analysis is mandatory: Don't assume patterns translate
- Each language is independent: Complete full cycle before moving to next
- Test-first for each variant: Never write a rule without test cases
- 100% test pass required: "Most tests pass" is not acceptable
Overview
This skill guides the creation of language-specific variants of existing Semgrep rules. Each target language goes through an independent 4-phase cycle:
FOR EACH target language:
Phase 1: Applicability Analysis → Verdict
Phase 2: Test Creation (Test-First)
Phase 3: Rule Creation
Phase 4: Validation
(Complete full cycle before moving to next language)
Foundational Knowledge
The semgrep-rule-creator skill is the authoritative reference for Semgrep rule creation fundamentals. While this skill focuses on porting existing rules to new languages, the core principles of writing quality rules remain the same.
Consult semgrep-rule-creator for guidance on:
- When to use taint mode vs pattern matching - Choosing the right approach for the vulnerability type
- Test-first methodology - Why tests come before rules and how to write effective test cases
- Anti-patterns to avoid - Common mistakes like overly broad or overly specific patterns
- Iterating until tests pass - The validation loop and debugging techniques
- Rule optimization - Removing redundant patterns after tests pass
When porting a rule, you're applying these same principles in a new language context. If uncertain about rule structure or approach, refer to semgrep-rule-creator first.
Four-Phase Workflow
Phase 1: Applicability Analysis
Before porting, determine if the pattern applies to the target language.
Analysis criteria:
- Does the vulnerability class exist in the target language?
- Does an equivalent construct exist (function, pattern, library)?
- Are the semantics similar enough for meaningful detection?
Verdict options:
APPLICABLE→ Proceed with variant creation
…
常见问题
什么是“Semgrep 规则”?
它们就像一份份“配方”,教程序去查找特定的代码模式,通常用于发现安全问题或缺陷。
为什么不能直接把规则复制到另一种语言上?
每种语言都有自己的特点和写法。一条在某种语言中运行完美的规则,在另一种语言中可能无法工作,或者会误判,即使两种语言看起来很相似。
使用这个工具需要会编程吗?
你不需要是经验丰富的程序员。工具会自动完成改编过程,但了解原规则的基本作用,有助于你选择合适的目标语言。
详情
作者的原始描述
Creates language variants of existing Semgrep rules. Use when porting a Semgrep rule to specified target languages. Takes an existing rule and target languages as input, produces independent rule+test directories for each language.
热度
- GitHub 星标
- 48k
- 排名
- #5714
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。