Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#3,909 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
api, security

Direzione di ricerca

La policy si trova in policies/set-headers/setheaders.go in wso2/gateway-controllers. Leggi validateHeaderEntries ed esegui il test di riproduzione in policies/set-headers per confermare il comportamento attuale. Aggiungi una validazione che rifiuti i caratteri di controllo specificati e un test unitario che si aspetti un errore; il lavoro è concluso quando Validate rifiuta quei valori.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Go
Stelle
79
Fork
130
Merge medio
2g 2h
PR unite (30g)
157

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di wso2/api-platform

Tutte le issue di wso2/api-platform

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.