Details
Captured run output (Apple M1 Pro, darwin/arm64 host, daptin amd64 binary v0.12.15 running under Docker Desktop with QEMU x86_64 emulation):
E2E: golang/x/text ParseAcceptLanguage '_' bypass through
daptin/daptin v0.12.15 LanguageMiddleware at
server/language.go.
Target: http://127.0.0.1:18888/ payload=262144 B
warm-up header=0 B '_'=0 '-'=0 status=200 t=19.968ms
--- measurements (single request each) ---
baseline (no header) header=0 B '_'=0 '-'=0 status=200 t=25.924208ms
baseline (1 short tag) header=5 B '_'=0 '-'=1 status=200 t=28.398333ms
guard-fires control ('-' x 256KiB) header=262142 B '_'=0 '-'=26214 status=200 t=105.506458ms
attack ('_' x 256KiB) header=262142 B '_'=26214 '-'=0 status=200 t=26.679448875s
attack repeat 2 header=262142 B '_'=26214 '-'=0 status=200 t=18.012964208s
attack repeat 3 header=262142 B '_'=26214 '-'=0 status=200 t=8.868606042s
A separate run with a 1 MiB payload exceeded the 2-minute client timeout on the attack request, confirming that the cost scales beyond 120 s per request at 1 MiB.
Interpretation:
| Request | Header bytes | Server time |
|------------------------------------------|--------------|-------------|
| no header / short tag | 0 - 5 | 26 - 28 ms |
| 256 KiB - separators (CVE-2022-32149 guard fires) | 256 KiB | 106 ms |
| 256 KiB _ separators (guard bypassed) | 256 KiB | 9 - 27 s |
| 1 MiB _ separators (guard bypassed) | 1 MiB | > 120 s |
The - control proves that the existing CVE-2022-32149 guard does still work on the canonical separator: a 256 KiB - payload returns in 106 ms because the parser short-circuits with ErrTagListTooLarge. The _ attack returns 200 from the same endpoint but consumes 9-27 s of server CPU because the guard did not fire and the quadratic scanner ran to completion. The amplification factor at the application boundary is ~85-250x on the 256 KiB payload and >1000x on a 1 MiB payload.
The amplification is higher than other consumers of ParseAcceptLanguage because Daptin formats the entire input into a log line via resource.CheckErr(err, "Failed to parse Accept-Language header [%v]", preferredLanguage) when parsing fails, and runs additional bookkeeping in GetLanguagePreference (a prefMap deduplication loop over the resulting tag slice).
Impact
- One unauthenticated client can pin one CPU core for ~9-27 seconds per 256 KiB request, or for at least 120 seconds per 1 MiB request.
- A single attacker on a 1 Mbit/s uplink can sustain ~1 attack request every 30 seconds, pinning one server core continuously with one TCP connection.
- A small number of concurrent attackers using ~10 MiB/s of upstream bandwidth pin a 10-core Daptin instance indefinitely.
- The endpoint returns 200 OK, so the attack does not surface as abnormal traffic in standard 4xx/5xx dashboards.
Suggested fix
Apply the size / character-class filter inside LanguageMiddleware (and inside GetLanguagePreference for defence in depth) before reaching language.ParseAcceptLanguage. The smallest change that preserves the existing behaviour for legitimate Accept-Language headers is to count _ alongside - and short-circuit when the total exceeds a small ceiling:
// server/language.go
const maxAcceptLanguageSeparators = 32 // real browsers send < 10
func (lm *LanguageMiddleware) LanguageMiddlewareFunc(c *gin.Context) {
header := c.GetHeader("Accept-Language")
if strings.Count(header, "-")+strings.Count(header, "_") > maxAcceptLanguageSeparators {
// Refuse to call into the BCP 47 parser with absurd input.
header = ""
}
pref := GetLanguagePreference(header, lm.defaultLanguage)
c.Request = c.Request.WithContext(context.WithValue(c.Request.Context(), "language_preference", pref))
}
A real Accept-Language header from a browser contains under 10 separators, so a ceiling of 32 leaves plenty of headroom while making the quadratic blow-up impossible.
The underlying issue is in golang.org/x/text/language. A future upstream fix is the right long-term solution; the change above is defensive-in-depth at the middleware that consumes attacker input.
Credit
Reported by tonghuaroot.
Fix PR
https://github.com/daptin/daptin-ghsa-rhj7-vh3v-mcq6/pull/1
Maintainer fix status
Fixed on master in commit 2d709509 Harden Accept-Language parsing.
The fix caps combined - and _ separators in Accept-Language before calling language.ParseAcceptLanguage, both in LanguageMiddlewareFunc and in GetLanguagePreference for defence in depth. Regression coverage was added in server/language_test.go for normal browser headers, a 256 KiB underscore-separated malformed header, and combined separator counting.
Verification run:
go test ./server -count=1
Result: passed.