Skip to content

fix(den-web): redirect legacy /api/den callers to DEN_API_PUBLIC_URL, not the in-network DEN_API_BASE - #4793

Merged
yomgui merged 1 commit into
devfrom
fix/den-web-public-api-redirect-latest
Sep 10, 2026
Merged

yomgui merged 1 commit into
devfrom
fix/den-web-public-api-redirect-latest

Conversation

@yomgui

@yomgui yomgui commented Sep 10, 2026

Copy link
Copy Markdown
Member

Problem

Follow-up to #4768 ("Not fixed here" section). den-web's legacy /api/den/* route (a 307 kept for older desktop builds) resolves its Location origin from DEN_API_BASE first, in both the route handler (app/(den)/_lib/den-api-origin.ts) and its build-time mirror (next-config-den-api-redirects.cjs). In the documented Compose stack (packaging/docker/docker-compose.eval.yml) and the Helm chart, DEN_API_BASE is the container-internal upstream the /api/auth/* proxy needs (http://den:8788, http://<release>-den-api:8788), so browsers were redirected to a host they cannot reach:

denApiRedirects({ DEN_API_BASE: 'http://den:8788', DEN_API_PUBLIC_URL: 'http://localhost:18788', DEN_BASE_URL: 'http://localhost:13005' })
→ destination http://den:8788/:path*     (expected http://localhost:18788/:path*)

/api/runtime-config already hands new clients DEN_API_PUBLIC_URL; the redirect disagreed with it.

