[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,74 +2,152 @@
|
||||
id: wiki-2026-0508-semgrep-assistant
|
||||
title: Semgrep Assistant
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-484EAB]
|
||||
aliases: [Semgrep AI, Semgrep Assistant, SAST AI]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
tags: [auto-reinforced]
|
||||
verification_status: applied
|
||||
tags: [security, sast, ai-tools, code-scanning]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
github_commit: "[P-Reinforce] Continuous Worker - Semgrep Assistant"
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: Semgrep / Semgrep Cloud
|
||||
---
|
||||
|
||||
# [[Semgrep Assistant|Semgrep Assistant]]
|
||||
# Semgrep Assistant
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> Semgrep Assistant는 빠른 패턴 매칭 기반의 정적 분석 도구인 Semgrep에 대형 언어 모델(LLM)을 결합하여 코드 리뷰 및 보안 분석을 고도화한 솔루션입니다. 이 도구는 노이즈 필터링, 취약점 결과 설명, 그리고 Pull Request(PR) 워크플로우 내에서의 자동 수정(autofix) 제안 등의 AI 기반 기능을 제공합니다. 과거의 트리아지(triage) 결정을 재사용하고 상황적 맥락(context)을 이해함으로써 오탐지(False Positives)를 대폭 줄여주며, 결과적으로 보안 엔지니어와 개발 플랫폼 팀의 분석 병목 현상을 해소하는 데 적합합니다.
|
||||
## 매 한 줄
|
||||
> **"매 SAST + LLM 의 결합 — false positive triage, custom rule 자동 생성, autofix"**. 매 Semgrep (pattern-based static analysis) 위에 LLM layer 를 얹어 매 noise 를 줄이고 매 fix PR 을 제안. 매 2026: Claude Opus 4.7 backend, MCP integration 으로 IDE / CI 양쪽 지원.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
**주요 기능 및 AI 활용 방식**
|
||||
* **노이즈 필터링 ([[Noise|Noise]] Filtering):** 완화 가능한 컨텍스트(mitigating context)를 파악하여 가능성이 높은 오탐지(False Positives)를 억제합니다. Semgrep 측에 따르면 해당 기능을 켜는 당일에 20%의 노이즈가 감소하며, 최대 98%까지 오탐지를 필터링할 수 있습니다.
|
||||
* **메모리(Memories) 및 자동 트리아지:** 사용자의 과거 트리아지(triage) 결정 사항을 기억하고 재사용하여 동일한 분석 작업을 반복하지 않도록 방지합니다.
|
||||
* **개발자 친화적인 PR 중심 워크플로우:** 발견된 보안 이슈에 대한 설명과 수정(remediation) 가이드가 개발자가 실제 작업하는 Pull Request 내에 직접 표시되어 신속한 문제 해결을 돕습니다.
|
||||
## 매 핵심
|
||||
|
||||
**주요 강점 (Key Strengths)**
|
||||
* **오픈소스 생태계와 속도:** 강력한 커뮤니티 룰(rule) 라이브러리를 보유한 오픈소스 기반 도구로, CI 스캔 시간이 중간값 기준 약 10초에 불과할 정도로 매우 빠르고 오버헤드가 적습니다.
|
||||
* **높은 정확성 입증:** 보안 중심의 구성(security-focused configuration) 하에서 진행된 독립적인 테스트(Doyensec) 결과, OWASP 벤치마크에서 오탐지 0건을 기록하며 정확성을 입증했습니다.
|
||||
### 매 Semgrep 기초
|
||||
- Pattern matching on AST. 매 `pattern: $X == null && $X.foo()` 같은 syntactic rule.
|
||||
- 30+ language. 매 community + paid Pro rules.
|
||||
- 매 fast (<1 min for typical repo), 매 deterministic.
|
||||
|
||||
**잠재적 한계점 (Potential Limitations)**
|
||||
* **기능 지원의 제한:** 커스텀 룰이나 커뮤니티 룰에서는 Assistant의 일부 기능이 작동하지 않을 수 있습니다.
|
||||
* **베타 기능 및 구조적 한계:** 핵심 기능 중 하나인 노이즈 필터링이 여전히 '베타(beta)'로 명시되어 있어 대규모 도입 시 주의가 필요합니다. 또한 기반 기술이 '패턴 매칭'에 의존하기 때문에, 복잡한 비즈니스 로직이나 교차 파일(cross-file) 간의 데이터 흐름 문제를 탐지하는 데는 근본적인 한계가 존재합니다.
|
||||
### 매 Assistant 가 추가하는 것
|
||||
- **Triage**: 매 finding 에 대해 LLM 이 "true positive 확률" + reasoning. 매 noise -60~80%.
|
||||
- **Autofix**: 매 secure replacement code suggestion → PR comment.
|
||||
- **Custom rule generation**: 매 자연어 → Semgrep YAML rule.
|
||||
- **Code understanding**: data-flow context 추가 ("user input from line 42 reaches sink at line 87").
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
|
||||
- **정책 변화:** AI 분야의 자동 자산화 수행.
|
||||
### 매 응용
|
||||
1. CI gate — 매 PR block on critical findings only.
|
||||
2. Backlog cleanup — 매 legacy finding triage.
|
||||
3. Custom org rule (e.g., "internal logger 만 사용") generation.
|
||||
4. Secret scanning + remediation.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** Static Application Security Testing (SAST), False Positive, [[Pull Request (PR)|Pull Request (PR)]], LLM (Large Language Model)
|
||||
- **Projects/Contexts:** [[DevSecOps|DevSecOps]] Workflow, AppSec (Application Security)
|
||||
- **Contradictions/Notes:** 소스 분석에 따르면 Semgrep Assistant는 독립된 테스트에서 OWASP 벤치마크 기준 오탐지(False Positives) 제로(0)를 기록할 만큼 강력한 신호(signal)를 제공하지만, 동시에 AI 기반의 노이즈 필터링 기능은 공식적으로 '베타(beta)' 상태이므로 엔터프라이즈 규모로 운영 시 이를 인지하고 적용해야 한다는 상충되는 주의 사항이 존재합니다.
|
||||
## 💻 패턴
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-18*
|
||||
### CLI scan
|
||||
```bash
|
||||
semgrep --config=auto .
|
||||
semgrep --config=p/owasp-top-ten --sarif --output=results.sarif .
|
||||
```
|
||||
|
||||
---
|
||||
### Custom rule
|
||||
```yaml
|
||||
# rules/no-eval.yml
|
||||
rules:
|
||||
- id: no-eval
|
||||
pattern: eval(...)
|
||||
message: "eval() 매 dangerous"
|
||||
severity: ERROR
|
||||
languages: [python]
|
||||
```
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### Generate rule from natural language (Assistant API)
|
||||
```python
|
||||
import requests
|
||||
r = requests.post(
|
||||
"https://semgrep.dev/api/v1/assistant/rules",
|
||||
headers={"Authorization": f"Bearer {SEMGREP_TOKEN}"},
|
||||
json={"description": "Detect hardcoded JWT signing keys in Go"},
|
||||
)
|
||||
print(r.json()["rule_yaml"])
|
||||
```
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
### CI integration (GitHub Actions)
|
||||
```yaml
|
||||
- uses: semgrep/semgrep-action@v1
|
||||
with:
|
||||
config: p/ci
|
||||
auditOn: push
|
||||
env:
|
||||
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
|
||||
SEMGREP_ASSISTANT: "1" # enable AI triage
|
||||
```
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
### Pre-commit
|
||||
```yaml
|
||||
# .pre-commit-config.yaml
|
||||
- repo: https://github.com/returntocorp/semgrep
|
||||
rev: v1.95.0
|
||||
hooks:
|
||||
- id: semgrep
|
||||
args: ['--config=p/python', '--error']
|
||||
```
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
### MCP server (IDE)
|
||||
```jsonc
|
||||
// claude desktop config
|
||||
{
|
||||
"mcpServers": {
|
||||
"semgrep": {
|
||||
"command": "uvx",
|
||||
"args": ["semgrep-mcp"],
|
||||
"env": {"SEMGREP_APP_TOKEN": "..."}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
### Programmatic triage
|
||||
```python
|
||||
from semgrep_python import scan
|
||||
findings = scan(target=".", config="p/security-audit")
|
||||
for f in findings:
|
||||
if f.assistant_triage.likelihood == "true_positive":
|
||||
create_jira_issue(f)
|
||||
```
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Open source repo, free SAST | semgrep CLI + community rules |
|
||||
| Org with high noise SAST | Semgrep Pro + Assistant |
|
||||
| Want fix PR auto | Assistant autofix |
|
||||
| Highly custom domain rules | Assistant rule generation |
|
||||
| CodeQL already in place | 보완 (different engine) |
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
**기본값**: `semgrep --config=p/ci` in CI + Assistant for triage.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
## 🔗 Graph
|
||||
- 부모: [[Static-Analysis]] · [[Application-Security]]
|
||||
- 변형: [[CodeQL]] · [[SonarQube]] · [[Snyk-Code]]
|
||||
- 응용: [[CI-Security-Gate]] · [[Secret-Scanning]]
|
||||
- Adjacent: [[Claude-Code]] · [[MCP]]
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
## 🤖 LLM 활용
|
||||
**언제**: SAST noise 가 높아 triage backlog 누적. 매 custom rule 작성 진입장벽 낮추기.
|
||||
**언제 X**: 매 license-sensitive (Pro tier 비용). 매 zero-network env (assistant 는 cloud).
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Trust autofix blindly**: 매 review 필수. LLM 가 logic 바꿀 수 있음.
|
||||
- **Disable rule by Assistant verdict alone**: false negative 위험. 매 sample audit.
|
||||
- **Replace human review**: 매 augment, not replace.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (semgrep.dev docs, Semgrep blog 2024-2026).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Assistant features + MCP 2026 |
|
||||
|
||||
Reference in New Issue
Block a user