Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[Bug]: set-headers policy accepts CR and LF in header values (Validate does not reject control characters)

Abierto Apto para principiantes
#3,909 0 comentarios 0 reacciones 0 asignados Ver en GitHub

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
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
api, security

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

Aspect/API Severity/Minor
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-headers Validate

No open issue that set-headers.Validate itself accepts CR/LF in headers[].value.

Possible Solution
  1. In validateHeaderEntries, reject values containing \r, \n, or \x00 (allow HTAB if desired).
  2. Add the unit test above expecting an error.
  3. 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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de wso2/api-platform

Todos los issues de wso2/api-platform

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.