-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add secret file authentication support (-sf flag) #2371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b60bfa2
feat: add secret file authentication support (-sf flag)
dogancanbakir 62eed15
fix: address CodeRabbitAI review comments
dogancanbakir a780d05
test: add comprehensive tests for auth provider
dogancanbakir a4ae407
lint
Mzack9999 fb1ea1c
Merge branch 'dev' into feature/secret-file-auth
Mzack9999 c125352
mod tidy
Mzack9999 93633d2
docs: add secret file authentication documentation
dogancanbakir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package authx | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/projectdiscovery/retryablehttp-go" | ||
| ) | ||
|
|
||
| var ( | ||
| _ AuthStrategy = &BasicAuthStrategy{} | ||
| ) | ||
|
|
||
| // BasicAuthStrategy is a strategy for basic auth | ||
| type BasicAuthStrategy struct { | ||
| Data *Secret | ||
| } | ||
|
|
||
| // NewBasicAuthStrategy creates a new basic auth strategy | ||
| func NewBasicAuthStrategy(data *Secret) *BasicAuthStrategy { | ||
| return &BasicAuthStrategy{Data: data} | ||
| } | ||
|
|
||
| // Apply applies the basic auth strategy to the request | ||
| func (s *BasicAuthStrategy) Apply(req *http.Request) { | ||
| req.SetBasicAuth(s.Data.Username, s.Data.Password) | ||
| } | ||
|
|
||
| // ApplyOnRR applies the basic auth strategy to the retryable request | ||
| func (s *BasicAuthStrategy) ApplyOnRR(req *retryablehttp.Request) { | ||
| req.SetBasicAuth(s.Data.Username, s.Data.Password) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package authx | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/projectdiscovery/retryablehttp-go" | ||
| ) | ||
|
|
||
| var ( | ||
| _ AuthStrategy = &BearerTokenAuthStrategy{} | ||
| ) | ||
|
|
||
| // BearerTokenAuthStrategy is a strategy for bearer token auth | ||
| type BearerTokenAuthStrategy struct { | ||
| Data *Secret | ||
| } | ||
|
|
||
| // NewBearerTokenAuthStrategy creates a new bearer token auth strategy | ||
| func NewBearerTokenAuthStrategy(data *Secret) *BearerTokenAuthStrategy { | ||
| return &BearerTokenAuthStrategy{Data: data} | ||
| } | ||
|
|
||
| // Apply applies the bearer token auth strategy to the request | ||
| func (s *BearerTokenAuthStrategy) Apply(req *http.Request) { | ||
| req.Header.Set("Authorization", "Bearer "+s.Data.Token) | ||
| } | ||
|
|
||
| // ApplyOnRR applies the bearer token auth strategy to the retryable request | ||
| func (s *BearerTokenAuthStrategy) ApplyOnRR(req *retryablehttp.Request) { | ||
| req.Header.Set("Authorization", "Bearer "+s.Data.Token) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| 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 { | ||
| req.AddCookie(&http.Cookie{ | ||
| Name: cookie.Key, | ||
| Value: cookie.Value, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // ApplyOnRR applies the cookies auth strategy to the retryable request | ||
| func (s *CookiesAuthStrategy) ApplyOnRR(req *retryablehttp.Request) { | ||
| // Build a set of cookie names to replace | ||
| newCookieNames := make(map[string]struct{}, len(s.Data.Cookies)) | ||
| for _, cookie := range s.Data.Cookies { | ||
| newCookieNames[cookie.Key] = struct{}{} | ||
| } | ||
|
|
||
| // Filter existing cookies, keeping only those not being replaced | ||
| existingCookies := req.Cookies() | ||
| filteredCookies := make([]*http.Cookie, 0, len(existingCookies)) | ||
| for _, cookie := range existingCookies { | ||
| if _, shouldReplace := newCookieNames[cookie.Name]; !shouldReplace { | ||
| filteredCookies = append(filteredCookies, cookie) | ||
| } | ||
| } | ||
|
|
||
| // Clear and reset cookies | ||
| req.Header.Del("Cookie") | ||
| for _, cookie := range filteredCookies { | ||
| req.AddCookie(cookie) | ||
| } | ||
| // Add new cookies | ||
| for _, cookie := range s.Data.Cookies { | ||
| req.AddCookie(&http.Cookie{ | ||
| Name: cookie.Key, | ||
| Value: cookie.Value, | ||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.