github.com/projectdiscovery/nuclei/v2@v2.9.15/pkg/protocols/headless/engine/action.go (about)

     1  package engine
     2  
     3  import "strings"
     4  
     5  // Action is an action taken by the browser to reach a navigation
     6  //
     7  // Each step that the browser executes is an action. Most navigations
     8  // usually start from the ActionLoadURL event, and further navigations
     9  // are discovered on the found page. We also keep track and only
    10  // scrape new navigation from pages we haven't crawled yet.
    11  type Action struct {
    12  	// description:
    13  	//   Args contain arguments for the headless action.
    14  	//
    15  	//   Per action arguments are described in detail [here](https://nuclei.projectdiscovery.io/templating-guide/protocols/headless/).
    16  	Data map[string]string `yaml:"args,omitempty" json:"args,omitempty" jsonschema:"title=arguments for headless action,description=Args contain arguments for the headless action"`
    17  	// description: |
    18  	//   Name is the name assigned to the headless action.
    19  	//
    20  	//   This can be used to execute code, for instance in browser
    21  	//   DOM using script action, and get the result in a variable
    22  	//   which can be matched upon by nuclei. An Example template [here](https://github.com/projectdiscovery/nuclei-templates/blob/main/headless/prototype-pollution-check.yaml).
    23  	Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"title=name for headless action,description=Name is the name assigned to the headless action"`
    24  	// description: |
    25  	//   Description is the optional description of the headless action
    26  	Description string `yaml:"description,omitempty" json:"description,omitempty" jsonschema:"title=description for headless action,description=Description of the headless action"`
    27  	// description: |
    28  	//   Action is the type of the action to perform.
    29  	ActionType ActionTypeHolder `yaml:"action" json:"action" jsonschema:"title=action to perform,description=Type of actions to perform,enum=navigate,enum=script,enum=click,enum=rightclick,enum=text,enum=screenshot,enum=time,enum=select,enum=files,enum=waitload,enum=getresource,enum=extract,enum=setmethod,enum=addheader,enum=setheader,enum=deleteheader,enum=setbody,enum=waitevent,enum=keyboard,enum=debug,enum=sleep"`
    30  }
    31  
    32  // String returns the string representation of an action
    33  func (a *Action) String() string {
    34  	builder := &strings.Builder{}
    35  	builder.WriteString(a.ActionType.String())
    36  	if a.Name != "" {
    37  		builder.WriteString(" Name:")
    38  		builder.WriteString(a.Name)
    39  	}
    40  	builder.WriteString(" ")
    41  	for k, v := range a.Data {
    42  		builder.WriteString(k)
    43  		builder.WriteString(":")
    44  		builder.WriteString(v)
    45  		builder.WriteString(",")
    46  	}
    47  	return strings.TrimSuffix(builder.String(), ",")
    48  }
    49  
    50  // GetArg returns an arg for a name
    51  func (a *Action) GetArg(name string) string {
    52  	v, ok := a.Data[name]
    53  	if !ok {
    54  		return ""
    55  	}
    56  	return v
    57  }