Advisory

GHSA-jr34-h97m-9hpx

Details, part 2 of 2. The advisory

Details

Interpretation:

| Request | Header bytes | Server time |
|------------------------------------------|--------------|-------------|
| no header / short tag | 0 - 5 | 3 - 11 ms |
| 1 MiB - separators (CVE-2022-32149 guard fires) | 1 MiB | 32 ms |
| 1 MiB _ separators (guard bypassed) | 1 MiB | 2.4 - 3.6 s |

The - control proves that the existing CVE-2022-32149 guard does still work on the canonical separator: a 1 MiB - payload returns in 32 ms because the parser short-circuits with ErrTagListTooLarge. The _ attack returns 404 (the same as the baseline) from the same endpoint but consumes ~2.4-3.6 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 ~75-110x (32 ms guard-fires vs 2.4-3.6 s attack on the same 1 MiB header).

Impact

  • One unauthenticated client can pin one CPU core for ~2.4 seconds per 1 MiB request to any URL (the middleware runs even on 404 paths).
  • Ten concurrent attackers using ~10 MiB/s of upstream bandwidth pin a 10-core nginx-ignition instance indefinitely.
  • The 4xx/5xx status of the eventual response does not matter — the middleware runs before route resolution, so the CPU cost is paid whether the URL exists or not.
  • Self-hosted nginx-ignition instances exposed to the public internet (a documented deployment pattern in the project's README) are exposed.

Suggested fix

Apply the size / character-class filter inside the middleware 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:

// api/common/server/i18n.go
const maxAcceptLanguageSeparators = 32 // real browsers send < 10

func i18nMiddleware(commands i18n.Commands) gin.HandlerFunc {
    return func(ginCtx *gin.Context) {
        lang := commands.DefaultLanguage()

        langHeader := ginCtx.GetHeader("Accept-Language")
        if strings.Count(langHeader, "-")+strings.Count(langHeader, "_") > maxAcceptLanguageSeparators {
            // Refuse to call into the BCP 47 parser with absurd input.
            langHeader = ""
        }
        tags, _, err := language.ParseAcceptLanguage(langHeader)
        if err == nil && len(tags) > 0 {
            for _, tag := range tags {
                if commands.Supports(tag) {
                    lang = tag
                    break
                }
            }
        }

        //nolint:staticcheck
        updatedCtx := context.WithValue(ginCtx.Request.Context(), i18n.ContextKey, lang)
        ginCtx.Request = ginCtx.Request.WithContext(updatedCtx)
        ginCtx.Set(i18n.ContextKey, lang)
        ginCtx.Next()
    }
}

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.

Sources & licences