Core: Authorization and Cookie headers leaked to cross-origin servers on HTTP redirect

Aperta
#2,181 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@insaf021 ci sta già lavorando.

Dal 31/7/2026.

  • #2182 di @insaf021 — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
java

Direzione di ricerca

Inizia da HttpRequest.handleRedirect() ed execute(), quindi esamina i tre scenari di regressione descritti nell’issue. Verifica il comportamento same-origin in caso di modifiche a schema, host e porta, inclusa la normalizzazione della porta predefinita; il lavoro è completato quando i reindirizzamenti cross-origin non includono gli header Authorization e Cookie, mentre i reindirizzamenti same-origin mantengono il comportamento previsto.

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

Descrizione

priority: p3

Environment details

  1. Core - HttpRequest in google-http-client
  2. OS type and version: Any
  3. Java version: Any (Java 8+)
  4. google-http-client version: reproducible on current main

Problem Statement
When HttpRequest follows a redirect to a different origin (different scheme, host, or port),
the Cookie header is not stripped. Additionally, Authorization headers set via interceptors
(e.g. BasicAuthentication) are re-applied by the interceptor on subsequent redirect
iterations regardless of destination origin. This can cause credentials to be silently
forwarded to attacker-controlled servers.

Steps to reproduce

  1. Build an HttpRequest with an Authorization interceptor (e.g. BasicAuthentication) and a
    Cookie header.
  2. Configure the transport to return a 302 redirect to a cross-origin URL (different host).
  3. Execute the request.
  4. Observe that the second request (to the cross-origin target) still includes Authorization
    and Cookie headers.

Proposed Fix
In handleRedirect(), compute whether the new URL is same-origin as the old URL (comparing
scheme, host, and effective port). Strip Cookie header if cross-origin. In execute(), before
each retry, compare current URL origin to original origin and strip Authorization and Cookie
if the URL has changed to a different origin (e.g. after a previous redirect).

Add getEffectivePort() and isSameOrigin() helpers to normalize default ports (80 for http,
443 for https).

Three regression tests are included in the accompanying PR covering same-origin,
cross-origin host change, scheme change, and port change scenarios.

Lingua principale
Java
Stelle
1.4k
Fork
476
Merge medio
10h 47m
PR unite (30g)
3

Preparare l'ambiente

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 googleapis/google-http-java-client

Tutte le issue di googleapis/google-http-java-client

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.