Skillpedia
برمجة عامة48k · #5713

semgrep-rule-creator

ما الذي تفعله

تساعدك هذه المهارة على إنشاء قواعد مخصصة لـ Semgrep، وهو برنامج يفحص كودك بحثًا عن ثغرات الأمان أو أنماط البرمجة. وتضمن أن تكون قواعدك مختبرة جيدًا وتعمل بشكل صحيح.

متى تستخدمها

  • ✓عندما تحتاج إلى إيجاد نوع محدد من مشكلات الأمان في كودك.
  • ✓عندما تريد إنشاء قواعد تضمن أن كودك يتبع نمطًا معينًا.
  • ✓عندما تريد التحقق مما إذا كانت البيانات الخارجية، مثل بيانات المستخدم، قد تسبب مشكلات أمنية في الأجزاء الحساسة من الكود.

رابط المهارة

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/semgrep-rule-creator/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/semgrep-rule-creator/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“أنشئ قاعدة Semgrep لإيجاد الأماكن التي يُستخدم فيها `eval()` مع مدخلات المستخدم في Python.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

تصف المشكلة والحالات التي يجب أن تُكتشف أو لا تُكتشف. تساعد المهارة على كتابة الاختبارات أولًا، ثم القاعدة، مع التأكد من أنها تعمل في جميع الحالات المختبرة.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

Semgrep Rule Creator

Create production-quality Semgrep rules with proper testing and validation.

When to Use

Ideal scenarios:

  • Writing Semgrep rules for specific bug patterns
  • Writing rules to detect security vulnerabilities in your codebase
  • Writing taint mode rules for data flow vulnerabilities
  • Writing rules to enforce coding standards

When NOT to Use

Do NOT use this skill for:

  • Running existing Semgrep rulesets
  • General static analysis without custom rules (use static-analysis skill)

Rationalizations to Reject

When writing Semgrep rules, reject these common shortcuts:

  • "The pattern looks complete" → Still run semgrep --test --config <rule-id>.yaml <rule-id>.<ext> to verify. Untested rules have hidden false positives/negatives.
  • "It matches the vulnerable case" → Matching vulnerabilities is half the job. Verify safe cases don't match (false positives break trust).
  • "Taint mode is overkill for this" → If data flows from user input to a dangerous sink, taint mode gives better precision than pattern matching.
  • "One test is enough" → Include edge cases: different coding styles, sanitized inputs, safe alternatives, and boundary conditions.
  • "I'll optimize the patterns first" → Write correct patterns first, optimize after all tests pass. Premature optimization causes regressions.
  • "The AST dump is too complex" → The AST reveals exactly how Semgrep sees code. Skipping it leads to patterns that miss syntactic variations.

Anti-Patterns

Too broad - matches everything, useless for detection:

# BAD: Matches any function call
pattern: $FUNC(...)

# GOOD: Specific dangerous function
pattern: eval(...) # security-allowlist: Semgrep sink pattern

Missing safe cases in tests - leads to undetected false positives:

# BAD: Only tests vulnerable case
# ruleid: my-rule
dangerous(user_input)

# GOOD: Include safe cases to verify no false positives
# ruleid: my-rule
dangerous(user_input)

# ok: my-rule
dangerous(sanitize(user_input))

# ok: my-rule
dangerous("hardcoded_safe_value")

Overly specific patterns - misses variations:

# BAD: Only matches exact format
pattern: os.system("rm " + $VAR)

# GOOD: Matches all os.system calls with taint tracking
mode: taint
pattern-sinks:
  - pattern: os.system(...)

Strictness Level

This workflow is strict - do not skip steps:

  • Read documentation first: See Documentation before writing Semgrep rules
  • Test-first is mandatory: Never write a rule without tests
  • 100% test pass is required: "Most tests pass" is not acceptable
  • Optimization comes last: Only simplify patterns after all tests pass
  • Avoid generic patterns: Rules must be specific, not match broad patterns
  • Prioritize taint mode: For data flow vulnerabilities
  • One YAML file - one Semgrep rule: Each YAML file must contain only one Semgrep rule; don't combine multiple rules in a single file
  • No generic rules: When targeting a specific language for Semgrep rules - avoid generic pattern matching (languages: generic)
  • Forbidden todook and todoruleid test annotations: todoruleid: <rule-id> and todook: <rule-id> annotations in tests files for future rule improvements are forbidden

Overview

This skill guides creation of Semgrep rules that detect security vulnerabilities and code patterns. Rules are created iteratively: analyze the problem, write tests first, analyze AST structure, write the rule, iterate until all tests pass, optimize the rule.

Approach selection:

  • Taint mode (prioritize): Data flow issues where untrusted input reaches dangerous sinks
  • Pattern matching: Simple syntactic patterns without data flow requirements

Why prioritize taint mode? Pattern matching finds syntax but misses context. A pattern eval($X) matches both eval(user_input) (vulnerable) and eval("safe_literal") (safe). Taint mode tracks data flow, so it only alerts when untrusted data actually reaches the sink—dramatically reducing false positives for injection vulnerabilities. <!-- security-allowlist: Semgrep taint-mode explanation -->

…

الأسئلة الشائعة

ما هو Semgrep؟

Semgrep أداة تحلل كودك لإيجاد المشكلات، مثل الأخطاء أو الثغرات الأمنية، باستخدام قواعد ينشئها أنت أو غيرك.

ما هي «قواعد» Semgrep؟

هي وصفات تخبر Semgrep بما يبحث عنه في كودك. قد تكون بسيطة، مثل «ابحث عن كل استدعاء لهذه الدالة»، أو معقدة، مثل «ابحث عن المكان الذي تصل فيه بيانات غير موثوقة إلى نقطة خطرة».

لماذا اختبار القواعد مهم؟

الاختبار يضمن أن القاعدة تجد المشكلات التي يجب أن تجدها دون أن تفوّت شيئًا، ولا تُطلق إنذارات حيث لا يجب. القواعد غير المختبرة قد تكون غير مفيدة بل ضارة.

التفاصيل

الوصف الأصلي من المؤلف

Creates custom Semgrep rules for detecting security vulnerabilities, bug patterns, and code patterns. Use when writing Semgrep rules or building custom static analysis detections.

repo: sickn33/agentic-awesome-skills

الشعبية

نجوم GitHub
48k
الترتيب
#5713
الترخيص
MIT
آخر تحديث
15‏/10‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة