Minder engine is susceptible to a denial of service from memory exhaustion that can be triggered from maliciously created templates.
Minder engine uses templating to generate strings for various use cases such as URLs, messages for pull requests, descriptions for advisories. In some cases can the user control both the template and the params for it, and in a subset of these cases, Minder reads the generated template entirely into memory. When Minders templating meets both of these conditions, an attacker is able to generate large enough templates that Minder will exhaust memory and crash.
One of these places is the REST ingester:
|
endpoint := new(bytes.Buffer) |
|
retp := &EndpointTemplateParams{ |
|
Entity: ent, |
|
Params: params, |
|
} |
|
|
|
if err := rdi.endpointTemplate.Execute(endpoint, retp); err != nil { |
|
return nil, fmt.Errorf("cannot execute endpoint template: %w", err) |
|
} |
With control over both endpoint and retp
on the following line:
|
if err := rdi.endpointTemplate.Execute(endpoint, retp); err != nil { |
… an attacker can make Minder generate a large template that Minder reads into memory on the following line by invoking endpoint.String()
:
|
req, err := rdi.cli.NewRequest(rdi.method, endpoint.String(), bodyr) |
Consider this example:
package main
import (
"fmt"
"html/template"
"os"
)
type EndpointTemplateParams struct {
// Params are the parameters to be used in the template
Params map[string]any
}
func main() {
retp := &EndpointTemplateParams{
Params: map[string]any{
"params": make([]string, 10),
},
}
fmt.Println(retp)
const templ = `
{{range $idx, $e := .Params.params}}
loooooooooooooooooooooooooooooooong-string-{{$idx}}
{{end}}
{{range $idx, $e := .Params.params}}
loooooooooooooooooooooooooooooooong-string-{{$idx}}
{{end}}
{{range $idx, $e := .Params.params}}
loooooooooooooooooooooooooooooooong-string-{{$idx}}
{{end}}`
tmpl := template.Must(template.New("").Parse(templ))
if err := tmpl.Execute(os.Stdout, retp); err != nil {
panic(err)
}
}
This example imitates the behavior on these lines:
|
endpoint := new(bytes.Buffer) |
|
retp := &EndpointTemplateParams{ |
|
Entity: ent, |
|
Params: params, |
|
} |
|
|
|
if err := rdi.endpointTemplate.Execute(endpoint, retp); err != nil { |
|
return nil, fmt.Errorf("cannot execute endpoint template: %w", err) |
|
} |
Running this example generates the following template:
loooooooooooooooooooooooooooooooong-string-0
loooooooooooooooooooooooooooooooong-string-1
loooooooooooooooooooooooooooooooong-string-2
loooooooooooooooooooooooooooooooong-string-3
loooooooooooooooooooooooooooooooong-string-4
loooooooooooooooooooooooooooooooong-string-5
loooooooooooooooooooooooooooooooong-string-6
loooooooooooooooooooooooooooooooong-string-7
loooooooooooooooooooooooooooooooong-string-8
loooooooooooooooooooooooooooooooong-string-9
loooooooooooooooooooooooooooooooong-string-0
loooooooooooooooooooooooooooooooong-string-1
loooooooooooooooooooooooooooooooong-string-2
loooooooooooooooooooooooooooooooong-string-3
loooooooooooooooooooooooooooooooong-string-4
loooooooooooooooooooooooooooooooong-string-5
loooooooooooooooooooooooooooooooong-string-6
loooooooooooooooooooooooooooooooong-string-7
loooooooooooooooooooooooooooooooong-string-8
loooooooooooooooooooooooooooooooong-string-9
loooooooooooooooooooooooooooooooong-string-0
loooooooooooooooooooooooooooooooong-string-1
loooooooooooooooooooooooooooooooong-string-2
loooooooooooooooooooooooooooooooong-string-3
loooooooooooooooooooooooooooooooong-string-4
loooooooooooooooooooooooooooooooong-string-5
loooooooooooooooooooooooooooooooong-string-6
loooooooooooooooooooooooooooooooong-string-7
loooooooooooooooooooooooooooooooong-string-8
loooooooooooooooooooooooooooooooong-string-9
A malicious user can call the loop more times, increase the loop count and/or make the repeated long string longer to make the size of the template bigger.
A sufficiently large template will consume a lot of memory on this line which will exhaust memory on the machine and crash the Minder server:
|
if err := rdi.endpointTemplate.Execute(endpoint, retp); err != nil { |
Minder should enforce a limit to generated templates before reading them into memory.
We believe the following templates are vulnerable:
|
if err := rdi.endpointTemplate.Execute(endpoint, retp); err != nil { |
|
if err := r.titleTemplate.Execute(title, tmplParams); err != nil { |
|
if err := r.bodyTemplate.Execute(body, tmplParams); err != nil { |
Minder has a few other templates especially in its engine which needs reviewing too. As a default, all templates should be limited in size before Minder reads them into memory.
Minder engine is susceptible to a denial of service from memory exhaustion that can be triggered from maliciously created templates.
Minder engine uses templating to generate strings for various use cases such as URLs, messages for pull requests, descriptions for advisories. In some cases can the user control both the template and the params for it, and in a subset of these cases, Minder reads the generated template entirely into memory. When Minders templating meets both of these conditions, an attacker is able to generate large enough templates that Minder will exhaust memory and crash.
One of these places is the REST ingester:
minder/internal/engine/ingester/rest/rest.go
Lines 115 to 123 in daccbc1
With control over both endpoint and
retp
on the following line:minder/internal/engine/ingester/rest/rest.go
Line 121 in daccbc1
… an attacker can make Minder generate a large template that Minder reads into memory on the following line by invoking
endpoint.String()
:minder/internal/engine/ingester/rest/rest.go
Line 131 in daccbc1
Consider this example:
This example imitates the behavior on these lines:
minder/internal/engine/ingester/rest/rest.go
Lines 115 to 123 in daccbc1
Running this example generates the following template:
A malicious user can call the loop more times, increase the loop count and/or make the repeated long string longer to make the size of the template bigger.
A sufficiently large template will consume a lot of memory on this line which will exhaust memory on the machine and crash the Minder server:
minder/internal/engine/ingester/rest/rest.go
Line 121 in daccbc1
Minder should enforce a limit to generated templates before reading them into memory.
We believe the following templates are vulnerable:
minder/internal/engine/ingester/rest/rest.go
Line 121 in daccbc1
minder/internal/engine/actions/remediate/pull_request/pull_request.go
Line 199 in e7f9914
minder/internal/engine/actions/remediate/pull_request/pull_request.go
Line 510 in e7f9914
Minder has a few other templates especially in its engine which needs reviewing too. As a default, all templates should be limited in size before Minder reads them into memory.