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

Open
#2,181 0 comments 0 reactions 0 assignees View on GitHub

@insaf021 is already working on this.

Since Jul 31, 2026.

  • #2182 by @insaf021 — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
java

Research direction

Start in HttpRequest.handleRedirect() and execute(), then review the three regression scenarios described in the issue. Verify same-origin behavior across scheme, host, and port changes, including default-port normalization; done when cross-origin Authorization and Cookie headers are absent while same-origin redirects retain expected behavior.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Java
Stars
1.4k
Forks
476
Avg merge
10h 47m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleapis/google-http-java-client

All issues in googleapis/google-http-java-client

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.