Skip to content

fix(console): derive environment.json api from the requested origin - #12893

Merged
livio-a merged 4 commits into
zitadel:mainfrom
MustafaKemal0146:fix/console-env-request-origin
Oct 21, 2026
Merged

livio-a merged 4 commits into
zitadel:mainfrom
MustafaKemal0146:fix/console-env-request-origin

Conversation

@MustafaKemal0146

@MustafaKemal0146 MustafaKemal0146 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Which Problems Are Solved

  • When an instance has multiple custom domains (or runs behind a reverse proxy that forwards the original host), the api attribute of the management console's /ui/console/assets/environment.json does not match the requested domain, while issuer does.
  • The api URL was built from the raw r.Host of the request, whereas the issuer is derived from the domain context that the WithOrigin middleware resolves from the instance / public host headers.

How the Problems Are Solved

  • The api URL is now taken from http_util.DomainContext(ctx).Origin(), the same source the OIDC issuer uses, so both values always match.

Additional Changes

  • Removes the now unused externalSecure parameter from console.Start. The protocol is already part of the domain context (WithOrigin is configured with ExternalSecure).
  • Adds a unit test for the environment.json handler covering the instance host, a public host and a forwarded instance host that differ from the request host. The test fails on main (api is https://zitadel.internal:8080 instead of https://custom.example.com) and passes with this change.

Additional Context

🤖 Generated with Claude Code

The api URL in the console's environment.json was built from the raw
request Host header, while the issuer already uses the domain context
resolved by the origin middleware. With multiple custom domains or a
reverse proxy, both values diverged.

Use the domain context origin for the api URL as well, so it always
matches the issuer. This makes the externalSecure parameter of
console.Start obsolete, as the protocol is already part of the domain
context.

Closes zitadel#12009

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 6, 2026 17:53
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@vercel

vercel Bot commented Oct 6, 2026

Copy link
Copy Markdown

@MustafaKemal0146 is attempting to deploy a commit to the zitadel Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@hifabienne hifabienne added the os-contribution This is a contribution from our open-source community label Oct 6, 2026
@livio-a
livio-a requested review from livio-a and a balanced review from Copilot October 7, 2026 13:31
@nx-cloud

nx-cloud Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 170d47b

Command Status Duration Result
nx affected --nxBail --targets lint test build ... ✅ Succeeded 12m 57s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-10-21 12:49:44 UTC

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation consistently uses the established origin context and covers the reported scenarios.

Review effort: Balanced
Findings: None

@livio-a livio-a left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, looks good! The api URL now follows the same origin resolution as the issuer, which fixes both #12009 and #12195. I added #12195 to the closed issues, since this also fixes the X-Forwarded-Host case. Could you have a look at the comments on the tests? Once they're addressed, I'm happy to approve.

Comment thread internal/api/ui/console/console.go Resolved
Comment thread internal/api/ui/console/console_test.go Resolved
Comment thread internal/api/ui/console/console_test.go Resolved
livio-a and others added 2 commits October 21, 2026 14:08
Run the test cases through the WithOrigin middleware with real
headers (X-Forwarded-Host, Forwarded, x-zitadel-*-host) instead of
setting the domain context directly, and drop the issuer assertion
which could not fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@livio-a

livio-a commented Oct 21, 2026

Copy link
Copy Markdown
Member

I pushed the test changes from my review directly to keep this moving. Thanks again for the fix!

@livio-a
livio-a enabled auto-merge (squash) October 21, 2026 12:36
@livio-a
livio-a disabled auto-merge October 21, 2026 12:54
@livio-a
livio-a merged commit ce12560 into zitadel:main Oct 21, 2026
8 of 10 checks passed
livio-a added a commit that referenced this pull request Oct 22, 2026
…12893)

<!--
Please inform yourself about the contribution guidelines on submitting a
PR here:
https://github.com/zitadel/zitadel/blob/main/CONTRIBUTING.md#submit-a-pull-request-pr.
Take note of how PR/commit titles should be written and replace the
template texts in the sections below. Don't remove any of the sections.
It is important that the commit history clearly shows what is changed
and why.
Important: By submitting a contribution you agree to the terms from our
Licensing Policy as described here:
https://github.com/zitadel/zitadel/blob/main/LICENSING.md#community-contributions.
-->

# Which Problems Are Solved

- When an instance has multiple custom domains (or runs behind a reverse
proxy that forwards the original host), the `api` attribute of the
management console's `/ui/console/assets/environment.json` does not
match the requested domain, while `issuer` does.
- The `api` URL was built from the raw `r.Host` of the request, whereas
the issuer is derived from the domain context that the `WithOrigin`
middleware resolves from the instance / public host headers.

# How the Problems Are Solved

- The `api` URL is now taken from
`http_util.DomainContext(ctx).Origin()`, the same source the OIDC issuer
uses, so both values always match.

# Additional Changes

- Removes the now unused `externalSecure` parameter from
`console.Start`. The protocol is already part of the domain context
(`WithOrigin` is configured with `ExternalSecure`).
- Adds a unit test for the `environment.json` handler covering the
instance host, a public host and a forwarded instance host that differ
from the request host. The test fails on `main` (`api` is
`https://zitadel.internal:8080` instead of `https://custom.example.com`)
and passes with this change.

# Additional Context

- Closes #12009
- Closes #12195
- AI-assisted: this change was prepared with Claude Code and reviewed
and tested by me (`go test ./internal/api/ui/console/`, `go vet`, `go
build ./cmd/...`).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Livio Spring <[email protected]>
(cherry picked from commit ce12560)
livio-a added a commit that referenced this pull request Oct 22, 2026
…12893)

<!--
Please inform yourself about the contribution guidelines on submitting a
PR here:
https://github.com/zitadel/zitadel/blob/main/CONTRIBUTING.md#submit-a-pull-request-pr.
Take note of how PR/commit titles should be written and replace the
template texts in the sections below. Don't remove any of the sections.
It is important that the commit history clearly shows what is changed
and why.
Important: By submitting a contribution you agree to the terms from our
Licensing Policy as described here:
https://github.com/zitadel/zitadel/blob/main/LICENSING.md#community-contributions.
-->

# Which Problems Are Solved

- When an instance has multiple custom domains (or runs behind a reverse
proxy that forwards the original host), the `api` attribute of the
management console's `/ui/console/assets/environment.json` does not
match the requested domain, while `issuer` does.
- The `api` URL was built from the raw `r.Host` of the request, whereas
the issuer is derived from the domain context that the `WithOrigin`
middleware resolves from the instance / public host headers.

# How the Problems Are Solved

- The `api` URL is now taken from
`http_util.DomainContext(ctx).Origin()`, the same source the OIDC issuer
uses, so both values always match.

# Additional Changes

- Removes the now unused `externalSecure` parameter from
`console.Start`. The protocol is already part of the domain context
(`WithOrigin` is configured with `ExternalSecure`).
- Adds a unit test for the `environment.json` handler covering the
instance host, a public host and a forwarded instance host that differ
from the request host. The test fails on `main` (`api` is
`https://zitadel.internal:8080` instead of `https://custom.example.com`)
and passes with this change.

# Additional Context

- Closes #12009
- Closes #12195
- AI-assisted: this change was prepared with Claude Code and reviewed
and tested by me (`go test ./internal/api/ui/console/`, `go vet`, `go
build ./cmd/...`).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Livio Spring <[email protected]>
(cherry picked from commit ce12560)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

os-contribution This is a contribution from our open-source community

Projects

Status: ✅ Done

4 participants