Path: blob/dev/pkg/protocols/headless/engine/action.go
2072 views
package engine12import (3"strings"45"github.com/invopop/jsonschema"6)78// Action is an action taken by the browser to reach a navigation9//10// Each step that the browser executes is an action. Most navigations11// usually start from the ActionLoadURL event, and further navigations12// are discovered on the found page. We also keep track and only13// scrape new navigation from pages we haven't crawled yet.14type Action struct {15// description:16// Args contain arguments for the headless action.17//18// Per action arguments are described in detail [here](https://nuclei.projectdiscovery.io/templating-guide/protocols/headless/).19Data map[string]string `yaml:"args,omitempty" json:"args,omitempty" jsonschema:"title=arguments for headless action,description=Args contain arguments for the headless action"`20// description: |21// Name is the name assigned to the headless action.22//23// This can be used to execute code, for instance in browser24// DOM using script action, and get the result in a variable25// which can be matched upon by nuclei. An Example template [here](https://github.com/projectdiscovery/nuclei-templates/blob/main/headless/prototype-pollution-check.yaml).26Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"title=name for headless action,description=Name is the name assigned to the headless action"`27// description: |28// Description is the optional description of the headless action29Description string `yaml:"description,omitempty" json:"description,omitempty" jsonschema:"title=description for headless action,description=Description of the headless action"`30// description: |31// Action is the type of the action to perform.32ActionType 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"`33}3435func (a Action) JSONSchemaExtend(schema *jsonschema.Schema) {36argsSchema, ok := schema.Properties.Get("args")37if !ok {38return39}40argsSchema.PatternProperties = map[string]*jsonschema.Schema{41".*": {42OneOf: []*jsonschema.Schema{43{44Type: "string",45},46{47Type: "integer",48},49{50Type: "boolean",51},52},53},54}55argsSchema.Ref = ""56}5758// String returns the string representation of an action59func (a *Action) String() string {60builder := &strings.Builder{}61builder.WriteString(a.ActionType.String())62if a.Name != "" {63builder.WriteString(" Name:")64builder.WriteString(a.Name)65}66builder.WriteString(" ")67for k, v := range a.Data {68builder.WriteString(k)69builder.WriteString(":")70builder.WriteString(v)71builder.WriteString(",")72}73return strings.TrimSuffix(builder.String(), ",")74}7576// GetArg returns an arg for a name77func (a *Action) GetArg(name string) string {78v, ok := a.Data[name]79if !ok {80return ""81}82return v83}848586