diff --git a/internal/runner/lazy.go b/internal/runner/lazy.go index 11ae2c69ec..7b8031ef59 100644 --- a/internal/runner/lazy.go +++ b/internal/runner/lazy.go @@ -67,7 +67,10 @@ func GetAuthTmplStore(opts *types.Options, catalog catalog.Catalog, execOpts *pr // GetLazyAuthFetchCallback returns a lazy fetch callback for auth secrets func GetLazyAuthFetchCallback(opts *AuthLazyFetchOptions) authx.LazyFetchSecret { return func(d *authx.Dynamic) error { - tmpls := opts.TemplateStore.LoadTemplates([]string{d.TemplatePath}) + tmpls, err := opts.TemplateStore.LoadTemplates([]string{d.TemplatePath}) + if err != nil { + return errkit.Wrap(err, "failed to load templates") + } if len(tmpls) == 0 { return fmt.Errorf("%w for path: %s", disk.ErrNoTemplatesFound, d.TemplatePath) } @@ -140,7 +143,7 @@ func GetLazyAuthFetchCallback(opts *AuthLazyFetchOptions) authx.LazyFetchSecret // log result of template in result file/screen _ = writer.WriteResult(e, opts.ExecOpts.Output, opts.ExecOpts.Progress, opts.ExecOpts.IssuesClient) } - _, err := tmpl.Executer.ExecuteWithResults(ctx) + _, err = tmpl.Executer.ExecuteWithResults(ctx) if err != nil { finalErr = err } diff --git a/pkg/catalog/loader/loader.go b/pkg/catalog/loader/loader.go index 19aa590970..d356c1eb1b 100644 --- a/pkg/catalog/loader/loader.go +++ b/pkg/catalog/loader/loader.go @@ -334,7 +334,7 @@ func (store *Store) RegisterPreprocessor(preprocessor templates.Preprocessor) { // Load loads all the templates from a store, performs filtering and returns // the complete compiled templates for a nuclei execution configuration. func (store *Store) Load() { - store.templates = store.LoadTemplates(store.finalTemplates) + store.templates, _ = store.LoadTemplates(store.finalTemplates) store.workflows = store.LoadWorkflows(store.finalWorkflows) } @@ -637,7 +637,7 @@ func isParsingError(store *Store, message string, template string, err error) bo } // LoadTemplates takes a list of templates and returns paths for them -func (store *Store) LoadTemplates(templatesList []string) []*templates.Template { +func (store *Store) LoadTemplates(templatesList []string) ([]*templates.Template, error) { return store.LoadTemplatesWithTags(templatesList, nil) } @@ -668,7 +668,8 @@ func (store *Store) LoadWorkflows(workflowsList []string) []*templates.Template // LoadTemplatesWithTags takes a list of templates and extra tags // returning templates that match. -func (store *Store) LoadTemplatesWithTags(templatesList, tags []string) []*templates.Template { +// Returns an error if dialers with the execution ID are not found. +func (store *Store) LoadTemplatesWithTags(templatesList, tags []string) ([]*templates.Template, error) { defer store.saveMetadataIndexOnce() indexFilter := store.indexFilter @@ -717,7 +718,7 @@ func (store *Store) LoadTemplatesWithTags(templatesList, tags []string) []*templ dialers := protocolstate.GetDialersWithId(typesOpts.ExecutionId) if dialers == nil { - panic("dialers with executionId " + typesOpts.ExecutionId + " not found") + return nil, fmt.Errorf("dialers with executionId %s not found", typesOpts.ExecutionId) } for _, templatePath := range includedTemplates { @@ -852,7 +853,7 @@ func (store *Store) LoadTemplatesWithTags(templatesList, tags []string) []*templ return loadedTemplates.Slice[i].Path < loadedTemplates.Slice[j].Path }) - return loadedTemplates.Slice + return loadedTemplates.Slice, nil } // IsHTTPBasedProtocolUsed returns true if http/headless protocol is being used for diff --git a/pkg/catalog/loader/loader_bench_test.go b/pkg/catalog/loader/loader_bench_test.go index 32ed506e8b..569a12dcba 100644 --- a/pkg/catalog/loader/loader_bench_test.go +++ b/pkg/catalog/loader/loader_bench_test.go @@ -71,7 +71,7 @@ func BenchmarkLoadTemplates(b *testing.B) { b.ReportAllocs() for b.Loop() { - _ = store.LoadTemplates([]string{config.DefaultConfig.TemplatesDirectory}) + _, _ = store.LoadTemplates([]string{config.DefaultConfig.TemplatesDirectory}) } }) @@ -89,7 +89,7 @@ func BenchmarkLoadTemplates(b *testing.B) { b.ReportAllocs() for b.Loop() { - _ = store.LoadTemplates([]string{config.DefaultConfig.TemplatesDirectory}) + _, _ = store.LoadTemplates([]string{config.DefaultConfig.TemplatesDirectory}) } }) @@ -107,7 +107,7 @@ func BenchmarkLoadTemplates(b *testing.B) { b.ReportAllocs() for b.Loop() { - _ = store.LoadTemplates([]string{config.DefaultConfig.TemplatesDirectory}) + _, _ = store.LoadTemplates([]string{config.DefaultConfig.TemplatesDirectory}) } }) @@ -125,7 +125,7 @@ func BenchmarkLoadTemplates(b *testing.B) { b.ReportAllocs() for b.Loop() { - _ = store.LoadTemplates([]string{config.DefaultConfig.TemplatesDirectory}) + _, _ = store.LoadTemplates([]string{config.DefaultConfig.TemplatesDirectory}) } }) @@ -143,7 +143,7 @@ func BenchmarkLoadTemplates(b *testing.B) { b.ReportAllocs() for b.Loop() { - _ = store.LoadTemplates([]string{config.DefaultConfig.TemplatesDirectory}) + _, _ = store.LoadTemplates([]string{config.DefaultConfig.TemplatesDirectory}) } }) @@ -161,7 +161,7 @@ func BenchmarkLoadTemplates(b *testing.B) { b.ReportAllocs() for b.Loop() { - _ = store.LoadTemplates([]string{config.DefaultConfig.TemplatesDirectory}) + _, _ = store.LoadTemplates([]string{config.DefaultConfig.TemplatesDirectory}) } }) @@ -181,7 +181,7 @@ func BenchmarkLoadTemplates(b *testing.B) { b.ReportAllocs() for b.Loop() { - _ = store.LoadTemplates([]string{config.DefaultConfig.TemplatesDirectory}) + _, _ = store.LoadTemplates([]string{config.DefaultConfig.TemplatesDirectory}) } }) } diff --git a/pkg/protocols/common/automaticscan/util.go b/pkg/protocols/common/automaticscan/util.go index 528b39049f..510743c6f4 100644 --- a/pkg/protocols/common/automaticscan/util.go +++ b/pkg/protocols/common/automaticscan/util.go @@ -37,7 +37,10 @@ func getTemplateDirs(opts Options) ([]string, error) { // LoadTemplatesWithTags loads and returns templates with given tags func LoadTemplatesWithTags(opts Options, templateDirs []string, tags []string, logInfo bool) ([]*templates.Template, error) { - finalTemplates := opts.Store.LoadTemplatesWithTags(templateDirs, tags) + finalTemplates, err := opts.Store.LoadTemplatesWithTags(templateDirs, tags) + if err != nil { + return nil, errors.Wrap(err, "could not load templates") + } if len(finalTemplates) == 0 { return nil, errors.New("could not find any templates with tech tag") }