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

Offen
#2,181 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

@insaf021 arbeitet bereits daran.

Seit 31.7.2026.

  • #2182 von @insaf021 — offen

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
72/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Ruhig
Tech-Stack
java

Rechercherichtung

Beginne in HttpRequest.handleRedirect() und execute() und überprüfe anschließend die drei im Issue beschriebenen Regressionsszenarien. Überprüfe das Same-Origin-Verhalten bei Änderungen an Schema, Host und Port, einschließlich der Normalisierung von Standard-Ports; fertig ist die Aufgabe, wenn bei Cross-Origin-Redirects die Authorization- und Cookie-Header fehlen, während Same-Origin-Redirects das erwartete Verhalten beibehalten.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Java
Sterne
1.4k
Forks
476
Ø Merge
10 Std. 47 Min.
Gemergte PRs (30 T.)
3

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus googleapis/google-http-java-client

Alle Issues in googleapis/google-http-java-client

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.