Merge pull request #1489 from projectdiscovery/workflow-validation-fix

update validation logic to validate workflow templates and subtemplates
dev
Sandeep Singh 2022-01-18 21:26:17 +05:30 committed by GitHub
commit eb6a1b263d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import (
templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types" templateTypes "github.com/projectdiscovery/nuclei/v2/pkg/templates/types"
"github.com/projectdiscovery/nuclei/v2/pkg/types" "github.com/projectdiscovery/nuclei/v2/pkg/types"
"github.com/projectdiscovery/nuclei/v2/pkg/utils/stats" "github.com/projectdiscovery/nuclei/v2/pkg/utils/stats"
"github.com/projectdiscovery/nuclei/v2/pkg/workflows"
) )
// Config contains the configuration options for the loader // Config contains the configuration options for the loader
@ -196,10 +197,31 @@ func areWorkflowOrTemplatesValid(store *Store, filteredTemplatePaths map[string]
return true return true
} }
} }
if isWorkflow {
if !areWorkflowTemplatesValid(store, template.Workflows) {
areTemplatesValid = false
continue
}
}
} }
return areTemplatesValid return areTemplatesValid
} }
func areWorkflowTemplatesValid(store *Store, workflows []*workflows.WorkflowTemplate) bool {
for _, workflow := range workflows {
if !areWorkflowTemplatesValid(store, workflow.Subtemplates) {
return false
}
_, err := store.config.Catalog.GetTemplatePath(workflow.Template)
if err != nil {
if isParsingError("Error occurred loading template %s: %s\n", workflow.Template, err) {
return false
}
}
}
return true
}
func isParsingError(message string, template string, err error) bool { func isParsingError(message string, template string, err error) bool {
if err == templates.ErrCreateTemplateExecutor { if err == templates.ErrCreateTemplateExecutor {
return false return false