Change (den-web only)

  • den-api-origin.ts + next-config-den-api-redirects.cjs: browser-facing origin order is now DEN_API_PUBLIC_URL → DEN_API_BASE → api.<web host>. The documented fallback is preserved: without a public URL nothing changes.
  • The runtime side now rejects non-http(s) schemes like the mirror already did. Previously a scheme-less value (localhost:18788) parsed as scheme localhost: and yielded the string "null" as origin; the parity test surfaced it.
  • The /api/auth/* proxy, /api/ready, the SSO probe and the dashboard layout keep reading DEN_API_BASE — untouched.
  • ee/apps/den-web/README.md: documents DEN_API_PUBLIC_URL.
  • No change to docker-compose.eval.yml (image pins are ci(release): pin the compose evaluation stack automatically after each release (gated remainder of #4732; scripts in #4905) #4732's; comments already describe the intended split).

Proof

Unit (bun, ee/apps/den-web) — extended tests/den-api-origin.test.ts, tests/den-api-redirect-rules.test.ts (route/build-time parity across 3 new env shapes) and app/api/_lib/den-api-redirect.test.mjs (through the real app/api/den/[...path]/route.ts):

bun test --conditions development tests/den-api-origin.test.ts tests/den-api-redirect-rules.test.ts app/api/_lib/den-api-redirect.test.mjs app/api/_lib/upstream-proxy.test.mjs app/api/_lib/upstream-proxy-lifecycle.test.mjs tests/web-page.test.ts
 57 pass / 0 fail / 213 expect() calls
pnpm --filter @openwork-ee/den-web typecheck → exit 0

pnpm --filter @openwork-ee/den-web test → 234 pass / 1 fail: tests/cloud-super-admins-role-hierarchy.test.ts ("Workflow Runs" label) — pre-existing, same single failure on clean base 586c4100f with this diff stashed.

Runtime boundary (testkit PR lane, local, Docker Desktop) — new evals/specs/den-web-public-api-redirect.test.ts + evals/worlds/den-compose-eval.ts. The world boots the documented docker-compose.eval.yml as an isolated project (unique name/network/volume, free host ports, random secrets) with the web service swapped for a locally built den-web image (OPENWORK_EVAL_DEN_WEB_IMAGE, pull_policy: never) plus a web-fallback container from the same image with DEN_API_PUBLIC_URL removed. Five steps, each with the negative half:

  1. GET :web/api/den/health?probe=redirect → 307, Location origin == DEN_API_PUBLIC_URL, path/query preserved, origin != http://den:8788
  2. following that redirect from the host → 200 {ok:true} on the public API origin
  3. same container: /api/auth/ok 200 (no redirect), /api/auth/get-session 200, /api/ready upstream ok
  4. /api/runtime-config denApiUrl == redirect origin
  5. web-fallback (no DEN_API_PUBLIC_URL): 307 → http://den:8788 (documented DEN_API_BASE fallback) and its /api/auth/ok still 200
docker build --load -f packaging/docker/Dockerfile.den-web -t openwork-den-web:public-redirect-586c410 .
OPENWORK_EVAL_DEN_WEB_IMAGE=openwork-den-web:public-redirect-586c410 pnpm evals:pr specs/den-web-public-api-redirect.test.ts
 Test Files 1 passed (1) · Tests 1 passed (1) · 32.88s · exit 0   (head bcb9470d9, placement: local)

Negative control — same spec against the published openwork-den-web:0.18.46@sha256:82affe9e… (the pin in the compose file): fails at step 1 with expected 'http://den:8788' to be 'http://localhost:<port>', i.e. the spec observes exactly the reported defect. Compose project, volumes and network were removed after each run.

The spec declares needs: { commands: ["docker"], env: ["OPENWORK_EVAL_DEN_WEB_IMAGE"] } and skips loudly without a prebuilt image, so nightly evals:pr does not build images. Daytona lane not used: the proof drives local Docker; no placement dependency.

Framework checks: spec-boundary-ratchet, spec-channel-ratchet, lint:layers (39 known violations before and after), check:browser, tsc -p evals (381 pre-existing errors before and after) — none reference the new files.

Warden (pnpm warden:check, HEAD bcb9470d9 vs origin/dev 586c4100f): diff-security-review, confidentiality-review, spec-provenance-review all completed — No findings, exit 0.

Release dependency

The published den-web image cannot contain this fix; the Compose/Helm redirect is corrected only once a den-web image with this commit is released and #4732's pin automation moves docker-compose.eval.yml to it. Until then /api/runtime-config (new clients) is correct and only the legacy /api/den/* path is affected.

… not the in-network DEN_API_BASE

Follow-up to #4768. den-web's legacy /api/den/* 307 (older desktop builds)
resolved its Location from DEN_API_BASE first. In the documented Compose and
Helm shapes DEN_API_BASE is the container-internal upstream the /api/auth/*
proxy needs (http://den:8788), so browsers were redirected to a host they
cannot reach. Prefer DEN_API_PUBLIC_URL, the browser-reachable origin that
runtime-config already hands to new clients, then fall back to DEN_API_BASE,
then api.<web host>, in both the route handler and its build-time mirror.
The runtime side now also rejects non-http(s) schemes like the mirror did,
so a scheme-less value no longer produces a "null" origin.

The /api/auth/* proxy, readiness and the SSO probe keep reading DEN_API_BASE.

Proof: extended den-web unit tests (route, origin, build-time parity) and a
new PR-lane spec, evals/specs/den-web-public-api-redirect.test.ts, that boots
the documented docker-compose.eval.yml as an isolated project with a locally
built den-web image (OPENWORK_EVAL_DEN_WEB_IMAGE) and asserts from the host
that the redirect lands on Den API health, the auth proxy still answers
through the in-network upstream, runtime-config agrees with the redirect,
and the same image without DEN_API_PUBLIC_URL keeps the DEN_API_BASE fallback.
@vercel

vercel Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openwork-app Ready Ready Preview Sep 10, 2026 2:38pm UTC
openwork-den Ready Ready Preview Sep 10, 2026 2:38pm UTC
openwork-diagnostics Ready Ready Preview Sep 10, 2026 2:38pm UTC
openwork-landing Ready Ready Preview, v0 Sep 10, 2026 2:38pm UTC

@yomgui

yomgui commented Sep 10, 2026 •

Copy link
Copy Markdown
Member Author

Passed · 10/10 tests · 15/15 assertions · 5 images

Commit bcb9470d954f078c96a948c6e8fa886c5706b077 · selected evidence

Open review report

@github-actions

Copy link
Copy Markdown
Contributor

Warden review summary — Clear

Native findings: 1. Blocking policy matches before consolidation: 0. Full finding text remains in Warden's native checks and review threads. This comment retains only native IDs, severity, skill attribution, and safe locations. Analysis run

Reported trigger coverage (not proof of complete repository or context coverage): diff-security-review (31848 ms), confidentiality-review (37753 ms), spec-provenance-review (79401 ms).

Blockers

  • None.

Advisories

  • F73-R4Y · medium · spec-provenance-review · evals/worlds/den-compose-eval.ts:76

Needs recheck

  • None.

Observed review-thread metrics

  • Unique observed run attempts in retained window: 1
  • Distinct heads in retained window: 1
  • Current unresolved Warden threads: 0 of 0 observed
  • Observed resolved/unresolved transitions in retained snapshots: 0 / 0
  • First observed resolved/unresolved (state at first collection, not event time): 0 / 0
  • Precision: unavailable (no adjudications; no TP/FP values are inferred)
  • Observation window: 1/20 run attempts retained; truncated: false
  • Transition snapshot: 0/0 current attributed threads retained (limit 500); truncated: false

Thread states are read-only collection snapshots. These metrics are neither lifetime totals nor exact resolution times, and this summary is not clearance authority.

@diff-warden diff-warden Bot 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.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (bcb9470d954f078c96a948c6e8fa886c5706b077). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

This branch was successfully deployed

4 active deployments
Preview – openwork-landing — bcb9470d Deployed Sep 10, 2026 by vercel[bot]
Preview – openwork-app — bcb9470d Deployed Sep 10, 2026 by vercel[bot]
Preview – openwork-den — bcb9470d Deployed Sep 10, 2026 by vercel[bot]
Preview – openwork-diagnostics — bcb9470d Deployed Sep 10, 2026 by vercel[bot]
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.

1 participant