-
Notifications
You must be signed in to change notification settings - Fork 795
Add comprehensive URL depth filtering system #1353 #1444
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -37,6 +37,8 @@ type CrawlerOptions struct { | |||||||||||||||||||||||||
Dialer *fastdialer.Dialer | ||||||||||||||||||||||||||
// Wappalyzer instance for technologies detection | ||||||||||||||||||||||||||
Wappalyzer *wappalyzer.Wappalyze | ||||||||||||||||||||||||||
// DepthValidator is a validator for URL depth filtering | ||||||||||||||||||||||||||
DepthValidator *filters.DepthFilterValidator | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// NewCrawlerOptions creates a new crawler options structure | ||||||||||||||||||||||||||
|
@@ -94,6 +96,10 @@ func NewCrawlerOptions(options *Options) (*CrawlerOptions, error) { | |||||||||||||||||||||||||
OutputTemplate: options.OutputTemplate, | ||||||||||||||||||||||||||
OutputMatchCondition: options.OutputMatchCondition, | ||||||||||||||||||||||||||
OutputFilterCondition: options.OutputFilterCondition, | ||||||||||||||||||||||||||
CountPathDepth: options.CountPathDepth, | ||||||||||||||||||||||||||
CountQueryParams: options.CountQueryParams, | ||||||||||||||||||||||||||
CountSubdomainDepth: options.CountSubdomainDepth, | ||||||||||||||||||||||||||
DepthFilterOrLogic: options.DepthFilterOrLogic, | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
for _, mr := range options.OutputMatchRegex { | ||||||||||||||||||||||||||
|
@@ -116,6 +122,20 @@ func NewCrawlerOptions(options *Options) (*CrawlerOptions, error) { | |||||||||||||||||||||||||
return nil, errorutil.NewWithErr(err).Msgf("could not create output writer") | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// Initialize depth filter validator if depth filters are configured | ||||||||||||||||||||||||||
var depthValidator *filters.DepthFilterValidator | ||||||||||||||||||||||||||
if len(options.CountPathDepth) > 0 || len(options.CountQueryParams) > 0 || len(options.CountSubdomainDepth) > 0 { | ||||||||||||||||||||||||||
depthValidator, err = filters.NewDepthFilterValidator( | ||||||||||||||||||||||||||
options.CountPathDepth, | ||||||||||||||||||||||||||
options.CountQueryParams, | ||||||||||||||||||||||||||
options.CountSubdomainDepth, | ||||||||||||||||||||||||||
options.DepthFilterOrLogic, | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
Comment on lines
+128
to
+133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also convert goflags.StringSlice when constructing the validator filters.NewDepthFilterValidator takes []string slices; pass converted values. - depthValidator, err = filters.NewDepthFilterValidator(
- options.CountPathDepth,
- options.CountQueryParams,
- options.CountSubdomainDepth,
- options.DepthFilterOrLogic,
- )
+ depthValidator, err = filters.NewDepthFilterValidator(
+ []string(options.CountPathDepth),
+ []string(options.CountQueryParams),
+ []string(options.CountSubdomainDepth),
+ options.DepthFilterOrLogic,
+ ) 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
return nil, errorutil.NewWithErr(err).Msgf("could not create depth filter validator") | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
crawlerOptions := &CrawlerOptions{ | ||||||||||||||||||||||||||
ExtensionsValidator: extensionsValidator, | ||||||||||||||||||||||||||
Parser: responseParser, | ||||||||||||||||||||||||||
|
@@ -124,6 +144,7 @@ func NewCrawlerOptions(options *Options) (*CrawlerOptions, error) { | |||||||||||||||||||||||||
Options: options, | ||||||||||||||||||||||||||
Dialer: fastdialerInstance, | ||||||||||||||||||||||||||
OutputWriter: outputWriter, | ||||||||||||||||||||||||||
DepthValidator: depthValidator, | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if options.RateLimit > 0 { | ||||||||||||||||||||||||||
|
@@ -150,9 +171,16 @@ func (c *CrawlerOptions) Close() error { | |||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func (c *CrawlerOptions) ValidatePath(path string) bool { | ||||||||||||||||||||||||||
// First check extension validation | ||||||||||||||||||||||||||
if c.ExtensionsValidator != nil { | ||||||||||||||||||||||||||
return c.ExtensionsValidator.ValidatePath(path) | ||||||||||||||||||||||||||
if !c.ExtensionsValidator.ValidatePath(path) { | ||||||||||||||||||||||||||
return false | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// Note: Depth validation is handled at output stage to allow crawling | ||||||||||||||||||||||||||
// but filter final results. This ensures we can discover URLs first. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return true | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compile-time type mismatch: convert goflags.StringSlice to []string
output.Options fields are []string, while options.Count* are goflags.StringSlice. Add explicit conversions to avoid build errors.
📝 Committable suggestion
🤖 Prompt for AI Agents