mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 13:55:24 +00:00
* Refactored header-based auth scans not to normalize the header names. * Removed the header validation as it's not really useful here. * adding docs --------- Co-authored-by: Mzack9999 <mzack9999@protonmail.com>
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package authx
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/projectdiscovery/retryablehttp-go"
|
|
)
|
|
|
|
var (
|
|
_ AuthStrategy = &HeadersAuthStrategy{}
|
|
)
|
|
|
|
// HeadersAuthStrategy is a strategy for headers auth
|
|
type HeadersAuthStrategy struct {
|
|
Data *Secret
|
|
}
|
|
|
|
// NewHeadersAuthStrategy creates a new headers auth strategy
|
|
func NewHeadersAuthStrategy(data *Secret) *HeadersAuthStrategy {
|
|
return &HeadersAuthStrategy{Data: data}
|
|
}
|
|
|
|
// Apply applies the headers auth strategy to the request
|
|
// NOTE: This preserves exact header casing (e.g., barAuthToken stays as barAuthToken)
|
|
// This is useful for APIs that require case-sensitive header names
|
|
func (s *HeadersAuthStrategy) Apply(req *http.Request) {
|
|
for _, header := range s.Data.Headers {
|
|
req.Header[header.Key] = []string{header.Value}
|
|
}
|
|
}
|
|
|
|
// ApplyOnRR applies the headers auth strategy to the retryable request
|
|
// NOTE: This preserves exact header casing (e.g., barAuthToken stays as barAuthToken)
|
|
// This is useful for APIs that require case-sensitive header names
|
|
func (s *HeadersAuthStrategy) ApplyOnRR(req *retryablehttp.Request) {
|
|
for _, header := range s.Data.Headers {
|
|
req.Header[header.Key] = []string{header.Value}
|
|
}
|
|
}
|