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

[Bug]: basic-auth policy rejects valid credentials when the Authorization scheme is not spelled exactly "Basic"

Aperta Adatta ai principianti
#3,882 1 commento 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
70/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go

Direzione di ricerca

Il codice interessato si trova in policies/basic-auth/basicauth.go in wso2/gateway-controllers; l’issue menziona anche l’helper di test esistente policies/basic-auth e gli esempi di confronto nelle policy JWT e dei token opachi. Leggi l’analisi dell’header Basic-Auth ed esegui la riproduzione fornita TestZZScheme. Il lavoro è completato quando tutti e quattro gli header Authorization equivalenti autenticano correttamente e i test delle policy passano.

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

Descrizione

Aspect/API Severity/Minor Type/Bug
Please select the area the issue is related to

Gateway

Please select the aspect the issue is related to

Aspect/API (API backends, definitions, contracts, interfaces, OpenAPI)

Description

The basic-auth policy (wso2/gateway-controllers, policies/basic-auth/basicauth.go, policy version v1.0.3) checks the scheme with a case-sensitive prefix match:

if !strings.HasPrefix(authHeader, "Basic ") {
    return p.handleAuthFailureHeaders(...)
}
encodedCredentials := strings.TrimPrefix(authHeader, "Basic ")

RFC 9110 section 11.1 says the authentication scheme is a case-insensitive token, and that the credentials may follow after one or more spaces (credentials = auth-scheme [ 1*SP ( token68 / #auth-param ) ]). As a result:

  • A client that sends basic <base64> or BASIC <base64> with the correct username and password gets 401 Unauthorized. Some HTTP libraries, hand-written scripts and older devices send the scheme in lower case.
  • A client that puts two spaces after the scheme also gets 401 Unauthorized.

The JWT and opaque-token policies in the same repository already compare the scheme case-insensitively (jwt-auth/jwtauth.go: strings.EqualFold(parts[0], scheme); opaque-token-auth/opaquetokenauth.go does the same), so the gateway's auth policies behave differently from each other.

Note: filed in wso2/api-platform because wso2/gateway-controllers, where the policy lives, has issues disabled.

Steps to Reproduce

On wso2/gateway-controllers main c5d83e0, add this test to policies/basic-auth and run go test -run TestZZScheme -v .. It uses the package's existing newBasicRequestHeaderContext helper.

func TestZZScheme(t *testing.T) {
	cred := base64.StdEncoding.EncodeToString([]byte("admin:secret"))
	for _, h := range []string{"Basic " + cred, "basic " + cred, "BASIC " + cred, "Basic  " + cred} {
		ctx := newBasicRequestHeaderContext(map[string][]string{"authorization": {h}})
		a := ins.OnRequestHeaders(context.Background(), ctx, map[string]interface{}{"username": "admin", "password": "secret"})
		switch v := a.(type) {
		case policy.ImmediateResponse:
			fmt.Printf("%-40q -> %d %s\n", h[:8], v.StatusCode, v.Body)
		default:
			fmt.Printf("%-40q -> allowed (authenticated=%v)\n", h[:8], ctx.SharedContext.AuthContext.Authenticated)
		}
	}
}

Expected behavior

All four headers carry the same valid credentials (admin:secret), so all four are authenticated.

Actual behavior

"Basic YW"  -> allowed (authenticated=true)
"basic YW"  -> 401 {"error":"Unauthorized","message":"Authentication required"}
"BASIC YW"  -> 401 {"error":"Unauthorized","message":"Authentication required"}
"Basic  Y"  -> 401 {"error":"Unauthorized","message":"Authentication required"}
Severity Level of the Issue

Severity/Minor (Non-critical functionality. Can be fixed in future releases)

Environment Details (with versions)
  • wso2/gateway-controllers main c5d83e0 (basic-auth policy v1.0.3, sdk/core v0.3.4)
  • Go 1.27.2, Debian Linux x86_64
Lingua principale
Go
Stelle
76
Fork
126
Merge medio
2g 6h
PR unite (30g)
177

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.