Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions pkg/protocols/headless/engine/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ import (

// Page is a single page in an isolated browser instance
type Page struct {
ctx *contextargs.Context
inputURL *urlutil.URL
options *Options
page *rod.Page
rules []rule
instance *Instance
hijackRouter *rod.HijackRouter
hijackNative *Hijack
mutex *sync.RWMutex
History []HistoryData
InteractshURLs []string
payloads map[string]interface{}
variables map[string]interface{}
ctx *contextargs.Context
inputURL *urlutil.URL
options *Options
page *rod.Page
rules []rule
instance *Instance
hijackRouter *rod.HijackRouter
hijackNative *Hijack
mutex *sync.RWMutex
History []HistoryData
InteractshURLs []string
payloads map[string]interface{}
variables map[string]interface{}
lastActionNavigate *Action
}

// HistoryData contains the page request/response pairs
Expand Down Expand Up @@ -274,6 +275,17 @@ func (p *Page) hasModificationRules() bool {
return false
}

// updateLastNavigatedURL updates the last navigated URL in the instance's
// request log.
func (p *Page) updateLastNavigatedURL() {
if p.lastActionNavigate == nil {
return
}

templateURL := p.lastActionNavigate.GetArg("url")
p.instance.requestLog[templateURL] = p.URL()
}

func containsModificationActions(actions ...*Action) bool {
for _, action := range actions {
if containsAnyModificationActionType(action.ActionType.ActionType) {
Expand Down
21 changes: 17 additions & 4 deletions pkg/protocols/headless/engine/page_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
// ExecuteActions executes a list of actions on a page.
func (p *Page) ExecuteActions(input *contextargs.Context, actions []*Action) (outData ActionData, err error) {
outData = make(ActionData)

// waitFuncs are function that needs to be executed after navigation
// typically used for waitEvent
waitFuncs := make([]func() error, 0)
Expand Down Expand Up @@ -76,6 +77,8 @@ func (p *Page) ExecuteActions(input *contextargs.Context, actions []*Action) (ou
}
}
}

p.lastActionNavigate = act
}
case ActionScript:
err = p.RunScript(act, outData)
Expand Down Expand Up @@ -407,12 +410,12 @@ func (p *Page) NavigateURL(action *Action, out ActionData) error {
finalparams.Merge(p.inputURL.Params.Encode())
parsedURL.Params = finalparams

// log all navigated requests
p.instance.requestLog[action.GetArg("url")] = parsedURL.String()

if err := p.page.Navigate(parsedURL.String()); err != nil {
return errorutil.NewWithErr(err).Msgf("could not navigate to url %s", parsedURL.String())
}

p.updateLastNavigatedURL()

return nil
}

Expand Down Expand Up @@ -667,6 +670,9 @@ func (p *Page) WaitPageLifecycleEvent(act *Action, out ActionData, event proto.P

fn()

// log the navigated request (even if it is a redirect)
p.updateLastNavigatedURL()

return nil
}

Expand All @@ -687,7 +693,14 @@ func (p *Page) WaitStable(act *Action, out ActionData) error {
}
}

return p.page.Timeout(timeout).WaitStable(dur)
if err := p.page.Timeout(timeout).WaitStable(dur); err != nil {
return err
}

// log the navigated request (even if it is a redirect)
p.updateLastNavigatedURL()

return nil
}

// GetResource gets a resource from an element from page.
Expand Down
11 changes: 4 additions & 7 deletions pkg/protocols/headless/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package headless

import (
"fmt"
"maps"
"net/url"
"strings"
"time"

"github.com/projectdiscovery/retryablehttp-go"

"github.com/pkg/errors"
"golang.org/x/exp/maps"

"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/nuclei/v3/pkg/fuzz"
Expand Down Expand Up @@ -189,12 +189,9 @@ func (request *Request) executeRequestWithPayloads(input *contextargs.Context, p
if request.options.HasTemplateCtx(input.MetaInput) {
outputEvent = generators.MergeMaps(outputEvent, request.options.GetTemplateCtx(input.MetaInput).GetAll())
}
for k, v := range out {
outputEvent[k] = v
}
for k, v := range payloads {
outputEvent[k] = v
}

maps.Copy(outputEvent, out)
maps.Copy(outputEvent, payloads)

var event *output.InternalWrappedEvent
if len(page.InteractshURLs) == 0 {
Expand Down
Loading