Merge remote-tracking branch 'origin'

This commit is contained in:
PDTeamX 2025-08-23 20:03:41 +05:30
commit 5bff7a2a90
3 changed files with 60 additions and 24 deletions

View File

@ -31,7 +31,7 @@ const (
CLIConfigFileName = "config.yaml" CLIConfigFileName = "config.yaml"
ReportingConfigFilename = "reporting-config.yaml" ReportingConfigFilename = "reporting-config.yaml"
// Version is the current version of nuclei // Version is the current version of nuclei
Version = `v3.4.9` Version = `v3.4.10`
// Directory Names of custom templates // Directory Names of custom templates
CustomS3TemplatesDirName = "s3" CustomS3TemplatesDirName = "s3"
CustomGitHubTemplatesDirName = "github" CustomGitHubTemplatesDirName = "github"

View File

@ -447,21 +447,8 @@ func (e *ExecutorOptions) ApplyNewEngineOptions(n *ExecutorOptions) {
return return
} }
// The types.Options include the ExecutionID among other things
e.Options = n.Options.Copy() e.Options = n.Options.Copy()
// Keep the template-specific fields, but replace the rest
/*
e.TemplateID = n.TemplateID
e.TemplatePath = n.TemplatePath
e.TemplateInfo = n.TemplateInfo
e.TemplateVerifier = n.TemplateVerifier
e.RawTemplate = n.RawTemplate
e.Variables = n.Variables
e.Constants = n.Constants
*/
e.Output = n.Output e.Output = n.Output
e.Options = n.Options
e.IssuesClient = n.IssuesClient e.IssuesClient = n.IssuesClient
e.Progress = n.Progress e.Progress = n.Progress
e.RateLimiter = n.RateLimiter e.RateLimiter = n.RateLimiter
@ -470,8 +457,6 @@ func (e *ExecutorOptions) ApplyNewEngineOptions(n *ExecutorOptions) {
e.Browser = n.Browser e.Browser = n.Browser
e.Interactsh = n.Interactsh e.Interactsh = n.Interactsh
e.HostErrorsCache = n.HostErrorsCache e.HostErrorsCache = n.HostErrorsCache
e.StopAtFirstMatch = n.StopAtFirstMatch
e.ExcludeMatchers = n.ExcludeMatchers
e.InputHelper = n.InputHelper e.InputHelper = n.InputHelper
e.FuzzParamsFrequency = n.FuzzParamsFrequency e.FuzzParamsFrequency = n.FuzzParamsFrequency
e.FuzzStatsDB = n.FuzzStatsDB e.FuzzStatsDB = n.FuzzStatsDB
@ -479,10 +464,6 @@ func (e *ExecutorOptions) ApplyNewEngineOptions(n *ExecutorOptions) {
e.Colorizer = n.Colorizer e.Colorizer = n.Colorizer
e.WorkflowLoader = n.WorkflowLoader e.WorkflowLoader = n.WorkflowLoader
e.ResumeCfg = n.ResumeCfg e.ResumeCfg = n.ResumeCfg
e.ProtocolType = n.ProtocolType
e.Flow = n.Flow
e.IsMultiProtocol = n.IsMultiProtocol
e.templateCtxStore = n.templateCtxStore
e.JsCompiler = n.JsCompiler e.JsCompiler = n.JsCompiler
e.AuthProvider = n.AuthProvider e.AuthProvider = n.AuthProvider
e.TemporaryDirectory = n.TemporaryDirectory e.TemporaryDirectory = n.TemporaryDirectory

View File

@ -64,6 +64,13 @@ func Parse(filePath string, preprocessor Preprocessor, options *protocols.Execut
newBase.TemplateInfo = tplCopy.Options.TemplateInfo newBase.TemplateInfo = tplCopy.Options.TemplateInfo
newBase.TemplateVerifier = tplCopy.Options.TemplateVerifier newBase.TemplateVerifier = tplCopy.Options.TemplateVerifier
newBase.RawTemplate = tplCopy.Options.RawTemplate newBase.RawTemplate = tplCopy.Options.RawTemplate
if tplCopy.Options.Variables.Len() > 0 {
newBase.Variables = tplCopy.Options.Variables
}
if len(tplCopy.Options.Constants) > 0 {
newBase.Constants = tplCopy.Options.Constants
}
tplCopy.Options = newBase tplCopy.Options = newBase
tplCopy.Options.ApplyNewEngineOptions(options) tplCopy.Options.ApplyNewEngineOptions(options)
@ -156,13 +163,17 @@ func Parse(filePath string, preprocessor Preprocessor, options *protocols.Execut
// Compile the workflow request // Compile the workflow request
if len(template.Workflows) > 0 { if len(template.Workflows) > 0 {
compiled := &template.Workflow compiled := &template.Workflow
compileWorkflow(filePath, preprocessor, options, compiled, options.WorkflowLoader) compileWorkflow(filePath, preprocessor, tplCopy.Options, compiled, tplCopy.Options.WorkflowLoader)
template.CompiledWorkflow = compiled template.CompiledWorkflow = compiled
template.CompiledWorkflow.Options = options template.CompiledWorkflow.Options = tplCopy.Options
} }
if isCachedTemplateValid(template) {
// options.Logger.Error().Msgf("returning cached template %s after recompiling %d requests", tplCopy.Options.TemplateID, tplCopy.Requests()) // options.Logger.Error().Msgf("returning cached template %s after recompiling %d requests", tplCopy.Options.TemplateID, tplCopy.Requests())
return template, nil return template, nil
} }
// else: fallthrough to re-parse template from scratch
}
} }
var reader io.ReadCloser var reader io.ReadCloser
@ -579,6 +590,50 @@ func parseTemplate(data []byte, srcOptions *protocols.ExecutorOptions) (*Templat
return template, nil return template, nil
} }
// isCachedTemplateValid validates that a cached template is still usable after
// option updates
func isCachedTemplateValid(template *Template) bool {
// no requests or workflows
if template.Requests() == 0 && len(template.Workflows) == 0 {
return false
}
// options not initialized
if template.Options == nil {
return false
}
// executer not available for non-workflow template
if len(template.Workflows) == 0 && template.Executer == nil {
return false
}
// compiled workflow not available
if len(template.Workflows) > 0 && template.CompiledWorkflow == nil {
return false
}
// template ID mismatch
if template.Options.TemplateID != template.ID {
return false
}
// executer exists but no requests or flow available
if template.Executer != nil {
// NOTE(dwisiswant0): This is a basic sanity check since we can't access
// private fields, but we can check requests tho
if template.Requests() == 0 && template.Options.Flow == "" {
return false
}
}
if template.Options.Options == nil {
return false
}
return true
}
var ( var (
jsCompiler *compiler.Compiler jsCompiler *compiler.Compiler
jsCompilerOnce = sync.OnceFunc(func() { jsCompilerOnce = sync.OnceFunc(func() {