Skip to content

Commit

Permalink
Ensure Headless protocol accesses flow protocol variables
Browse files Browse the repository at this point in the history
  • Loading branch information
dogancanbakir committed Jan 24, 2025
1 parent a0c3075 commit c5c1800
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pkg/protocols/headless/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ func (request *Request) ExecuteWithResults(input *contextargs.Context, metadata,
}

vars := protocolutils.GenerateVariablesWithContextArgs(input, false)
payloads := generators.BuildPayloadFromOptions(request.options.Options)
optionVars := generators.BuildPayloadFromOptions(request.options.Options)
// add templatecontext variables to varMap
values := generators.MergeMaps(vars, metadata, payloads)
if request.options.HasTemplateCtx(input.MetaInput) {
values = generators.MergeMaps(values, request.options.GetTemplateCtx(input.MetaInput).GetAll())
vars = generators.MergeMaps(vars, metadata, optionVars, request.options.GetTemplateCtx(input.MetaInput).GetAll())
}
variablesMap := request.options.Variables.Evaluate(values)
payloads = generators.MergeMaps(variablesMap, payloads, request.options.Constants)
variablesMap := request.options.Variables.Evaluate(vars)
vars = generators.MergeMaps(vars, variablesMap, request.options.Constants)

// check for operator matches by wrapping callback
gotmatches := false
Expand All @@ -71,7 +70,7 @@ func (request *Request) ExecuteWithResults(input *contextargs.Context, metadata,
}
// verify if fuzz elaboration was requested
if len(request.Fuzzing) > 0 {
return request.executeFuzzingRule(input, payloads, previous, wrappedCallback)
return request.executeFuzzingRule(input, vars, previous, wrappedCallback)
}
if request.generator != nil {
iterator := request.generator.NewIterator()
Expand All @@ -83,13 +82,13 @@ func (request *Request) ExecuteWithResults(input *contextargs.Context, metadata,
if gotmatches && (request.StopAtFirstMatch || request.options.Options.StopAtFirstMatch || request.options.StopAtFirstMatch) {
return nil
}
value = generators.MergeMaps(value, payloads)
value = generators.MergeMaps(value, vars)
if err := request.executeRequestWithPayloads(input, value, previous, wrappedCallback); err != nil {
return err
}
}
} else {
value := maps.Clone(payloads)
value := maps.Clone(vars)
if err := request.executeRequestWithPayloads(input, value, previous, wrappedCallback); err != nil {
return err
}
Expand Down

0 comments on commit c5c1800

Please sign in to comment.