googleapis / googleapis/google-http-java-client
Core: Authorization and Cookie headers leaked to cross-origin servers on HTTP redirect
還沒有人認領這個 Issue。
- 主要語言
- Java
- 星號
- 1.4k
- 分支
- 473
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Environment details
- Core - HttpRequest in google-http-client
- OS type and version: Any
- Java version: Any (Java 8+)
- 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
- Build an HttpRequest with an Authorization interceptor (e.g. BasicAuthentication) and a
Cookie header. - Configure the transport to return a 302 redirect to a cross-origin URL (different host).
- Execute the request.
- 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.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 HttpRequest.handleRedirect() 和 execute() 開始,接著檢查 issue 中描述的三個回歸情境。驗證 scheme、host 和 port 發生變更時的 same-origin 行為,包括預設 port 正規化;當 cross-origin 重新導向中不存在 Authorization 和 Cookie 標頭,而 same-origin 重新導向保留預期行為時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- java
- 領域
- backend-api-design, security
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 72/100