mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 22:25:27 +00:00
Fixed template validation edge cases (#2051)
This commit is contained in:
parent
77caa39161
commit
3648c47e35
@ -341,10 +341,9 @@ func (r *Runner) RunEnumeration() error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not load templates from config")
|
||||
}
|
||||
store.Load()
|
||||
|
||||
if r.options.Validate {
|
||||
if err := store.ValidateTemplates(r.options.Templates, r.options.Workflows); err != nil {
|
||||
if err := store.ValidateTemplates(); err != nil {
|
||||
return err
|
||||
}
|
||||
if stats.GetValue(parsers.SyntaxErrorStats) == 0 && stats.GetValue(parsers.SyntaxWarningStats) == 0 && stats.GetValue(parsers.RuntimeWarningsStats) == 0 {
|
||||
@ -354,6 +353,7 @@ func (r *Runner) RunEnumeration() error {
|
||||
}
|
||||
return nil // exit
|
||||
}
|
||||
store.Load()
|
||||
|
||||
r.displayExecutionInfo(store)
|
||||
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
package loader
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/projectdiscovery/gologger"
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/catalog"
|
||||
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/config"
|
||||
@ -119,11 +120,18 @@ func New(config *Config) (*Store, error) {
|
||||
store.finalWorkflows = append(store.finalWorkflows, remoteWorkflows...)
|
||||
}
|
||||
|
||||
// Handle a dot as the current working directory
|
||||
if len(store.finalTemplates) == 1 && store.finalTemplates[0] == "." {
|
||||
currentDirectory, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not get current directory")
|
||||
}
|
||||
store.finalTemplates = []string{currentDirectory}
|
||||
}
|
||||
// Handle a case with no templates or workflows, where we use base directory
|
||||
if len(store.finalTemplates) == 0 && len(store.finalWorkflows) == 0 && !urlBasedTemplatesProvided {
|
||||
store.finalTemplates = []string{config.TemplatesDirectory}
|
||||
}
|
||||
|
||||
return store, nil
|
||||
}
|
||||
|
||||
@ -157,13 +165,9 @@ func init() {
|
||||
|
||||
// ValidateTemplates takes a list of templates and validates them
|
||||
// erroring out on discovering any faulty templates.
|
||||
func (store *Store) ValidateTemplates(templatesList, workflowsList []string) error {
|
||||
// consider all the templates by default if no templates passed by user
|
||||
if len(templatesList) == 0 {
|
||||
templatesList = store.finalTemplates
|
||||
}
|
||||
templatePaths := store.config.Catalog.GetTemplatesPath(templatesList)
|
||||
workflowPaths := store.config.Catalog.GetTemplatesPath(workflowsList)
|
||||
func (store *Store) ValidateTemplates() error {
|
||||
templatePaths := store.config.Catalog.GetTemplatesPath(store.finalTemplates)
|
||||
workflowPaths := store.config.Catalog.GetTemplatesPath(store.finalWorkflows)
|
||||
|
||||
filteredTemplatePaths := store.pathFilter.Match(templatePaths)
|
||||
filteredWorkflowPaths := store.pathFilter.Match(workflowPaths)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user