-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation for GitLab personal access tokens
Add Secret validation #191
- Loading branch information
Baruch Odem
committed
Mar 26, 2024
1 parent
7a8a406
commit ae8bcbb
Showing
4 changed files
with
48 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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,21 @@ | ||
package validation | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
func sendValidationRequest(endpoint string, authorization string) (*http.Response, error) { | ||
req, err := http.NewRequest("GET", endpoint, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req.Header.Set("Authorization", authorization) | ||
|
||
client := &http.Client{} | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return resp, nil | ||
} |
This file contains 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 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,25 @@ | ||
package validation | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/checkmarx/2ms/lib/secrets" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
func validateGitlab(s *secrets.Secret) secrets.ValidationResult { | ||
const gitlabURL = "https://gitlab.com/api/v4/user" | ||
|
||
resp, err := sendValidationRequest(gitlabURL, fmt.Sprintf("Bearer %s", s.Value)) | ||
|
||
if err != nil { | ||
log.Warn().Err(err).Msg("Failed to validate secret") | ||
return secrets.UnknownResult | ||
} | ||
|
||
if resp.StatusCode == http.StatusOK { | ||
return secrets.ValidResult | ||
} | ||
return secrets.RevokedResult | ||
} |
This file contains 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