diff --git a/internal/request/request.go b/internal/request/request.go index 83f1830..eb5ab86 100644 --- a/internal/request/request.go +++ b/internal/request/request.go @@ -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 } diff --git a/scan/alg_none_jwt.go b/scan/alg_none_jwt.go index 0d9e5c0..5e5ce7d 100644 --- a/scan/alg_none_jwt.go +++ b/scan/alg_none_jwt.go @@ -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} } diff --git a/scan/not_verified_jwt.go b/scan/not_verified_jwt.go index 95e2111..baa294f 100644 --- a/scan/not_verified_jwt.go +++ b/scan/not_verified_jwt.go @@ -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} } diff --git a/scan/scan.go b/scan/scan.go index 2542f2b..0cd20ba 100644 --- a/scan/scan.go +++ b/scan/scan.go @@ -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) }