Skip to content

Commit f72081c

Browse files
committed
Add max file size flag and enhance file processing logic
- Introduced a new flag `--max-file-size` to set the maximum file size for scanning. - Updated `processLocalFiles` function to accept the max file size parameter. - Modified file processing logic to skip files exceeding the specified size. - Added a new pattern for Netlify Access Tokens to improve detection capabilities.
1 parent d853832 commit f72081c

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

cmd/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ func init() {
150150
// Group: General Behavior
151151
rootCmd.Flags().BoolP("no-progress", "n", false, "Disable the progress bar display") // Added based on scan.go
152152
rootCmd.Flags().BoolP("silent", "s", false, "Silent mode (suppress progress bar and info logs)") // Kept, might conflict with no-progress? Review needed.
153+
rootCmd.Flags().Int64("max-file-size", 10, "Maximum file size to scan in MB (0 for no limit)")
153154
vip.BindPFlag("no_progress", rootCmd.Flags().Lookup("no-progress"))
154155
vip.BindPFlag("silent", rootCmd.Flags().Lookup("silent"))
155-
156+
vip.BindPFlag("max_file_size", rootCmd.Flags().Lookup("max-file-size"))
156157
}
157158

cmd/scan.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func runScan(cmd *cobra.Command, args []string) error {
255255
wg.Add(1)
256256
go func() {
257257
defer wg.Done()
258-
secrets, err := processLocalFiles(localFiles, logger, writer, pm, scanConcurrency, vip.GetBool("no_progress"), silentMode)
258+
secrets, err := processLocalFiles(localFiles, logger, writer, pm, scanConcurrency, vip.GetBool("no_progress"), silentMode, vip.GetInt64("max_file_size"))
259259
if err != nil {
260260
logger.Error("Error processing local files: %v", err)
261261
mu.Lock()
@@ -556,15 +556,7 @@ func collectFilesFromDirectory(dirPath string, logger *output.Logger) ([]string,
556556
return nil
557557
}
558558

559-
ext := strings.ToLower(filepath.Ext(path))
560-
if ext == ".js" || ext == ".jsx" || ext == ".ts" ||
561-
ext == ".html" || ext == ".css" || ext == ".json" ||
562-
ext == ".txt" || ext == ".xml" || ext == ".yml" ||
563-
ext == ".yaml" || ext == ".md" || ext == ".csv" ||
564-
ext == ".config" || ext == ".ini" || ext == ".conf" ||
565-
ext == "" {
566-
files = append(files, path)
567-
}
559+
files = append(files, path)
568560

569561
return nil
570562
})
@@ -620,10 +612,10 @@ func logInputSummary(logger *output.Logger, remoteURLs, localFiles []string) {
620612
Processes local files using the scanner
621613
Signature updated to accept silent bool
622614
*/
623-
func processLocalFiles(files []string, logger *output.Logger, writer *output.Writer, pm *patterns.PatternManager, concurrency int, noProgress bool, silent bool) (int, error) {
615+
func processLocalFiles(files []string, logger *output.Logger, writer *output.Writer, pm *patterns.PatternManager, concurrency int, noProgress bool, silent bool, maxFileSizeMB int64) (int, error) {
624616
scannerCfg := scanner.LocalScannerConfig{
625617
Concurrency: concurrency,
626-
MaxFileSize: 10 * 1024 * 1024,
618+
MaxFileSize: maxFileSizeMB * 1024 * 1024,
627619
NoProgress: noProgress,
628620
Silent: silent,
629621
}

core/patterns/patterns.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,16 @@ var DefaultPatterns = &PatternDefinitions{
375375
MinLength: 64,
376376
},
377377

378+
"netlify_access_token": {
379+
Regex: `nf[pcfub]_[a-zA-Z0-9_\\-]{36}`,
380+
Description: "Netlify Access Token",
381+
Enabled: true,
382+
Category: "cloud",
383+
MinLength: 40,
384+
MaxLength: 40,
385+
KeywordMatches: []string{"netlify"},
386+
},
387+
378388
// Payment services
379389
"paypal_client_id": {
380390
Regex: `(?i)(?:paypal|braintree).{0,20}(?:[:=]\s*)['"]([A-Za-z0-9_-]{20,64})['"]`,

core/scanner/local_scanner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func (s *LocalScanner) processFile(filePath string) (int, error) {
244244
return 0, nil
245245
}
246246

247-
if fi.Size() > s.config.MaxFileSize {
247+
if s.config.MaxFileSize > 0 && fi.Size() > s.config.MaxFileSize {
248248
s.incrementSkippedFiles()
249249
if !s.config.Silent {
250250
s.logger.Debug("Skipping large file: %s (%d bytes)", filePath, fi.Size())

0 commit comments

Comments
 (0)