From 5e84d3d877498ccb291842faeb3f154df998abc7 Mon Sep 17 00:00:00 2001 From: Darion Date: Thu, 14 Sep 2023 13:08:43 -0400 Subject: [PATCH] added the option to disable following redirects (#588) --- cmd/katana/main.go | 1 + pkg/engine/common/http.go | 3 +++ pkg/types/options.go | 2 ++ 3 files changed, 6 insertions(+) diff --git a/cmd/katana/main.go b/cmd/katana/main.go index 79b9f21b..0490d553 100644 --- a/cmd/katana/main.go +++ b/cmd/katana/main.go @@ -105,6 +105,7 @@ pipelines offering both headless and non-headless crawling.`) flagSet.StringVarP(&options.Strategy, "strategy", "s", "depth-first", "Visit strategy (depth-first, breadth-first)"), flagSet.BoolVarP(&options.IgnoreQueryParams, "ignore-query-params", "iqp", false, "Ignore crawling same path with different query-param values"), flagSet.BoolVarP(&options.TlsImpersonate, "tls-impersonate", "tlsi", false, "enable experimental client hello (ja3) tls randomization"), + flagSet.BoolVarP(&options.DisableRedirects, "disable-redirects", "dr", false, "disable following redirects (default false)"), ) flagSet.CreateGroup("debug", "Debug", diff --git a/pkg/engine/common/http.go b/pkg/engine/common/http.go index 90d8dd5a..87b25ddc 100644 --- a/pkg/engine/common/http.go +++ b/pkg/engine/common/http.go @@ -54,6 +54,9 @@ func BuildHttpClient(dialer *fastdialer.Dialer, options *types.Options, redirect Transport: transport, Timeout: time.Duration(options.Timeout) * time.Second, CheckRedirect: func(req *http.Request, via []*http.Request) error { + if options.DisableRedirects { + return http.ErrUseLastResponse + } if len(via) == 10 { return errorutil.New("stopped after 10 redirects") } diff --git a/pkg/types/options.go b/pkg/types/options.go index 9b7705ad..5e4b8607 100644 --- a/pkg/types/options.go +++ b/pkg/types/options.go @@ -144,6 +144,8 @@ type Options struct { Debug bool // TlsImpersonate enables experimental tls ClientHello randomization for standard crawler TlsImpersonate bool + //DisableRedirects disables the following of redirects + DisableRedirects bool } func (options *Options) ParseCustomHeaders() map[string]string {