Repository navigation
fix(fe): fall back to the gateway twins when fetching app metadata - #4281
Merged
Merged
Conversation
The origin an app's metadata is fetched from is the one its identity is derived for, which `remapToLegacyDomain` has already collapsed onto `ic0.app` when it is a canister gateway origin, so that a canister derives one principal across `ic0.app`, `icp0.io` and `icp.net`. A canister need not be served on all three. The staging test app answers `400 client_domain_canister_mismatch` at `<id>.ic0.app` while serving the document at `<id>.icp0.io`, so the fetch failed and the screens fell back to the curated entry with nothing to indicate why. Principal derivation needs that remap; the metadata document, which has no bearing on derivation, does not. Invert the remap and try the twins in turn. All three resolve to the same canister, so this widens where the document may be served, never whose document is used, and the same-origin rule for the logo now follows whichever origin served the document. An origin that answers `404`, or answers with a document at all, settles the question and no twin is tried: an app that publishes nothing still costs a single request, and a document that fails validation is still that origin's answer rather than a reason to look elsewhere. Only a reply that says the app is not served here (`400`, `5xx`) or no reply at all (a network error, a CORS rejection, a redirect, a timeout) moves on. To tell those apart, the shared capped fetch now reports the status it saw instead of collapsing every failure to `undefined`.
aterga
commented
Aug 24, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds gateway-twin fallback when fetching canister app metadata.
Changes:
- Generates equivalent
ic0.app,icp0.io, andicp.netmetadata origins. - Retries non-definitive fetch failures while preserving document-relative logo validation.
- Adds gateway fallback and logo-origin tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
appMetadata.ts |
Implements gateway-origin fallback and status-aware fetching. |
appMetadata.test.ts |
Tests fallback order, stopping rules, and logo origins. |
Suppressed comments (1)
src/frontend/src/lib/utils/appMetadata.ts:493
- This changes the public metadata discovery contract, but
docs/ii-spec.mdx:350still tells integrators that II fetches only from the derivation origin and that the document must be published there. It also does not describe the new status-based twin fallback or that logo same-origin is relative to the twin that served the document. Please update the specification so applications can reliably implement the behavior introduced here.
for (const candidate of appMetadataOrigins(origin)) {
const attempt = await fetchAppMetadataFrom(candidate);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Review feedback on #4281: the inverse of `remapToLegacyDomain` should not restate its regex. `GATEWAY_ORIGIN_REGEX` moves to `urlUtils` and captures both the canister subdomain and the gateway domain, so `remapToLegacyDomain` normalizes onto `ic0.app` with it and `gatewayOriginTwins` inverts it, from one pattern and one list of gateway domains. `appMetadataOrigins` is then just the origin followed by its twins. `urlUtils` rather than `iiConnection` because `appMetadata` is a leaf with no local imports, and `remapToLegacyDomain` keeps its home so its call sites are untouched. `remapToLegacyDomain` behaviour is unchanged: it previously matched only the two remapped domains and passed everything else through, and now matches all three and passes `ic0.app` through. Checked against the old implementation over `.raw` labels, subdomain-suffix lookalikes (`x.icp0.io.evil.com`), non-default ports, paths, uppercase and the empty string.
The metadata document is no longer fetched only from the origin the app's identity is derived for: when that is a canister gateway origin, the same canister's other gateway domains are tried in turn, because a canister reachable at `<id>.icp0.io` can answer `400 client_domain_canister_mismatch` at the `<id>.ic0.app` origin principals are derived against. Spell out the retry policy integrators need to implement against (which statuses settle the question and which move on), and make explicit that the logo's same-origin requirement is relative to the domain that served the document, not to the requested one.
|
✅ No security or compliance issues detected. Reviewed everything up to 23d8ffc. Security OverviewDetected Code Changes
|
sea-snake
approved these changes
Aug 24, 2026
sea-snake
left a comment
Contributor
There was a problem hiding this comment.
I think just icp.net was probably sufficient, but PR is fine nontheless.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
App metadata (#4221) is fetched from the origin the app's identity is derived for. When that is a canister gateway origin,
remapToLegacyDomainhas already collapsed it ontoic0.app, so a canister derives one principal whether the user arrived viaic0.app,icp0.iooricp.net.A canister need not be served on all three. The staging test app answers
400 client_domain_canister_mismatchat.ic0.appwhile serving the document at.icp0.io. The fetch failed, the failure was silent by design, and the screens fell back to the curated entry, so an app that had published the file correctly still showed as unbranded with nothing to indicate why.Principal derivation needs that remap. The metadata document does not: it has no bearing on derivation, and the spec is explicit that it carries no principal-derivation security semantics.
Changes
appMetadataOrigins(origin)inverts the remap: forhttps://<sub>.ic0.appit yields that origin followed by theicp0.ioandicp.nettwins, preserving a.rawlabel. Any other origin (a custom domain, localhost) yields just itself. All three twins resolve to the same canister, so this widens where the document may be served, never whose document is used.fetchAppMetadatatries those origins in turn and stops at the first that answers.fetchCappedreports the status it saw rather than collapsing every failure toundefined, which is what lets the caller distinguish the two kinds of failure below.GATEWAY_ORIGIN_REGEXinurlUtils):remapToLegacyDomainnormalizes ontoic0.appwith it andgatewayOriginTwinsinverts it, so the set of gateway domains and the shape of a canister subdomain are stated once.remapToLegacyDomain's behaviour is unchanged.docs/ii-spec.mdx, App metadata): which origins are asked and in what order, which statuses settle the question and which move on, and that the logo's same-origin requirement is relative to the domain that served the document rather than the one that was requested.When a twin is tried
Only when the origin did not answer for the app:
200, document valid200, document invalid or unparseable404400,5xx, other non-200The
404case is what keeps this cheap. All three domains resolve to the same canister, so a canister that says "no such file" has answered for every one of them, and the ordinary case of an app that publishes nothing still costs exactly one request. Only an app in the broken position above pays for extra attempts.Tests
11 new cases in
appMetadata.test.ts(48 total in the file):appMetadataOrigins: twins for a remapped origin,.rawpreserved, no twins invented for a custom domain.icp0.ioon the exact reported failure (400 client_domain_canister_mismatchatic0.app, document aticp0.io), fallback on toicp.net, and fallback when the first origin cannot be reached at all.404, and none tried when a document is served but fails validation, each asserting the request count.Verification:
npx vitest run src/frontend/src/lib/utils/appMetadata.test.ts: 47 passed, 1 failed. The failure isshould fetch a same-origin logo and render it from a blob url, which assertsexpect.any(Blob)against a Blob from a different realm. It reproduces identically onmainwith this change stashed (36 passed, 1 failed), so it is a pre-existing sandbox issue and not a regression here.npx vitest run src/frontend/src/lib/utils/validateDerivationOrigin.test.ts: 25 passed, covering theremapToLegacyDomainrewrite.eslint --max-warnings 0,prettier --checkandtsc --project tsconfig.all.json --noEmitare clean on the changed source files.Note on sequencing
I understand the plan was to ship fuller support for this in about a week. This is the narrow fix for the reported symptom only, so it should be easy to drop or fold in if it overlaps with that work.
Generated by Claude Code