Path: blob/dev/pkg/protocols/common/generators/options.go
2846 views
package generators12import (3"sync"45"github.com/projectdiscovery/nuclei/v3/pkg/types"6)78// optionsPayloadMap caches the result of BuildPayloadFromOptions per options9// pointer. This supports multiple SDK instances with different options running10// concurrently.11var optionsPayloadMap sync.Map // map[*types.Options]map[string]interface{}1213// BuildPayloadFromOptions returns a map with the payloads provided via CLI.14//15// The result is cached per options pointer since options don't change during a run.16// Returns a copy of the cached map to prevent concurrent modification issues.17// Safe for concurrent use with multiple SDK instances.18func BuildPayloadFromOptions(options *types.Options) map[string]interface{} {19if options == nil {20return make(map[string]interface{})21}2223if cached, ok := optionsPayloadMap.Load(options); ok {24return CopyMap(cached.(map[string]interface{}))25}2627m := make(map[string]interface{})2829// merge with vars30if !options.Vars.IsEmpty() {31m = MergeMaps(m, options.Vars.AsMap())32}3334// merge with env vars35if options.EnvironmentVariables {36m = MergeMaps(EnvVars(), m)37}3839actual, _ := optionsPayloadMap.LoadOrStore(options, m)4041// Return a copy to prevent concurrent writes to the cached map42return CopyMap(actual.(map[string]interface{}))43}4445// ClearOptionsPayloadMap clears the cached options payload.46// SDK users should call this when disposing of a NucleiEngine instance47// to prevent memory leaks if creating many short-lived instances.48func ClearOptionsPayloadMap(options *types.Options) {49if options != nil {50optionsPayloadMap.Delete(options)51}52}535455