55 "encoding/base64"
66 "os"
77 "path/filepath"
8+ "strconv"
89 "strings"
910 "time"
1011
@@ -13,7 +14,18 @@ import (
1314 "github.com/step-security/dev-machine-guard/internal/progress"
1415)
1516
16- const maxProjectScanBytes = 500 * 1024 * 1024 // 500MB total limit
17+ const defaultMaxProjectScanBytes = 500 * 1024 * 1024 // 500MB total limit
18+
19+ // getMaxProjectScanBytes returns the size limit, overridable via
20+ // STEPSEC_MAX_NODE_SCAN_BYTES environment variable.
21+ func getMaxProjectScanBytes () int64 {
22+ if v := os .Getenv ("STEPSEC_MAX_NODE_SCAN_BYTES" ); v != "" {
23+ if n , err := strconv .ParseInt (v , 10 , 64 ); err == nil && n > 0 {
24+ return n
25+ }
26+ }
27+ return defaultMaxProjectScanBytes
28+ }
1729
1830// NodeScanner performs enterprise-mode node scanning (raw output, base64 encoded).
1931type NodeScanner struct {
@@ -148,10 +160,11 @@ func (s *NodeScanner) scanPnpmGlobal(ctx context.Context) (model.NodeScanResult,
148160}
149161
150162// ScanProjects finds package.json files and runs the appropriate package manager list command.
151- // Logs each found project and respects the 500MB size limit.
163+ // Logs each found project and respects the size limit (default 500MB, override via STEPSEC_MAX_NODE_SCAN_BYTES) .
152164func (s * NodeScanner ) ScanProjects (ctx context.Context , searchDirs []string ) []model.NodeScanResult {
153165 var results []model.NodeScanResult
154166 totalSize := int64 (0 )
167+ maxBytes := getMaxProjectScanBytes ()
155168 count := 0
156169
157170 for _ , dir := range searchDirs {
@@ -176,8 +189,8 @@ func (s *NodeScanner) ScanProjects(ctx context.Context, searchDirs []string) []m
176189 s .log .Progress (" Reached maximum of %d projects, stopping search" , maxNodeProjects )
177190 return filepath .SkipAll
178191 }
179- if totalSize > maxProjectScanBytes {
180- s .log .Progress (" Reached data size limit (%d bytes collected, limit: %d bytes)" , totalSize , maxProjectScanBytes )
192+ if totalSize > maxBytes {
193+ s .log .Progress (" Reached data size limit (%d bytes collected, limit: %d bytes)" , totalSize , maxBytes )
181194 s .log .Progress (" Skipping remaining projects (prioritized by most recently modified)" )
182195 return filepath .SkipAll
183196 }
@@ -196,8 +209,8 @@ func (s *NodeScanner) ScanProjects(ctx context.Context, searchDirs []string) []m
196209 r := s .scanProject (ctx , projectDir )
197210 resultSize := int64 (len (r .RawStdoutBase64 )) + int64 (len (r .RawStderrBase64 ))
198211
199- if totalSize + resultSize > maxProjectScanBytes {
200- s .log .Progress (" Reached data size limit (%d bytes collected, limit: %d bytes)" , totalSize , maxProjectScanBytes )
212+ if totalSize + resultSize > maxBytes {
213+ s .log .Progress (" Reached data size limit (%d bytes collected, limit: %d bytes)" , totalSize , maxBytes )
201214 s .log .Progress (" Skipping remaining projects (prioritized by most recently modified)" )
202215 return filepath .SkipAll
203216 }
0 commit comments