Skip to content

Authorize a declared derivation_origin against ii-alternative-origins (ICPBB-430) - #131

Merged
aterga merged 3 commits into
mainfrom
security/derivation-origin-authorization
Aug 17, 2026
Merged

aterga merged 3 commits into
mainfrom
security/derivation-origin-authorization

Conversation

@aterga

@aterga aterga commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Problem (ICPBB-430)

resolve_app_identity (src/discover.rs) resolved a user's Internet Identity derivation_origin from 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:

  • cross-app deanonymization (the attacker's canister sees caller() == the victim's Oisy principal — exactly what II's per-origin principals exist to prevent),
  • authenticated action as the victim at attacker-named canisters, and reads of the victim's private per-app data via the auto-approved read-only canister_query.

The trust direction was inverted: Internet Identity/the browser fetch /.well-known/ii-alternative-origins at 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:

  • A self-declaration (declared origin == the app's own origin) needs no cross-origin trust — accepted.
  • A cross-origin declared origin is honored only when the declared origin's ii-alternative-origins lists 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.com declaration is now rejected, so open_app/resolve_app never 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_origin argument passed directly to canister_query/canister_update_call goes through resolve_identity_target (shape-canonicalization only), not this resolution. The reported attack chain runs through open_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.

…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]>
@aterga
aterga requested review from a team and a balanced review from Copilot August 14, 2026 05:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/discover.rs Resolved
Comment thread src/discover.rs Resolved
sea-snake
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]>
Copilot AI review requested due to automatic review settings August 14, 2026 11:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Comment thread src/discover.rs Resolved
…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]>
Copilot AI review requested due to automatic review settings August 14, 2026 13:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 Err and 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`).

@aterga
aterga merged commit 20a52e9 into main Aug 17, 2026
8 checks passed
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.

3 participants