-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add healthcheck endpoints discovery scan
- Loading branch information
1 parent
ca2e1fb
commit a6c61b8
Showing
7 changed files
with
106 additions
and
4 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
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,36 @@ | ||
package healthcheck | ||
|
||
import ( | ||
"github.com/cerberauth/vulnapi/internal/auth" | ||
"github.com/cerberauth/vulnapi/internal/operation" | ||
"github.com/cerberauth/vulnapi/report" | ||
"github.com/cerberauth/vulnapi/scan/discover" | ||
) | ||
|
||
const ( | ||
DiscoverableHealthCheckScanID = "discover.healthcheck" | ||
DiscoverableHealthCheckScanName = "Discoverable healthcheck endpoint" | ||
) | ||
|
||
var issue = report.Issue{ | ||
ID: "discover.discoverable_healthcheck", | ||
Name: "Discoverable healthcheck endpoint", | ||
|
||
Classifications: &report.Classifications{ | ||
OWASP: report.OWASP_2023_SSRF, | ||
}, | ||
|
||
CVSS: report.CVSS{ | ||
Version: 4.0, | ||
Vector: "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:N/SC:N/SI:N/SA:N", | ||
Score: 0, | ||
}, | ||
} | ||
|
||
var healthcheckSeclistUrl = "https://raw.githubusercontent.com/cerberauth/vulnapi/main/seclist/lists/healthcheck.txt" | ||
|
||
func ScanHandler(op *operation.Operation, securityScheme *auth.SecurityScheme) (*report.ScanReport, error) { | ||
vulnReport := report.NewIssueReport(issue).WithOperation(op).WithSecurityScheme(securityScheme) | ||
r := report.NewScanReport(DiscoverableHealthCheckScanID, DiscoverableHealthCheckScanName, op) | ||
return discover.DownloadAndScanURLs("HealthCheck", healthcheckSeclistUrl, r, vulnReport, op, securityScheme) | ||
} |
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,50 @@ | ||
package healthcheck_test | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/cerberauth/vulnapi/internal/auth" | ||
"github.com/cerberauth/vulnapi/internal/operation" | ||
"github.com/cerberauth/vulnapi/internal/request" | ||
"github.com/cerberauth/vulnapi/scan/discover/healthcheck" | ||
"github.com/jarcoal/httpmock" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDiscoverableScanner_Passed_WhenNoDiscoverableHealthCheckEndpointFound(t *testing.T) { | ||
client := request.NewClient(request.NewClientOptions{ | ||
RateLimit: 500, | ||
}) | ||
httpmock.ActivateNonDefault(client.Client) | ||
defer httpmock.DeactivateAndReset() | ||
|
||
op := operation.MustNewOperation(http.MethodGet, "http://localhost:8080/", nil, client) | ||
httpmock.RegisterResponder(op.Method, op.URL.String(), httpmock.NewBytesResponder(http.StatusNoContent, nil)) | ||
httpmock.RegisterNoResponder(httpmock.NewBytesResponder(http.StatusNotFound, nil)) | ||
|
||
report, err := healthcheck.ScanHandler(op, auth.MustNewNoAuthSecurityScheme()) | ||
|
||
require.NoError(t, err) | ||
assert.Greater(t, httpmock.GetTotalCallCount(), 5) | ||
assert.True(t, report.Issues[0].HasPassed()) | ||
} | ||
|
||
func TestDiscoverableScanner_Failed_WhenOneHealthCheckEndpointFound(t *testing.T) { | ||
client := request.NewClient(request.NewClientOptions{ | ||
RateLimit: 500, | ||
}) | ||
httpmock.ActivateNonDefault(client.Client) | ||
defer httpmock.DeactivateAndReset() | ||
|
||
operation := operation.MustNewOperation(http.MethodGet, "http://localhost:8080/healthz", nil, client) | ||
httpmock.RegisterResponder(operation.Method, operation.URL.String(), httpmock.NewBytesResponder(http.StatusOK, nil)) | ||
httpmock.RegisterNoResponder(httpmock.NewBytesResponder(http.StatusNotFound, nil)) | ||
|
||
report, err := healthcheck.ScanHandler(operation, auth.MustNewNoAuthSecurityScheme()) | ||
|
||
require.NoError(t, err) | ||
assert.Greater(t, httpmock.GetTotalCallCount(), 0) | ||
assert.True(t, report.Issues[0].HasFailed()) | ||
} |
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
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,12 @@ | ||
alive | ||
health | ||
health/live | ||
health/ready | ||
health/started | ||
healthz | ||
healthz/live | ||
healthz/ready | ||
ready | ||
status | ||
status/live | ||
status/ready |
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