1
---
2
name: sast-configuration
3
description: Configure Static Application Security Testing (SAST) tools for automated vulnerability detection in application code. Use when setting up security scanning, implementing DevSecOps practices, or automating code vulnerability detection.
4
---
5
6
# SAST Configuration
7
8
Static Application Security Testing (SAST) tool setup, configuration, and custom rule creation for comprehensive security scanning across multiple programming languages.
9
10
## Overview
11
12
This skill provides comprehensive guidance for setting up and configuring SAST tools including Semgrep, SonarQube, and CodeQL. Use this skill when you need to:
13
14
- Set up SAST scanning in CI/CD pipelines
15
- Create custom security rules for your codebase
16
- Configure quality gates and compliance policies
17
- Optimize scan performance and reduce false positives
18
- Integrate multiple SAST tools for defense-in-depth
19
20
## Core Capabilities
21
22
### 1. Semgrep Configuration
23
24
- Custom rule creation with pattern matching
25
- Language-specific security rules (Python, JavaScript, Go, Java, etc.)
26
- CI/CD integration (GitHub Actions, GitLab CI, Jenkins)
27
- False positive tuning and rule optimization
28
- Organizational policy enforcement
29
30
### 2. SonarQube Setup
31
32
- Quality gate configuration
33
- Security hotspot analysis
34
- Code coverage and technical debt tracking
35
- Custom quality profiles for languages
36
- Enterprise integration with LDAP/SAML
37
38
### 3. CodeQL Analysis
39
40
- GitHub Advanced Security integration
41
- Custom query development
42
- Vulnerability variant analysis
43
- Security research workflows
44
- SARIF result processing
45
46
## Quick Start
47
48
### Initial Assessment
49
50
1. Identify primary programming languages in your codebase
51
2. Determine compliance requirements (PCI-DSS, SOC 2, etc.)
52
3. Choose SAST tool based on language support and integration needs
53
4. Review baseline scan to understand current security posture
54
55
### Basic Setup
56
57
```bash
58
# Semgrep quick start
59
pip install semgrep
60
semgrep --config=auto --error
61
62
# SonarQube with Docker
63
docker run -d --name sonarqube -p 9000:9000 sonarqube:10.8-community
64
65
# CodeQL CLI setup
66
gh extension install github/gh-codeql
67
codeql database create mydb --language=python
68
```
69
70
## Integration Patterns
71
72
### CI/CD Pipeline Integration
73
74
```yaml
75
# GitHub Actions example
76
- name: Run Semgrep
77
uses: returntocorp/semgrep-action@v1
78
with:
79
config: >-
80
p/security-audit
81
p/owasp-top-ten
82
```
83
84
### Pre-commit Hook
85
86
```bash
87
# .pre-commit-config.yaml
88
- repo: https://github.com/returntocorp/semgrep
89
rev: v1.45.0
90
hooks:
91
- id: semgrep
92
args: ['--config=auto', '--error']
93
```
94
95
## Best Practices
96
97
1. **Start with Baseline**
98
- Run initial scan to establish security baseline
99
- Prioritize critical and high severity findings
100
- Create remediation roadmap
101
102
2. **Incremental Adoption**
103
- Begin with security-focused rules
104
- Gradually add code quality rules
105
- Implement blocking only for critical issues
106
107
3. **False Positive Management**
108
- Document legitimate suppressions
109
- Create allow lists for known safe patterns
110
- Regularly review suppressed findings
111
112
4. **Performance Optimization**
113
- Exclude test files and generated code
114
- Use incremental scanning for large codebases
115
- Cache scan results in CI/CD
116
117
5. **Team Enablement**
118
- Provide security training for developers
119
- Create internal documentation for common patterns
120
- Establish security champions program
121
122
## Common Use Cases
123
124
### New Project Setup
125
126
```bash
127
# Semgrep: install, then run an auto-config scan that exits non-zero on findings
128
pip install semgrep
129
semgrep --config=auto --error
130
131
# SonarQube: start a community server for local evaluation, then analyze with sonar-scanner.
132
# SONAR_ES_BOOTSTRAP_CHECKS_DISABLE skips the Elasticsearch host checks for a local try-out;
133
# a real deployment needs vm.max_map_count>=524288 and fs.file-max>=131072 on the host instead.
134
docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:10.8-community
135
```
136
137
### Custom Rule Development
138
139
```yaml
140
rules:
141
- id: hardcoded-jwt-secret
142
pattern: jwt.encode($DATA, "...", ...)
143
message: JWT secret should not be hardcoded
144
severity: ERROR
145
```
146
147
### Compliance Scanning
148
149
```bash
150
# PCI-DSS focused scan
151
semgrep --config p/pci-dss --json -o pci-scan-results.json
152
```
153
154
## Troubleshooting
155
156
### High False Positive Rate
157
158
- Review and tune rule sensitivity
159
- Add path filters to exclude test files
160
- Use nostmt metadata for noisy patterns
161
- Create organization-specific rule exceptions
162
163
### Performance Issues
164
165
- Enable incremental scanning
166
- Parallelize scans across modules
167
- Optimize rule patterns for efficiency
168
- Cache dependencies and scan results
169
170
### Integration Failures
171
172
- Verify API tokens and credentials
173
- Check network connectivity and proxy settings
174
- Review SARIF output format compatibility
175
- Validate CI/CD runner permissions
176
177
## Related Skills
178
179
- [STRIDE Analysis Patterns](../stride-analysis-patterns/SKILL.md)
180
- [Threat Mitigation Mapping](../threat-mitigation-mapping/SKILL.md)
181
182
## Tool Comparison
183
184
| Tool | Best For | Language Support | Cost | Integration |
185
| --------- | ------------------------ | ---------------- | --------------- | ------------- |
186
| Semgrep | Custom rules, fast scans | 30+ languages | Free/Enterprise | Excellent |
187
| SonarQube | Code quality + security | 25+ languages | Free/Commercial | Good |
188
| CodeQL | Deep analysis, research | 10+ languages | Free (OSS) | GitHub native |
189
190
## Next Steps
191
192
1. Complete initial SAST tool setup
193
2. Run baseline security scan
194
3. Create custom rules for organization-specific patterns
195
4. Integrate into CI/CD pipeline
196
5. Establish security gate policies
197
6. Train development team on findings and remediation
198