[Bug]: set-headers policy accepts CR and LF in header values (Validate does not reject control characters)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 76/100
Línea de trabajo
La policy está en policies/set-headers/setheaders.go en wso2/gateway-controllers. Lee validateHeaderEntries y ejecuta la prueba de reproducción en policies/set-headers para confirmar el comportamiento actual. Añade una validación que rechace los caracteres de control especificados y una prueba unitaria que espere un error; el trabajo estará terminado cuando Validate rechace esos valores.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
The set-headers policy (wso2/gateway-controllers, policies/set-headers/setheaders.go, policy version v1.2.0) validates that each entry has non-empty name and string value, then lowercases the name and forwards the value unchanged into HeadersToSet / HeadersToAppend.
Unlike the documentation-driven Host checks discussed for host-rewrite, and unlike what #3902 asks for on respond, validateHeaderEntries never rejects carriage return, line feed, or other CTL characters in the value. RFC 9110 forbids CR and LF inside a field value. A configured value such as a\r\nX-Injected: yes passes Validate and is returned from parseHeaderEntries intact.
Depending on how the gateway applies UpstreamRequestHeaderModifications / DownstreamResponseHeaderModifications, that is the same header-injection shape as #3902 (respond) and the Host CRLF case in #3884. #3791 already notes that Envoy can reject some illegal values at request time with a 500; the policy layer still accepts them at configure / Validate time, so bad config is not caught where other header policies are being tightened.
Steps to Reproduce
On wso2/gateway-controllers main 4cf9570, under policies/set-headers:
func TestValidateAllowsCRLFInValue(t *testing.T) {
p := &SetHeadersPolicy{}
err := p.Validate(map[string]interface{}{
"request": map[string]interface{}{
"headers": []interface{}{
map[string]interface{}{"name": "x-a", "value": "ok\r\nX-Injected: yes"},
},
},
})
if err != nil {
t.Fatalf("expected accept today, got %v", err)
}
entries := p.parseHeaderEntries([]interface{}{
map[string]interface{}{"name": "x-a", "value": "ok\r\nX-Injected: yes"},
})
if entries[0].Value != "ok\r\nX-Injected: yes" {
t.Fatalf("value altered: %q", entries[0].Value)
}
}
go test -run TestValidateAllowsCRLFInValue -v .
Expected behavior
Validate returns an error for any header value that contains \r, \n, or other CTL characters (HTAB optional).
Actual behavior
Validate returns nil and parseHeaderEntries keeps the CRLF value.
Severity Level of the Issue
Severity/Minor (Non-critical functionality. Can be fixed in future releases)
Environment Details (with versions)
- wso2/gateway-controllers main
4cf9570(set-headers policy v1.2.0, sdk/core v0.2.15) - Go 1.26.x, Linux x86_64
Related Issues
- #3902 respond policy CRLF in header values (same class, different policy)
- #3884 host-rewrite Host CRLF / invalid characters
- #3791 GetParamsOfPolicy YAML injection into set-headers params (controller-side; suggests validating values after render, does not fix policy
Validate) - #3792 (PR) builds upstream auth set-headers params as a map; controller-side, does not touch
set-headersValidate
No open issue that set-headers.Validate itself accepts CR/LF in headers[].value.
Possible Solution
- In
validateHeaderEntries, reject values containing\r,\n, or\x00(allow HTAB if desired). - Add the unit test above expecting an error.
- Align with the respond / host-rewrite hardening so all header-writing policies share one rule.
if strings.ContainsAny(value, "\r\n\x00") {
return fmt.Errorf("%s[%d].value contains invalid control characters", fieldName, i)
}
I'm happy to send a PR.
- Lenguaje dominante
- Go
- Estrellas
- 79
- Forks
- 130
- Merge medio
- 1 d 15 h
- PR fusionados (30 d)
- 174
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de wso2/api-platform
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
wso2/api-platform#3968 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
wso2/api-platform#3964 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
wso2/api-platform#3963 ·
Los mantenedores suelen responder en 1 día
-
Area/Policies Aspect/Testing Type/Improvement
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
wso2/api-platform#3956 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
wso2/api-platform#3917 ·
Los mantenedores suelen responder en 1 día
Todos los issues de wso2/api-platform
Issues similares
-
ux
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
evcc-io/evcc#35605 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug report
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
type:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
nightgauge/nightgauge#2732 ·
Los mantenedores suelen responder en 1 día
-
fix below CVEsAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 5 días
-
good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100