Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip scope validation for initial host #858

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions pkg/engine/common/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (s *Shared) NewCrawlSessionWithURL(URL string) (*CrawlSession, error) {
cancel()
return nil, err
}
queue.Push(&navigation.Request{Method: http.MethodGet, URL: URL, Depth: 0}, 0)
queue.Push(&navigation.Request{Method: http.MethodGet, URL: URL, Depth: 0, SkipValidation: true}, 0)

if s.KnownFiles != nil {
navigationRequests, err := s.KnownFiles.Request(URL)
Expand Down Expand Up @@ -205,7 +205,12 @@ func (s *Shared) Do(crawlSession *CrawlSession, doRequest DoRequestFunc) error {
continue
}

if ok, err := s.Options.ValidateScope(req.URL, crawlSession.Hostname); err != nil || !ok {
inScope, scopeErr := s.Options.ValidateScope(req.URL, crawlSession.Hostname)
if scopeErr != nil {
gologger.Debug().Msgf("Error validating scope for `%v`: %v. skipping", req.URL, scopeErr)
continue
}
if !req.SkipValidation && !inScope {
gologger.Debug().Msgf("`%v` not in scope. skipping", req.URL)
continue
}
Expand All @@ -224,7 +229,9 @@ func (s *Shared) Do(crawlSession *CrawlSession, doRequest DoRequestFunc) error {

resp, err := doRequest(crawlSession, req)

s.Output(req, resp, nil, err)
if inScope {
s.Output(req, resp, nil, err)
}

if err != nil {
gologger.Warning().Msgf("Could not request seed URL %s: %s\n", req.URL, err)
Expand Down
23 changes: 12 additions & 11 deletions pkg/navigation/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ type Depth struct{}

// Request is a navigation request for the crawler
type Request struct {
Method string `json:"method,omitempty"`
URL string `json:"endpoint,omitempty"`
Body string `json:"body,omitempty"`
Depth int `json:"-"`
Headers map[string]string `json:"headers,omitempty"`
Tag string `json:"tag,omitempty"`
Attribute string `json:"attribute,omitempty"`
RootHostname string `json:"-"`
Source string `json:"source,omitempty"`
CustomFields map[string][]string `json:"-"`
Raw string `json:"raw,omitempty"`
Method string `json:"method,omitempty"`
URL string `json:"endpoint,omitempty"`
Body string `json:"body,omitempty"`
Depth int `json:"-"`
SkipValidation bool `json:"-"`
Headers map[string]string `json:"headers,omitempty"`
Tag string `json:"tag,omitempty"`
Attribute string `json:"attribute,omitempty"`
RootHostname string `json:"-"`
Source string `json:"source,omitempty"`
CustomFields map[string][]string `json:"-"`
Raw string `json:"raw,omitempty"`
}

// RequestURL returns the request URL for the navigation
Expand Down