mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2026-02-01 00:03:15 +08:00
refactor(runner): adjust max-host-error if gt concurrency (#5633)
* refactor(common): use `ParseRequestURI` instead when `NormalizeCacheValue` also it exports the method Signed-off-by: Dwi Siswanto <git@dw1.io> * refactor(runner): adjust `max-host-error` if gt `concurrency` Signed-off-by: Dwi Siswanto <git@dw1.io> * fix lint * chore(runner): expose adjusted `max-host-error` value Signed-off-by: Dwi Siswanto <git@dw1.io> --------- Signed-off-by: Dwi Siswanto <git@dw1.io> Co-authored-by: Doğan Can Bakır <dogancanbakir@protonmail.com>
This commit is contained in:
@@ -75,24 +75,34 @@ func (c *Cache) Close() {
|
||||
c.failedTargets.Purge()
|
||||
}
|
||||
|
||||
func (c *Cache) normalizeCacheValue(value string) string {
|
||||
finalValue := value
|
||||
if strings.HasPrefix(value, "http") {
|
||||
if parsed, err := url.Parse(value); err == nil {
|
||||
hostname := parsed.Host
|
||||
finalPort := parsed.Port()
|
||||
if finalPort == "" {
|
||||
if parsed.Scheme == "https" {
|
||||
finalPort = "443"
|
||||
} else {
|
||||
finalPort = "80"
|
||||
}
|
||||
hostname = net.JoinHostPort(parsed.Host, finalPort)
|
||||
// NormalizeCacheValue processes the input value and returns a normalized cache
|
||||
// value.
|
||||
func (c *Cache) NormalizeCacheValue(value string) string {
|
||||
var normalizedValue string = value
|
||||
|
||||
u, err := url.ParseRequestURI(value)
|
||||
if err != nil || u.Host == "" {
|
||||
u, err2 := url.ParseRequestURI("https://" + value)
|
||||
if err2 != nil {
|
||||
return normalizedValue
|
||||
}
|
||||
|
||||
normalizedValue = u.Host
|
||||
} else {
|
||||
port := u.Port()
|
||||
if port == "" {
|
||||
switch u.Scheme {
|
||||
case "https":
|
||||
normalizedValue = net.JoinHostPort(u.Host, "443")
|
||||
case "http":
|
||||
normalizedValue = net.JoinHostPort(u.Host, "80")
|
||||
}
|
||||
finalValue = hostname
|
||||
} else {
|
||||
normalizedValue = u.Host
|
||||
}
|
||||
}
|
||||
return finalValue
|
||||
|
||||
return normalizedValue
|
||||
}
|
||||
|
||||
// ErrUnresponsiveHost is returned when a host is unresponsive
|
||||
@@ -166,7 +176,7 @@ func (c *Cache) GetKeyFromContext(ctx *contextargs.Context, err error) string {
|
||||
address = tmp.String()
|
||||
}
|
||||
}
|
||||
finalValue := c.normalizeCacheValue(address)
|
||||
finalValue := c.NormalizeCacheValue(address)
|
||||
return finalValue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user