oauth2-proxy/pkg
赵鑫亿 7361885fae fix(redirect): preserve requested URL in forward_auth flows without whitelist
In reverse-proxy / forward_auth setups (Caddy `forward_auth`, nginx
`auth_request`), the post-login redirect is built as an absolute URL
`{scheme}://{host}{uri}` and passed to oauth2-proxy via the `rd` query
parameter. The Caddy integration docs require `--reverse-proxy=true` but
do not mention that the host must also be added to `--whitelist-domain`.

Without `--whitelist-domain`, the absolute `rd` was rejected by the
redirect validator and, because the `sign_in`/`start` requests are served
under the proxy prefix, the remaining redirect strategies collapsed to
"/", silently losing the originally requested URL (and its query) after
login.

When `rd` is an absolute http(s) URL that fails whitelist validation but
targets the same host the request was served on, fall back to its path
component and re-validate it as a relative redirect. This is safe:
- it is a same-origin relative redirect, so it cannot redirect to a
  different host;
- the extracted path is still run through the validator, so open-redirect
  protections (e.g. "//", "/../") still apply;
- a `rd` pointing at a different, non-whitelisted host is left untouched,
  so the other redirect strategies still run unchanged.

Regression tests model the Caddy `forward_auth` sign_in request and
verify that the originally requested path+query is preserved without a
whitelist, that a different non-whitelisted host is still rejected, and
that open-redirect payloads are still blocked.

Fixes #2940

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: 赵鑫亿 <98445030+zhaoxinyi02@users.noreply.github.com>
2026-08-10 18:16:00 +08:00
..
apis chore(goconsts): use proper constants for http methods 2026-06-08 12:54:58 +02:00
app fix(redirect): preserve requested URL in forward_auth flows without whitelist 2026-08-10 18:16:00 +08:00
authentication chore(goconsts): use proper constants for http methods 2026-06-08 12:54:58 +02:00
cookies Merge commit from fork 2026-04-13 18:22:56 +02:00
encryption fix alpha config 2025-11-16 22:38:40 +01:00
header revert: secrets as []byte instead of string 2025-11-16 22:38:42 +01:00
ip Merge commit from fork 2026-04-13 18:22:56 +02:00
logger Request ID Logging (#1087) 2021-03-21 18:20:57 +00:00
middleware Merge commit from fork 2026-04-13 18:22:56 +02:00
providers feat: add support for specifying allowed OIDC JWT signing algorithms (#2753) (#2851) 2026-03-18 22:24:27 +08:00
proxyhttp feat: add support for setting a unix binding's socket file mode (#3376) 2026-03-19 00:08:50 +08:00
requests chore(goconsts): use proper constants for http methods 2026-06-08 12:54:58 +02:00
sessions feat: add same site option for csrf cookies (#3347) 2026-03-18 23:14:36 +08:00
upstream chore(deps): bump Go to 1.26 and migrate upstream reverse proxies to Rewrite 2026-06-08 14:12:56 +02:00
util feat: allow arbitrary claims from the IDToken and IdentityProvider UserInfo endpoint to be added to the session state (#2685) 2026-03-14 12:04:33 +08:00
validation chore(deps): bump Go to 1.26 and migrate upstream reverse proxies to Rewrite 2026-06-08 14:12:56 +02:00
version feat: Replace default Go user-agent with oauth2-proxy and version (#2570) 2024-07-14 21:09:17 +01:00
watcher Fix Linting Errors (#1835) 2022-10-21 11:57:51 +01:00