Skip to content

Commit

Permalink
feat: add user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelgautier committed Oct 10, 2023
1 parent 54daba2 commit 8f94bba
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
17 changes: 12 additions & 5 deletions internal/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@ package request

import (
"fmt"
"io"
"net/http"
)

func SendRequestWithBearerAuth(url string, token string) (int, error) {
func SendRequestWithBearerAuth(url string, token string) (int, []byte, error) {
client := &http.Client{}

req, err := http.NewRequest("GET", url, nil)
if err != nil {
return 0, err
return 0, nil, err
}

req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
req.Header.Set("User-Agent", "vulnapi/0.1")

resp, err := client.Do(req)
if err != nil {
return 0, err
return 0, nil, err
}
defer resp.Body.Close()

return resp.StatusCode, nil
body, err := io.ReadAll(resp.Body)
if err != nil {
return 0, nil, err
}

return resp.StatusCode, body, nil
}
2 changes: 1 addition & 1 deletion scan/alg_none_jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func AlgNoneJwtScanHandler(url string, token string) []error {
return []error{err}
}

statusCode, err := request.SendRequestWithBearerAuth(url, newToken)
statusCode, _, err := request.SendRequestWithBearerAuth(url, newToken)
if err != nil {
return []error{err}
}
Expand Down
2 changes: 1 addition & 1 deletion scan/not_verified_jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func NotVerifiedJwtScanHandler(url string, token string) []error {
return []error{err}
}

statusCode, err := request.SendRequestWithBearerAuth(url, newToken)
statusCode, _, err := request.SendRequestWithBearerAuth(url, newToken)
if err != nil {
return []error{err}
}
Expand Down
2 changes: 1 addition & 1 deletion scan/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *Scan) ValidateRequest() error {
return errors.New("no valid JWT provided")
}

statusCode, err := request.SendRequestWithBearerAuth(s.Url, *s.ValidJwt)
statusCode, _, err := request.SendRequestWithBearerAuth(s.Url, *s.ValidJwt)
if err != nil {
return fmt.Errorf("request with url %s has an unexpected error", err)
}
Expand Down

0 comments on commit 8f94bba

Please sign in to comment.