projectdiscovery / nuclei

Nuclei is a fast, customizable vulnerability scanner powered by the global security community and built on a simple YAML-based DSL, enabling collaboration to tackle trending vulnerabilities on the internet. It helps you find vulnerabilities in your applications, APIs, networks, DNS, and cloud configurations.
https://docs.projectdiscovery.io/tools/nuclei
MIT License
20.59k stars 2.51k forks source link

Refactor and move all variables to ScanContext #4631

Open tarunKoyalwar opened 10 months ago

tarunKoyalwar commented 10 months ago

Proposed Change

In Nuclei , we use map data type to store all variables and different types of variables at that . and for every request we create new map by joining and evaluating them before and after every request (this causes lot of allocations and deallocations). having a centrailized VariableCluster makes it more strategic and easy to manage

// once created are not updated and remain throughout lifecycle of scan
type ReadOnlyVars map[string]any

type VarCluster struct {
    VariablesField map[string]any          // from `variables` field in template
    CustomVars     *CustomVars            // given from cli using -V
    InputVars      ReadOnlyVars           // input url based vars like Path etc (same for all requests in a template)
    Constants      ReadOnlyVars           // read only cannot be replaced
    ProtoVars      map[string]any // obtained after executing request or from extractors
}
tarunKoyalwar commented 8 months ago

During testing , it has come to attention that sometimes variables are being evaluated 2 times and if a variable contains a interactsh-url placeholder. then it's causing Correlation Id not found issue. A short term fix for this is to locate this but a long term a way better solution is to move all state to state.ScanContext