Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

AdkWebServer's root->dev-ui redirect breaks behind a path-stripping reverse proxy

未关闭
#1,457 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@hemasekhar-p 已经在做这个了。

开始于 2026年8月26日。

  • #1458 来自 @luisSilva1234 —— 已关闭,未合并
  • #1463 来自 @luissilva-mollie —— 已关闭,未合并

评估

这个 Issue 还没有评估数据。

描述

needs review

Description

AdkWebServer.addViewControllers() redirects "/" to the root-relative path "/dev-ui":

https://github.com/google/adk-java/blob/e8b1c20d10680e7ed8e936ae1ac0ab768a0b8345/dev/src/main/java/com/google/adk/web/AdkWebServer.java#L151

registry.addRedirectViewController("/", "/dev-ui");

When this app is deployed behind a reverse proxy that strips a path prefix before forwarding the request (a common pattern for platform-managed multi-tenant gateways, e.g. Kubernetes Gateway API HTTPRoute with a URLRewrite/ReplacePrefixMatch filter), the browser follows this redirect to an unprefixed path the proxy has no route for, and the dev UI 404s.

Why this can't be fixed by the app alone with standard Spring mechanisms

Spring's own reverse-proxy support (server.forward-headers-strategy=framework, which installs ForwardedHeaderFilter) is specifically designed to solve exactly this class of problem via the X-Forwarded-Prefix header — but it only works for context-relative redirect targets (ones that do not start with /). I traced this through ForwardedHeaderExtractingResponse#sendRedirect:

path = (path.startsWith(FOLDER_SEPARATOR) ? path :
        StringUtils.applyRelativePath(this.request.getRequestURI(), path));

Root-relative targets (starting with /, as "/dev-ui" does) skip the applyRelativePath branch entirely — the one place X-Forwarded-Prefix awareness would apply — so the prefix is never spliced back in, no matter how the proxy is configured.

Proposed fix

Change the redirect target to be context-relative instead of root-relative:

registry.addRedirectViewController("/", "dev-ui");

I verified this doesn't change behavior for the common local/non-proxied case: RedirectView's contextRelative handling only prepends the context path when the target starts with / (so a context-relative target like "dev-ui" is passed through as-is), and the servlet container's own relative-URL resolution for sendRedirect still resolves "dev-ui" against the current request path "/" to "/dev-ui". It does additionally allow server.forward-headers-strategy=framework + an X-Forwarded-Prefix header to correctly restore a proxy's path prefix, fixing the reverse-proxy case with zero app-specific workaround code.

I've opened a PR with this one-line fix plus the corresponding test update: (link to follow)

Environment

  • adk-java: current main (verified against commit e8b1c20)
  • Encountered while deploying a Java ADK agent behind a Kubernetes Gateway API HTTPRoute that strips a per-app path prefix
主要语言
Java
星标
1.7k
派生
433
平均合并
2 天 21 小时
30 天内合并 PR
40

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

google/adk-java 的其他 Issue

查看 google/adk-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。