Skip to content

fix(proxy): preserve cross-origin redirects - #34

Open
idirze wants to merge 1 commit into
OKDP:mainfrom
idirze:fix/33-preserve-cross-origin-redirects
Open

fix(proxy): preserve cross-origin redirects#34
idirze wants to merge 1 commit into
OKDP:mainfrom
idirze:fix/33-preserve-cross-origin-redirects

Conversation

@idirze

@idirze idirze commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Description

ModifyResponse stripped the scheme and host from every 302 Location header without checking where the redirect pointed.

As a result, any absolute cross-origin redirect could be reduced to a relative path and incorrectly resolved by the browser against spark-web-proxy.

For example, when the Spark authentication filter redirects an unauthenticated browser to an OIDC identity provider:

https://<keycloak-host>/realms/master/protocol/openid-connect/auth?client_id=...

the proxy rewrote the Location to:

/realms/master/protocol/openid-connect/auth?client_id=...

The browser then resolved that relative path against spark-web-proxy:

https://<spark-web-proxy-host>/realms/master/protocol/openid-connect/auth?client_id=...

resulting in a 404 instead of continuing the OIDC authentication flow.

This change:

  • leaves already-relative Location headers unchanged;
  • compares absolute redirect targets with the configured Spark upstream origin;
  • rewrites redirects only when they target the Spark upstream;
  • preserves cross-origin redirects unchanged;
  • correctly compares upstream origins when HTTP or HTTPS default ports are omitted.

This preserves the existing Spark redirect behavior while allowing redirects to external origins, including identity providers, to pass through correctly.

Related Issue

Refs #33

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / chore
  • Breaking change

How to Test

Run the project test suite:

make test

The issue can be reproduced using the Spark authentication filter with PKCE disabled, causing it to emit an HTTP 302 redirect to Keycloak:

use-pkce: false

Then access the Spark History UI through spark-web-proxy.

Before

The external OIDC redirect is rewritten and resolved against the proxy:

https://<spark-web-proxy-host>/realms/master/protocol/openid-connect/auth?client_id=...

and returns 404.

After

The original cross-origin Location is preserved:

https://<keycloak-host>/realms/master/protocol/openid-connect/auth?client_id=...

and the browser is correctly redirected to the identity provider.

Internal Spark redirects continue to be rewritten through the proxy, while relative redirects remain unchanged.

Checklist

ModifyResponse stripped the scheme and host from every 302 Location
header, without checking where the redirect pointed. An absolute
cross-origin redirect, such as the auth filter sending an
unauthenticated browser to the identity provider, was reduced to a bare
path that the browser resolved against the proxy, so the OIDC flow
never started.

Compare the redirect target with the upstream origin and rewrite only
when they match. Relative Location headers are left alone, as are
redirects to any other origin.

Refs OKDP#33
@idirze
idirze requested review from a team September 1, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants