mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 20:05:27 +00:00
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package authx
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/projectdiscovery/retryablehttp-go"
|
|
)
|
|
|
|
var (
|
|
_ AuthStrategy = &CookiesAuthStrategy{}
|
|
)
|
|
|
|
// CookiesAuthStrategy is a strategy for cookies auth
|
|
type CookiesAuthStrategy struct {
|
|
Data *Secret
|
|
}
|
|
|
|
// NewCookiesAuthStrategy creates a new cookies auth strategy
|
|
func NewCookiesAuthStrategy(data *Secret) *CookiesAuthStrategy {
|
|
return &CookiesAuthStrategy{Data: data}
|
|
}
|
|
|
|
// Apply applies the cookies auth strategy to the request
|
|
func (s *CookiesAuthStrategy) Apply(req *http.Request) {
|
|
for _, cookie := range s.Data.Cookies {
|
|
c := &http.Cookie{
|
|
Name: cookie.Key,
|
|
Value: cookie.Value,
|
|
}
|
|
req.AddCookie(c)
|
|
}
|
|
}
|
|
|
|
// ApplyOnRR applies the cookies auth strategy to the retryable request
|
|
func (s *CookiesAuthStrategy) ApplyOnRR(req *retryablehttp.Request) {
|
|
// Before adding new cookies, remove existing cookies
|
|
req.Header.Del("Cookie")
|
|
|
|
for _, cookie := range s.Data.Cookies {
|
|
c := &http.Cookie{
|
|
Name: cookie.Key,
|
|
Value: cookie.Value,
|
|
}
|
|
req.AddCookie(c)
|
|
}
|
|
}
|