From 5c9c779e95752cd892b4d14f4dc641d57dd15b00 Mon Sep 17 00:00:00 2001 From: geeknik <466878+geeknik@users.noreply.github.com> Date: Tue, 11 Jun 2024 07:25:50 -0500 Subject: [PATCH] Update init.go - The Init function now validates the Timeout and JsConcurrency values, setting them to reasonable defaults if necessary. - Added logging statements to monitor and debug the initialization process. - Ensures that PoolingJsVmConcurrency is not set to a negative value, which can prevent potential issues. --- pkg/js/compiler/init.go | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/pkg/js/compiler/init.go b/pkg/js/compiler/init.go index 8a171dc3da..2db39ebd23 100644 --- a/pkg/js/compiler/init.go +++ b/pkg/js/compiler/init.go @@ -1,6 +1,7 @@ package compiler import ( + "log" "github.com/projectdiscovery/nuclei/v3/pkg/types" ) @@ -16,18 +17,31 @@ var ( // Init initializes the javascript protocol func Init(opts *types.Options) error { + // Validate the provided timeout if opts.Timeout < 10 { - // keep existing 10s timeout - return nil + log.Println("Provided timeout too low, using default 10s timeout") + opts.Timeout = 10 } + + // Validate the provided concurrency if opts.JsConcurrency < 100 { - // 100 is reasonable default + log.Println("Provided JS concurrency too low, setting to default 100") opts.JsConcurrency = 100 } - // we have dialer timeout set to 10s so js needs to be at least - // 15s to return the actual error if not it will be a dialer timeout + + // Calculate and set the JsProtocolTimeout JsProtocolTimeout = int(float64(opts.Timeout) * JsTimeoutMultiplier) - PoolingJsVmConcurrency = opts.JsConcurrency - PoolingJsVmConcurrency -= NonPoolingVMConcurrency + + // Adjust PoolingJsVmConcurrency based on NonPoolingVMConcurrency + PoolingJsVmConcurrency = opts.JsConcurrency - NonPoolingVMConcurrency + if PoolingJsVmConcurrency < 0 { + log.Println("Adjusted PoolingJsVmConcurrency to minimum value 0") + PoolingJsVmConcurrency = 0 + } + + log.Printf("JS Protocol Timeout set to %d seconds\n", JsProtocolTimeout) + log.Printf("Pooling JS VM Concurrency set to %d\n", PoolingJsVmConcurrency) + log.Printf("Non-Pooling JS VM Concurrency set to %d\n", NonPoolingVMConcurrency) + return nil }