mirror of
https://github.com/lunchcat/sif.git
synced 2026-06-12 19:11:25 -07:00
fix: error patterns and string building in sif.go and js/scan.go
replace errors.new(fmt.sprintf()) with fmt.errorf, use strings.builder instead of string concatenation in loop, fix defer in loop issue, preallocate slices where size is estimable
This commit is contained in:
+8
-8
@@ -14,7 +14,6 @@ package js
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -44,17 +43,17 @@ func JavascriptScan(url string, timeout time.Duration, threads int, logdir strin
|
||||
}
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var html string
|
||||
var sb strings.Builder
|
||||
scanner := bufio.NewScanner(resp.Body)
|
||||
scanner.Split(bufio.ScanLines)
|
||||
for scanner.Scan() {
|
||||
html += scanner.Text()
|
||||
sb.WriteString(scanner.Text())
|
||||
}
|
||||
html := sb.String()
|
||||
|
||||
doc, err := htmlquery.Parse(strings.NewReader(html))
|
||||
if err != nil {
|
||||
@@ -99,19 +98,20 @@ func JavascriptScan(url string, timeout time.Duration, threads int, logdir strin
|
||||
|
||||
jslog.Infof("Got %d scripts, now running scans on them", len(scripts))
|
||||
|
||||
var supabaseResults []supabaseScanResult
|
||||
supabaseResults := make([]supabaseScanResult, 0, len(scripts))
|
||||
for _, script := range scripts {
|
||||
jslog.Infof("Scanning %s", script)
|
||||
resp, err := http.Get(script)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
jslog.Warnf("Failed to fetch script: %s", err)
|
||||
continue
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
jslog.Errorf("Failed to read script body: %s", err)
|
||||
continue
|
||||
}
|
||||
content := string(bodyBytes)
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package sif
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -81,7 +80,7 @@ func New(settings *config.Settings) (*App, error) {
|
||||
app.targets = append(app.targets, scanner.Text())
|
||||
}
|
||||
} else {
|
||||
return app, errors.New("target(s) must be supplied with -u or -f\n\nSee 'sif -h' for more information")
|
||||
return app, fmt.Errorf("target(s) must be supplied with -u or -f\n\nSee 'sif -h' for more information")
|
||||
}
|
||||
|
||||
return app, nil
|
||||
@@ -105,16 +104,16 @@ func (app *App) Run() error {
|
||||
defer logger.Close()
|
||||
}
|
||||
|
||||
scansRun := []string{}
|
||||
scansRun := make([]string, 0, 16)
|
||||
|
||||
for _, url := range app.targets {
|
||||
if !strings.Contains(url, "://") {
|
||||
return errors.New(fmt.Sprintf("URL %s must include leading protocol", url))
|
||||
return fmt.Errorf("URL %s must include leading protocol", url)
|
||||
}
|
||||
|
||||
log.Infof("📡Starting scan on %s...", url)
|
||||
|
||||
moduleResults := []ModuleResult{}
|
||||
moduleResults := make([]ModuleResult, 0, 16)
|
||||
|
||||
if app.settings.LogDir != "" {
|
||||
if err := logger.CreateFile(&app.logFiles, url, app.settings.LogDir); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user