From 09893539d2097e7a2099880c9ab4ccab38b54410 Mon Sep 17 00:00:00 2001 From: Sajad Parra Date: Fri, 14 Jan 2022 16:27:54 +0530 Subject: [PATCH 1/2] update validation logic to validate workflow templates and subtemplates --- v2/pkg/catalog/loader/loader.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/v2/pkg/catalog/loader/loader.go b/v2/pkg/catalog/loader/loader.go index b4eec967..dbff056f 100644 --- a/v2/pkg/catalog/loader/loader.go +++ b/v2/pkg/catalog/loader/loader.go @@ -13,6 +13,7 @@ import ( templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types" "github.com/projectdiscovery/nuclei/v2/pkg/types" "github.com/projectdiscovery/nuclei/v2/pkg/utils/stats" + "github.com/projectdiscovery/nuclei/v2/pkg/workflows" ) // Config contains the configuration options for the loader @@ -196,6 +197,30 @@ func areWorkflowOrTemplatesValid(store *Store, filteredTemplatePaths map[string] return true } } + if isWorkflow { + if !areWorkflowTemplatesValid(store, template.Workflows) { + areTemplatesValid = false + continue + } + } + } + return areTemplatesValid +} + +func areWorkflowTemplatesValid(store *Store, workflows []*workflows.WorkflowTemplate) bool { + areTemplatesValid := true + for _, workflow := range workflows { + if !areWorkflowTemplatesValid(store, workflow.Subtemplates) { + areTemplatesValid = false + continue + } + _, err := store.config.Catalog.GetTemplatePath(workflow.Template) + if err != nil { + if isParsingError("Error occurred loading template %s: %s\n", workflow.Template, err) { + areTemplatesValid = false + continue + } + } } return areTemplatesValid } From 7af556c36cdd8294ab7fa4ca19ba5bc4d90f9b96 Mon Sep 17 00:00:00 2001 From: Sajad Parra Date: Tue, 18 Jan 2022 14:44:58 +0530 Subject: [PATCH 2/2] return validation result instead of continue in the loop --- v2/pkg/catalog/loader/loader.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/v2/pkg/catalog/loader/loader.go b/v2/pkg/catalog/loader/loader.go index dbff056f..2276445d 100644 --- a/v2/pkg/catalog/loader/loader.go +++ b/v2/pkg/catalog/loader/loader.go @@ -208,21 +208,18 @@ func areWorkflowOrTemplatesValid(store *Store, filteredTemplatePaths map[string] } func areWorkflowTemplatesValid(store *Store, workflows []*workflows.WorkflowTemplate) bool { - areTemplatesValid := true for _, workflow := range workflows { if !areWorkflowTemplatesValid(store, workflow.Subtemplates) { - areTemplatesValid = false - continue + return false } _, err := store.config.Catalog.GetTemplatePath(workflow.Template) if err != nil { if isParsingError("Error occurred loading template %s: %s\n", workflow.Template, err) { - areTemplatesValid = false - continue + return false } } } - return areTemplatesValid + return true } func isParsingError(message string, template string, err error) bool {