Skip to content

Commit 3605ed4

Browse files
committed
fix(039): Semgrep timeout + exclude dependency dirs from scan
Semgrep timed out on ElevenLabs (14,953 files, 361MB including 6,979 Python files from site-packages). Two fixes: 1. Semgrep timeout increased from 5min to 10min for large source trees 2. Semgrep command now excludes site-packages, node_modules, dist-packages 3. Source resolver excludes dependency directories from docker diff extraction — these are third-party packages, not user code Before: ElevenLabs extracted 14,953 files (361MB) -> Semgrep timeout After: Only actual MCP server code extracted -> fast scan Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9090e9f commit 3605ed4

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

internal/security/scanner/registry_bundled.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ var bundledScanners = []*ScannerPlugin{
5353
OptionalEnv: []EnvRequirement{
5454
{Key: "SEMGREP_APP_TOKEN", Label: "Semgrep Cloud Token", Secret: true},
5555
},
56-
Command: []string{"semgrep", "scan", "--sarif", "--output", "/scan/report/results.sarif", "/scan/source"},
57-
Timeout: "300s",
58-
NetworkReq: true, // Downloads rules from registry
56+
Command: []string{"semgrep", "scan", "--sarif", "--output", "/scan/report/results.sarif", "--exclude", "site-packages", "--exclude", "node_modules", "--exclude", "dist-packages", "/scan/source"},
57+
Timeout: "600s", // 10 minutes — large source trees take time
58+
NetworkReq: true, // Downloads rules from registry
5959
},
6060
{
6161
ID: "trivy-mcp",

internal/security/scanner/source_resolver.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func (r *SourceResolver) findAppDirectories(diffOutput string) []string {
250250
return dirs
251251
}
252252

253-
// isSystemPath returns true for OS-level paths that aren't app source
253+
// isSystemPath returns true for OS-level paths or dependency dirs that aren't app source
254254
func (r *SourceResolver) isSystemPath(path string) bool {
255255
systemPrefixes := []string{
256256
"/etc/", "/var/", "/tmp/", "/proc/", "/sys/", "/dev/",
@@ -262,6 +262,12 @@ func (r *SourceResolver) isSystemPath(path string) bool {
262262
return true
263263
}
264264
}
265+
// Skip dependency directories (too large, not user code)
266+
if strings.Contains(path, "/site-packages/") ||
267+
strings.Contains(path, "/dist-packages/") ||
268+
strings.Contains(path, "/node_modules/") {
269+
return true
270+
}
265271
return false
266272
}
267273

internal/security/scanner/source_resolver_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"os"
66
"path/filepath"
7+
"strings"
78
"testing"
89

910
"go.uber.org/zap"
@@ -132,20 +133,24 @@ A /usr/local/lib/python3.11/site-packages/mcp_server/main.py`
132133

133134
dirs := r.findAppDirectories(diffOutput)
134135

135-
// Should find: /root/.npm, /app, and site-packages
136+
// Should find: /root/.npm and /app
137+
// node_modules and site-packages are now excluded (dependency code, not user code)
136138
found := make(map[string]bool)
137139
for _, d := range dirs {
138140
found[d] = true
139141
}
140142

141-
if !found["/root/.npm/_npx/abc123/node_modules"] {
142-
t.Errorf("expected node_modules dir, got %v", dirs)
143+
if !found["/root/.npm"] {
144+
t.Errorf("expected /root/.npm dir, got %v", dirs)
143145
}
144146
if !found["/app"] {
145147
t.Errorf("expected /app dir, got %v", dirs)
146148
}
147-
if !found["/usr/local/lib/python3.11/site-packages"] {
148-
t.Errorf("expected site-packages dir, got %v", dirs)
149+
// site-packages and node_modules should be filtered out
150+
for _, d := range dirs {
151+
if strings.Contains(d, "site-packages") || strings.Contains(d, "node_modules") {
152+
t.Errorf("dependency dir should be excluded: %s", d)
153+
}
149154
}
150155
}
151156

0 commit comments

Comments
 (0)