技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
security-sast-dast【数据与研究】Use this skill when asked about SAST, DAST, static analysis, dynamic analysis, code scanning, SonarQube, Semgrep, Checkmarx, Fortify, OWASP ZAP, or Burp Suite. This skill enforces: SAST tool integration with custom rule writing, DAST scanning with authenticated sessions, false positive triage workflow, and CI pipeline gate configuration. Do NOT use f…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Build a security scanning pipeline with static analysis rule sets, dynamic analysis scenarios, false positive management, and CI gating.
Exact user phrases: "SAST", "DAST", "static analysis", "dynamic analysis", "code scanning", "SonarQube", "Semgrep", "Checkmarx", "Fortify", "OWASP ZAP", "Burp Suite", "security scan pipeline", "code quality gate", "scan results", "false positive".
Before activating, verify:
Security scanning pipeline configuration as YAML and rule set files.
# SAST pipeline step
# Semgrep rules
# Quality gate thresholds
# DAST scan script
# CI integration snippet
No preamble. No postamble. No explanations. No filler/hedging/transitions. Compress output — why use many token when few do trick.
300 lines of configuration and rules.
What is the primary goal?
├── Custom rule writing per project patterns → Semgrep
├── Deep interprocedural / variant analysis → CodeQL
├── Quality gates and tech debt tracking → SonarQube
├── Unified platform (code + deps + containers) → Snyk Code
└── Enterprise compliance reporting → Checkmarx / Fortify
Is the repo public or private?
├── Public → Semgrep (free) + CodeQL (free for public repos)
├── Private with GitHub Advanced Security → CodeQL included
└── Private without GHAS → Semgrep (free) + SonarQube Community (free)
What languages are in the codebase?
├── Python, JavaScript/TypeScript, Java, Go → Any tool works
├── C/C++, C#, Kotlin, Swift → CodeQL or Semgrep
├── Ruby, PHP, Rust → Semgrep (best coverage)
├── Scala, Kotlin → CodeQL or Semgrep
└── 10+ languages → SonarQube (broadest support)
What is the team size?
├── <10 developers → Semgrep + ZAP (free, effective)
├── 10-50 developers → Semgrep + SonarQube + ZAP
├── 50-200 developers → Semgrep + SonarQube + Burp Pro + ZAP
└── >200 developers → Enterprise suite (Checkmarx/Fortify + Acunetix)
What is the budget?
├── $0 → OWASP ZAP (full-featured, free)
├── $500-1000/year → ZAP + Burp Suite Community
├── $5000+/year → Burp Suite Professional
└── Enterprise budget → Acunetix or Burp Enterprise
What type of application?
├── Standard web app (HTML forms, links) → Any DAST tool
├── SPA (React, Angular, Vue) → ZAP (SPA-friendly crawler) or Burp
├── API-only (REST, GraphQL) → ZAP API scan (best for OpenAPI/GraphQL)
├── Mobile app backend → Burp (mobile proxy setup)
└── Internal enterprise app → Acunetix (macro auth)
What is the scan target?
├── CI/CD (automated, pipeline) → ZAP Docker (best CI integration)
├── Manual penetration testing → Burp Suite (best manual workflow)
├── Compliance scanning → Acunetix (comprehensive reporting)
└── Production passive scanning → ZAP baseline (safe, read-only)
Findings correlation matrix:
Vulnerability Class │ SAST Covers │ DAST Covers
───────────────────────────────────────────────────────────────
SQL Injection │ Source + sink │ Confirms exploitability
XSS │ Sink only │ Confirms with payload
Command Injection │ Source + sink │ Confirms exploitability
Path Traversal │ Source + sink │ Confirms exploitability
SSRF │ Source (limited) │ Confirms endpoint
Authentication Bypass │ Logic patterns │ Confirms via session
Authorization Issues │ Missing checks │ Confirms via access
CSRF │ Missing tokens │ Confirms via request
Insecure Deserialization │ Dangerous calls │ Confirms via payload
Sensitive Data Exposure │ Hardcoded secrets │ Confirms in response
Security Misconfiguration │ Config analysis │ Confirms headers/CSP
XXE │ Parser config │ Confirms with payload
Workflow:
├── SAST finds potential vulnerability with file/line reference
├── Map to DAST-affected endpoint (if applicable)
├── DAST confirms exploitability with live payload
├── If SAST flags but DAST cannot confirm → manual review
├── If DAST finds but SAST didn't flag → improve SAST rules
└── Both-positive findings: highest priority for remediation
Semgrep is the recommended default SAST tool for most projects. It is fast, multi-language, and excels at custom rule writing. Rule packs come from the Semgrep Registry. Rules are written in YAML with a pattern-matching syntax that can detect code patterns across function boundaries. Semgrep supports all major languages (Python, JavaScript/TypeScript, Java, Go, Rust, Ruby, C#, PHP, Kotlin, Scala) and runs in CI with diff-aware scanning. Install via pip install semgrep or use the official GitHub Action. Key strengths: pattern-based matching that goes beyond regex, support for metavariables and ellipsis operators, community-maintained rule packs, and a built-in rule testing framework.
CodeQL is best for deep interprocedural analysis and variant analysis. Developed by GitHub, it uses a declarative query language (QL) to find vulnerabilities across the codebase. A single CodeQL query can find all variants of a vulnerability pattern (e.g., all paths where user input reaches a SQL query). CodeQL requires a compiled database of the codebase, which is built during the CI scan step. It supports C/C++, C#, Go, Java/Kotlin, JavaScript/TypeScript, Python, and Ruby. CodeQL is free for public repositories and included in GitHub Advanced Security for private repos. Key strengths: variant analysis, data flow tracking across function and file boundaries, and deep semantic understanding of the code.
SonarQube is the best tool for quality gates, technical debt tracking, and broad language support. It tracks code quality metrics over time: coverage, duplicated lines, code smells, bugs, vulnerabilities, and hotspots. The quality gate is a configurable policy that blocks PRs when predefined thresholds are exceeded. SonarQube can be self-hosted (Community Edition is free) or used as SonarCloud (SaaS). It supports 30+ languages. Key strengths: historical trend tracking, quality gates as a PR policy, security hotspots that require manual review, and broad ecosystem integrations.
Snyk Code is a SAST tool integrated into the Snyk platform. It is particularly strong for finding vulnerabilities in open-source dependencies and container images combined with application-level code analysis. It uses deep semantic analysis and AI to find issues with low false positive rates. Snyk Code integrates with Snyk Open Source and Snyk Container for a unified vulnerability management experience. Key strengths: low false positive rate, IDE integration for real-time feedback, and unified platform with dependency scanning and container scanning.
OWASP ZAP (Zed Attack Proxy) is the recommended default DAST tool. It is free, open-source, and community-maintained. ZAP can be run as a desktop application, a daemon for CI integration, or a Docker container. Scan modes: automated scan (spider → passive → active), API scan (import OpenAPI/GraphQL schema), and baseline scan (passive-only, safe for production). ZAP supports authenticated scanning via context-based session management, bearer token injection, and form-based authentication. The HUD (Heads-Up Display) mode provides browser-based interaction for manual testing. Key strengths: free and open-source, extensive active scan rules, API scanning, and Docker-native CI integration.
Burp Suite is the professional standard for web application security testing. The Community Edition includes an HTTP proxy, repeater, decoder, and scanner. The Professional Edition adds automated scanning, advanced vulnerability detection, and CI integration. Burp's scanning phases: crawl (discover all endpoints), audit (automated vulnerability checks), and intruder (targeted fuzzing). Extensions from the BApp Store extend functionality: Autorize for auth bypass detection, JSON Web Tokens for JWT manipulation, and ActiveScan++ for enhanced scan coverage. Key strengths: manual testing workflow, extensive extension ecosystem, and industry-standard tooling.
Acunetix is a commercial DAST tool with deep scanning capabilities. It is known for its comprehensive vulnerability database covering over 7000 vulnerabilities. Acunetix supports multi-step form authentication, macro recording for complex login sequences, and integration with issue trackers (Jira, GitHub Issues). Key strengths: deep scanning for complex vulnerabilities, macro-based authentication, and enterprise reporting.
Semgrep: best for custom rule writing, multi-language, fast. SonarQube: best for quality gates, technical debt tracking, broad language support. CodeQL: best for deep interprocedural analysis, variant analysis. Checkmarx/Fortify: enterprise-grade with compliance reporting. Default choice: Semgrep for SAST + SonarQube for quality gates.
Enable built-in rule packs: Semgrep p/security-audit, p/owasp-top-ten, p/command-injection. Write custom rules for project-specific patterns: hardcoded secrets, dangerous function usage, missing authorization checks, SQL injection via ORM bypass. Rule severity: ERROR (must fix), WARN (should fix), INFO (suggested). False positives: tag with fp metadata and documented reason.
SAST runs on every PR — diff-aware scanning for changed files only. Full scan on main branch daily. Quality gates: 0 ERROR severity findings, WARN count must not increase, coverage threshold for new code. DAST runs on staging deployment — weekly full scan, on-demand for critical releases. Pipeline blocks on critical findings.
OWASP ZAP: automated scan with API context, authenticated session management via bearer token or form auth. Burp Suite: manual testing with targeted scope. Scan profile: spider (crawl all pages), active scan (inject payloads), fuzzing (parameter mutation). Exclude logout, password change, and high-volume endpoints from active scanning.
Triage workflow: automated deduplication → security review → mark as FP/WONT-FIX/ACCEPTED-RISK. Store decisions in .sast-fps.yml per project. Suppress known FP with reason comment and expiry date. Review suppressed rules quarterly.
Semgrep custom rules follow a standard pattern: rule ID in kebab-case, severity (ERROR/WARN/INFO), languages array, and patterns (match, exclude, condition). Test rules with positive and negative test cases annotated with ruleid: and ok: comments. Run semgrep --test to validate. Store custom rules in .semgrep/rules/ organized by vulnerability category. Each rule directory has a tests/ subdirectory with test files.
For applications requiring authentication, configure the scan context: define the login URL, authentication type (form-based, bearer token, OAuth), credentials, and session cookie name. ZAP uses a context file (.context) that defines the URL regex, authentication script, and session management. For API-focused applications, use API keys or bearer tokens in request headers. Test authentication before running a full scan by verifying the auth token/cookie is correctly injected into scan requests.
Define the DAST scan scope precisely to avoid scanning out-of-scope endpoints. In-scope: the application's own domains and subdomains. Out-of-scope: third-party CDNs, analytics endpoints, authentication providers, social login. Scope is defined as URL regex patterns in the scan tool. For API scanning, scope is defined by the OpenAPI/Swagger specification paths. Exclude destructive endpoints (DELETE, mass-update) from active scanning.
Map SAST findings to affected endpoints in DAST scope. Prioritize findings that appear in both analyses. Track finding age: 0-7 days (active), 7-30 days (aging), 30+ days (overdue). Generate weekly trend report by severity and category.
| Feature | Semgrep | CodeQL | SonarQube | Snyk Code |
|---|---|---|---|---|
| Primary strength | Custom rules, speed | Deep interprocedural, variant analysis | Quality gates, tech debt tracking | Low FP rate, IDE integration |
| Language support | 20+ languages | 7 languages | 30+ languages | 10+ languages |
| Rule format | YAML patterns | QL queries | Built-in rules + plugin API | Built-in + custom |
| CI integration | GitHub Action, CLI | GitHub Action | SonarScanner CLI, GitHub Action | Snyk CLI, GitHub Action |
| Diff-aware | Yes (--baseline-commit) | Yes (PR analysis) | Yes (new code analysis) | Yes |
| False positive rate | Low-Medium | Low | Medium | Very low |
| Licensing | Open source (LGPL) | Free for public repos | Community (free), Developer (paid) | Free tier, paid plans |
| Best for | General SAST + custom rules | Security research, variant analysis | Quality gates, coverage tracking | Platform approach (code + deps + containers) |
| Feature | OWASP ZAP | Burp Suite | Acunetix |
|---|---|---|---|
| Cost | Free | Community: free, Pro: $449/year | Commercial (custom pricing) |
| Scan modes | Automated, API, Baseline | Crawl, Audit, Intruder | DeepScan, QuickScan |
| CI integration | Docker + CLI action | Pro only (REST API) | Yes (CLI + REST API) |
| Authentication | Context-based, form, token | Macro-based, form, token | Macro recording |
| API scanning | OpenAPI, GraphQL, SOAP | OpenAPI via extension | OpenAPI, GraphQL |
| WebSocket testing | Limited | Yes (via extension) | Yes |
| Reporting | HTML, JSON, Markdown, PDF | HTML, XML, PDF | HTML, PDF, Excel |
| Extensibility | Scripts (JS, Python) | BApp Store (100+ extensions) | Limited |
| Best for | Budget-conscious teams, CI | Professional manual testing | Enterprise compliance |
| Scan Type | Tool | Frequency | Duration | Target | Gate |
|---|---|---|---|---|---|
| Diff SAST | Semgrep | Per PR | < 5 min | PR diff | Block on ERROR |
| Full SAST | SonarQube | Daily (main branch) | 15-60 min | Full codebase | Report only |
| Quick DAST | ZAP baseline | Per deployment | 15-30 min | Staging | Report only |
| Full DAST | ZAP active | Weekly | 2-4 hours | Staging | Block on HIGH/MEDIUM |
| Deep DAST | Burp/Acunetix | Monthly | 4-8 hours | Staging copy | Full report |
| Compliance DAST | Acunetix | Quarterly | Full day | Production (passive only) | Compliance report |
New Finding → Automated Dedup → Categorize Severity
├── CRITICAL: Immediate fix (24h SLA) → Hotfix PR required
├── HIGH: Fix in current sprint (72h SLA) → Bug ticket created
├── MEDIUM: Fix within 2 sprints → Backlog item
└── LOW: Fix when convenient → Icebox
│
└── Review → Is it a real vulnerability?
├── Yes → Assign to team, create remediation ticket
├── FP → Add to .sast-fps.yml with reason
└── WONT-FIX → Document accepted risk, get security team approval
| Severity | Discovery to Fix | Verification | Reporting |
|---|---|---|---|
| CRITICAL | 24 hours | 12 hours | Within SLA |
| HIGH | 72 hours | 24 hours | Weekly report |
| MEDIUM | 2 sprints | 1 sprint | Monthly report |
| LOW | Indefinite | Per fix | Quarterly report |
Full codebase scans take 30-60 minutes, blocking CI pipelines. Use diff-aware scanning for PRs (Semgrep --baseline-commit, SonarQube new code analysis). Save full scans for nightly builds.
Active DAST scanning sends malicious payloads that can corrupt data, trigger alerts, or crash services. Always target staging or a dedicated test environment. Production scans must be passive-only (ZAP baseline, read-only checks).
Without a documented FP process, teams ignore scan results entirely. Create a .sast-fps.yml file per project, tag findings with rationale, and review quarterly.
SAST finds code-level issues. DAST finds runtime issues. They complement each other but are often run in isolation. Correlate findings: SAST flags the source, DAST confirms exploitability. Prioritize correlated findings.
DAST scanning third-party endpoints, analytics services, or auth providers causes false positives and may violate terms of service. Define scope precisely with URL regex patterns.
Scanning only unauthenticated pages misses 80% of application logic. Always configure authenticated sessions. Test authentication injection before full scan execution.
Default rule packs are generic and miss project-specific patterns. Write custom rules for your framework, authentication model, and business logic.
Without severity-defined SLAs, critical findings sit alongside low-priority ones. Set SLAs: CRITICAL 24h, HIGH 72h, MEDIUM 2 sprints, LOW per backlog.
Blocking on WARN or INFO findings creates friction and leads to rule bypass. Block only on ERROR/CRITICAL. Use WARN to trend, not to block.
Without trend data, you cannot tell if security posture is improving or degrading. SonarQube tracks metrics over time. Generate weekly trend reports by severity.
--baseline-commit). Full scan nightly.semgrep --test.Semgrep is faster and easier for custom rule writing (YAML patterns, simple syntax). CodeQL provides deeper interprocedural analysis but requires a compiled database and QL query language. Choose Semgrep for quick custom rules, CodeQL for variant analysis and complex data-flow tracing.
Semgrep focuses on finding vulnerabilities with custom patterns. SonarQube tracks overall code health: coverage, duplication, code smells, technical debt. They are complementary. Use Semgrep for SAST detection. Use SonarQube for quality gates and trends.
ZAP is free, open-source, and CI-friendly (Docker, CLI). Burp Suite Pro offers better manual testing workflows and a rich extension ecosystem. Use ZAP for CI/CD automation. Use Burp for professional manual pentesting.
ZAP is free with community support. Acunetix is commercial with deeper scanning, macro auth recording, and enterprise compliance reporting. Use ZAP for regular CI scanning. Use Acunetix for quarterly compliance scans.
SAST finds issues early in development (shift-left) with file/line precision. DAST finds runtime issues with exploitability confirmation. SAST has higher false positive rate. DAST has higher true positive rate but finds issues later. Use both for defense in depth.
# .semgrep/rules/security/aws-creds.yml
rules:
- id: hardcoded-aws-creds
patterns:
- pattern-regex: (?:AWS_ACCESS_KEY_ID|AWS_SECRET_ACCESS_KEY)\s*=\s*['"](?!\{\{)
- pattern-not-regex: \{\{.*\}\}
message: "Hardcoded AWS credential detected"
severity: ERROR
languages: [generic]
metadata:
category: security
technology: aws
# .semgrep/rules/security/sql-injection.yml
rules:
- id: sql-injection-py
patterns:
- pattern: |
cursor.execute(f"...$QUERY...")
- pattern-not: |
cursor.execute("...", ...)
message: "SQL injection via f-string interpolation"
severity: ERROR
languages: [python]
metadata:
cwe: CWE-89
owasp: A03:2021
# .semgrep/rules/security/nosql-injection.yml
rules:
- id: mongodb-nosql-injection
patterns:
- pattern: |
$DB.find({ $KEY: { "\$where": $VAL } })
- pattern-not: |
$DB.find({ $KEY: { "\$where": literal($VAL) } })
message: "NoSQL injection via $where operator"
severity: ERROR
languages: [javascript, typescript]
# .github/workflows/security-scan.yml
name: Security Scan
on:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
sast:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Semgrep SAST
uses: semgrep/semgrep-action@v1
with:
config: >-
p/security-audit
p/owasp-top-ten
.semgrep/rules/
auditOn: push
generateSarif: true
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: semgrep.sarif
dast:
needs: deploy-staging
runs-on: ubuntu-latest
steps:
- name: ZAP Baseline Scan
uses: zaproxy/action-baseline@v0.12
with:
target: https://staging.example.com
rules_file_name: .zap/rules.tsv
cmd_options: '-a'
# .github/security-gates.yml
quality_gates:
sast:
error_threshold: 0
warn_threshold: 10
block_on_error: true
block_on_warn: false
dast:
high_findings_threshold: 0
medium_findings_threshold: 5
block_on_high: true
block_on_medium: false
Manual scanning by security team. No CI integration. No defined SLAs. Findings tracked in spreadsheets. No correlation between SAST and DAST.
SAST runs in CI on every PR. DAST runs weekly on staging. Basic severity-gated policy (block on CRITICAL). False positives tracked in YAML files. Weekly scan reports.
Diff-aware SAST + full daily scan. DAST baseline per deployment + full DAST weekly. Custom rules for framework-specific patterns. SAST-DAST correlation with prioritized backlog. SLAs enforced with automated ticket creation.
Real-time scanning in IDE. AI-assisted false positive triage. Automated rule generation from incident patterns. Runtime verification correlates SAST findings with live behavior. Supply chain + SAST + DAST unified risk scoring. Self-healing: auto-rollback on critical findings in production.
Blocking CI on MEDIUM or LOW findings creates negative developer sentiment and leads to rule bypass. Block only on ERROR/CRITICAL/confirmed HIGH. Use lower severity for trends and education only.
Default rule packs are generic and miss framework-specific vulnerabilities. Always add custom rules for your ORM, auth library, template engine, and serialization framework.
Without documenting and reviewing false positives, the same noise appears in every scan. Developers learn to ignore results. Create .sast-fps.yml with rationale, review quarterly.
SAST produces theoretical findings; DAST confirms exploitation. Running SAST in isolation generates high noise. Prioritize findings confirmed by both tools.
Active DAST scanning sends real attack payloads that can corrupt data, trigger security alerts, or crash services. Target staging or dedicated test environments. Production gets passive baseline only.
Scanning only public pages misses 80-90% of the application attack surface. Always configure authenticated sessions with the appropriate user role. Test authentication injection before full scan.
Scanning without URL scope includes third-party services, CDNs, and auth providers. This generates irrelevant alerts and may violate terms of service. Define scope with precise regex patterns.
Modern applications have more API endpoints than UI pages. DAST must cover REST, GraphQL, and gRPC endpoints using OpenAPI/GraphQL schema imports. API-only scans with ZAP or dedicated API scanners.
Default scan speeds can overwhelm staging environments. Configure delays: -t for threads, -d for delay in ZAP. For API scanning, respect rate limits to avoid false network error findings.
.semgrep/rules/ with testssecurity-api-security for API-specific scanning and protection rules
devops-ci-cd for pipeline integration and deployment gates