Repository navigation
Authorize a declared derivation_origin against ii-alternative-origins (ICPBB-430) - #131
Merged
Merged
Conversation
…ntity (ICPBB-430) `resolve_app_identity` accepted the `derivation_origin` a site declares about itself in its own `/.well-known/ic-app.json` VERBATIM, with no check that the site is entitled to it. Any website could therefore declare `derivation_origin: https://oisy.com`, and when the user asked their agent about that site the agent would derive the user's REAL Oisy identity and act under it — cross-app deanonymization plus authenticated action as the victim at attacker-named canisters. The server even fetched the authoritative file (`ii-alternative-origins`) but used it for display only. Apply the same rule Internet Identity and the browser enforce, on the server: a cross-origin declared derivation origin is honored only when the DECLARED origin lists the requesting application origin in its `/.well-known/ii-alternative-origins`. A self-declaration (the app names its own origin) needs no check. An unauthorized claim is ignored and the resolution falls back to the application origin — which the existing IC-evidence gate then refuses for a non-IC site — and is logged. The authorization list was already fetched here (for display); the fix gates on it. The decision is a pure, unit-tested helper; the fetched list is reused for the display path so no extra round-trip is added on the identity hot path beyond the one cross-origin claim that must be checked. Not covered here (documented as follow-up): a raw `derivation_origin` argument passed directly to `canister_query`/`canister_update_call` bypasses this resolution; the reported chain runs through open_app/resolve_app, which this closes. Co-Authored-By: Claude Opus 5 <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds authorization for cross-origin Internet Identity derivation origins, preventing identity spoofing.
Changes:
- Validates cross-origin declarations against
ii-alternative-origins. - Reuses fetched origins and adds helper tests.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
sea-snake
previously approved these changes
Aug 14, 2026
- Refactor the nested manifest/declaration if/else tree in resolve_app_identity into a flat `resolve_declared_origin` helper with early guards (let-else + early returns), returning a `DeclaredResolution`. resolve_app_identity now just destructures it. - Extract the security-critical decision into a pure `resolved_declared` (declared + its alt-origins → (derivation_origin, source)) and add `resolved_declared_maps_origin_and_source`, which covers self / authorized / unauthorized / unverifiable, asserting the fall-back to the application origin as AppUrlDefault — the resolver branch the prior string-helper test didn't reach (review comment 1). - Fix the misleading warning: `fetch_alternative_origins` collapses every failure (DNS/TLS/timeout/non-success/parse) to an empty list, so an empty result means authorization was UNVERIFIABLE, not that the list omitted the app. The log now says so (review comment 2). No behavior change to the authorization outcome; live-network resolve tests still pass. Co-Authored-By: Claude Opus 5 <[email protected]>
aterga
commented
Aug 14, 2026
…nt fallback Per review: when a manifest declares a CROSS-origin derivation_origin that cannot be authorized against that origin's ii-alternative-origins, resolve_app_identity now returns an Err instead of falling back to the application origin. Falling back there silently derived the WRONG principal for an app that deliberately pins a custom derivation origin, and masked a spoof, a misconfiguration, or a transiently-unreachable list. Surfacing it lets the caller refuse rather than act as an unintended identity. No-declaration / self-declaration / authorized cross-origin are unchanged (the first two legitimately default to the application origin). The decision is now a pure `decide_declared_origin` returning Result<(origin, source), _>, unit-tested across no-declaration / self / authorized / unauthorized / unverifiable — including the Err branch the prior string-helper test didn't reach. Replaces the earlier `resolved_declared` fall-back helper. Live-network resolve tests still pass. Co-Authored-By: Claude Opus 5 <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/discover.rs:786
- The PR description says an unauthorized declaration is ignored and resolution falls back to the application origin (then through the IC-evidence/known-app logic), but this branch now returns
Errand skips those fallbacks entirely. This is a material user-visible contract difference, especially for known apps with an unreachable or temporarily malformed alternative-origins endpoint. Please align the description/acceptance criteria with the intentional fail-closed behavior, or restore the documented fallback.
/// A cross-origin claim that CANNOT be authorized is an `Err`, not a silent
/// fall-back: falling back to the application origin there would derive the WRONG
/// principal for an app that deliberately pins a custom derivation origin (and
/// would mask a spoof, a misconfiguration, or an unreachable `ii-alternative-origins`).
sea-snake
approved these changes
Aug 17, 2026
7 of 10 tasks
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.
Problem (ICPBB-430)
resolve_app_identity(src/discover.rs) resolved a user's Internet Identityderivation_originfrom a value the target site declares about itself in its own/.well-known/ic-app.json, accepting it verbatim (source =Declared, documented "authoritative") with no check that the site is entitled to that origin.So any website — no IC hosting required — could serve a static file declaring
"derivation_origin": "https://oisy.com". When the user asks their agent about that site, the agent derives the user's real Oisy identity and acts under it, calling attacker-named canisters. That yields:caller() == the victim's Oisy principal— exactly what II's per-origin principals exist to prevent),canister_query.The trust direction was inverted: Internet Identity/the browser fetch
/.well-known/ii-alternative-originsat the derivation origin (the party being impersonated) and require the requesting origin to be listed. imcp2 read the claim at the requesting site and — though it fetched the authoritative file — used it for display only, noting "the list never affects the resolved derivation origin." DFINITY's own II spec forbids exactly this: "never set origins you do not control as derivationOrigin."Confirmed present on
main. Not DoS — this is broken access control with confidentiality impact.Fix
Apply the browser/II rule on the server, in
resolve_app_identity:ii-alternative-originslists the requesting application origin (derivation_origin_authorized, a pure unit-tested helper). Otherwise the claim is ignored, resolution falls back to the application origin — which the existing IC-evidence gate then refuses for a non-IC site — and the refusal is logged.The authorization list is the same one already fetched for display, so the fetched list is reused; no extra round-trip is added except the one cross-origin claim that must be checked. Matching is by exact origin (scheme+host+port), reusing
parse_alternative_origins' normalization.Effect on the reported chain
The attacker's
oisy.comdeclaration is now rejected, soopen_app/resolve_appnever hand the agent the spoofed origin. A non-IC attacker site is refused by the existing gate; an IC-hosted attacker site resolves to its own origin (the attacker only ever sees its own users' per-origin principals — no cross-app leak).Tests
derivation_origin_authorized_requires_the_declared_origin_to_list_the_app: self-declaration allowed; unlisted cross-origin claim (the spoof) refused; empty list refused; listed cross-origin claim (a legitimate multi-frontend app) allowed; exact-origin matching (different scheme/port/host must not pass).Full lib suite green (158 tests incl. the live-network resolve tests, confirming legitimate resolution is unaffected); no new clippy warnings.
Not covered here (follow-up)
A raw
derivation_originargument passed directly tocanister_query/canister_update_callgoes throughresolve_identity_target(shape-canonicalization only), not this resolution. The reported attack chain runs throughopen_app/resolve_app, which this PR closes. Binding the raw-arg path to a validated resolution is a separate change (there's no requesting "application origin" in that path to authorize against) and is noted for follow-up.