Repository navigation
Refuse guessed app domains: gate app_url_default on IC evidence + "did you mean" repair - #57
Merged
Merged
Conversation
…e→URL repair
Observed failure: given only an app NAME ("multidex"), a model guessed
domains (multidex.com, multidex.app, multi.dex) instead of calling
icp_find_app_by_name — and resolve_app rewarded the guesses with a
success + buried note, since app_url_default resolves ANY reachable
https origin. Three layers now enforce name→URL discipline:
1. Runtime gate: resolve_app_identity probes the origin for IC evidence
(the gateway's x-ic-canister-id header, captured from the manifest
response or one extra fetch) whenever the derivation origin would be
ASSUMED (app_url_default). resolve_app and every app_url identity
route (get_app_principal, list_app_accounts, call_canister) now
REFUSE an origin with no IC evidence instead of resolving a guessed
lookalike domain to a plausible-but-wrong identity. Deliberate use of
a non-IC-hosted II origin stays possible via explicit
derivation_origin.
2. "Did you mean" repair: similar_known_app() token-matches a guessed
host against the known-app registry, so refusals, fetch errors
(DNS-dead guesses like multi.dex), empty discover results, and even
IC-hosted lookalike successes name the real app and its URL
("DID YOU MEAN MULTI/DEX? Its real URL is https://multidex.ai") —
one-step convergence instead of another guess.
3. Prompt-level steering: the server instructions gain a "names are not
URLs" rule (icp_find_app_by_name FIRST, then web search / ask — never
fabricate a domain), and the resolve_app / discover_app_canisters /
icp_find_app_by_name descriptions plus every app_url arg schema carry
the same directive. ResolveAppOutput exposes application_is_ic.
Covered by offline tests (lookalike matching, refusal/repair message
content) and live ones (example.com refused; known apps skip the probe).
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh
There was a problem hiding this comment.
Pull request overview
This PR hardens app identity resolution against models guessing lookalike domains from an app name by (1) gating app_url_default derivation-origin assumptions on positive Internet Computer (IC) evidence and (2) attaching a one-step “did you mean …” repair path when a guessed host resembles a known app.
Changes:
- Add IC-served evidence probing (
x-ic-canister-id) toresolve_app_identityand refuse unverifiedapp_url_defaultresolutions in identity-bearing routes. - Introduce
discover::similar_known_app()to provide “did you mean” guidance for guessed/lookalike hosts and surface that guidance across key error/empty-result paths. - Update tool descriptions / server instructions / README to explicitly steer “name → URL” via
icp_find_app_by_nameand prohibit fabricated domains; extendResolveAppOutputwithapplication_is_ic.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/main.rs | Wrap app-url errors with guidance; refuse unverified app_url_default identity derivations; add “did you mean” messaging and related tests. |
| src/discover.rs | Add application_is_ic evidence probing to app identity resolution; implement similar_known_app() and tests. |
| src/identities.rs | Tighten app_url schema docs; extend ResolveAppOutput with application_is_ic. |
| src/calls.rs | Update app_url argument docs to discourage guessing and reflect refusal behavior. |
| README.md | Document “name ≠ URL” flow and the new refusal/repair behavior in user-facing docs. |
Comments suppressed due to low confidence (1)
src/main.rs:706
discover_app_canistersadds “did you mean” guidance for the empty-result case, but the error path (Err(e) => Ok(err(e))) still returns raw DNS/TLS/timeout/SSRF errors without the same repair guidance. The PR description says the repair is attached to fetch/DNS errors as well (so they don’t look like transient failures that invite more guessing).
);
let output = discover::DiscoverOutput::from((domain, Vec::new()));
Ok(ok_structured(text, &output))
}
Err(e) => Ok(err(e)),
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…e discover errors Two fixes from PR review: - resolve_app_identity no longer concludes application_is_ic=Some(false) from a FAILED probe: a timeout/TLS/connect error on the origin now propagates as "could not reach …" (which callers wrap with the guess-repair guidance) instead of misclassifying an unreachable-but- real IC app as a reachable non-IC site. The confirmation probe also targets the ORIGIN ROOT rather than the caller's full URL, so an arbitrary user-supplied path can't point the header check at a huge resource. - discover_app_canisters' error path now carries the same app_url_error_with_guidance repair as the identity routes, so a DNS-dead guessed domain reads as "wrong URL — here's the real one" there too. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh
- IC evidence now requires the x-ic-canister-id header to carry a value that parses as a canister principal, not merely be present — a new has_ic_gateway_header() gates both probes. An unrelated origin echoing an empty/junk header can no longer fake IC hosting and slip past the guessed-domain guard. (Still a heuristic, not a security boundary — headers are forgeable — but it defeats accidental/lazy false positives; the explicit derivation_origin escape hatch remains.) - Reworded unverified_app_url_error: the refusal condition is "no valid x-ic-canister-id + no declared derivation origin", so it no longer implies /.well-known/ic-app.json was unfetchable when it may have been served fine but simply declared no derivation origin. Adds an offline test pinning the value-validation (valid ids pass; empty/junk/absent fail). Full suite: 120 passed. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh
Two wording fixes — the gateway-header check is heuristic and the manifest fetch can error independently of the root probe: - unverified_app_url_error: "couldn't be fetched or declares no derivation origin" instead of implying the manifest was present but empty (the app_url_default+no-evidence signal doesn't guarantee the manifest request succeeded). - resolve_app app_url_default note: "showed evidence of being served from the Internet Computer (its responses carry the gateway's x-ic-canister-id header)" instead of the definitive "IS served", and the same fetched-or-undeclared softening for the manifest. No behavior change; full suite: 120 passed. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh
Collapses the app entry path (name→URL→resolve→discover) into a single
tool, removing the seam where models fabricate a domain instead of
looking it up. open_app(app) takes a NAME or a URL:
- a name / bare host is matched to the known-app registry first, so even
a wrong-TLD guess ("multidex.com") repairs to the canonical URL;
- an explicit https:// URL is honoured as given (reaches the IC-evidence
gate, so a deliberately-typed guess still refuses + repairs);
- a bare unknown name is refused with find-the-real-URL guidance rather
than fabricated into a host.
It then runs resolve_app_identity + discover concurrently and returns
the derivation origin (+ source, alt-origins, application_is_ic) and the
discovered canisters in one object, carrying the same guessed-domain gate
and "did you mean" repair as the granular tools. Discovery is best-effort
(empty/unreachable still yields a valid derivation context). Anonymous;
no principal derived.
The narrower tools (icp_find_app_by_name / resolve_app /
discover_app_canisters) stay for single-step use and remain open_app's
implementation. Server instructions + typical-flow + README now lead with
open_app; the resolve_app note logic is factored into a shared
resolution_note() so both tools stay in lock-step.
New: discover::{classify_app_query, AppQuery, OpenAppArgs, OpenAppOutput};
main::{open_app, resolution_note}. Tests: classifier routing
(name/wrong-TLD/explicit-URL/unknown), tool count 25→26 with open_app in
the read-only set. Full suite: 121 passed.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh
…ters" open_app previously collapsed discover()'s Result with unwrap_or_default, so a DNS/TLS/SSRF discovery failure looked identical to an app that declares no canisters. Now the discovery error is kept distinct: the text says "Canister discovery FAILED (<err>) — NOT 'no canisters'; the derivation origin is still valid; retry", and a new OpenAppOutput.discovery_error field carries it for structured clients (null when discovery succeeded, whether or not it found anything). The derivation context is unaffected (origin resolution succeeds first and already gates bad URLs). Full suite: 121 passed. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh
…efusal - open_app now cleans its `app` query through clean_identity_arg (trim + reject empty + reject control chars), matching the rest of the identity input surface. Previously control chars could be echoed into the UnknownName error via find_app_by_name's note. - Discovery is now spawned and ABORTED when origin resolution fails or the IC-evidence gate refuses, instead of tokio::join! waiting out discovery's timeout against an about-to-be-refused origin. The happy path stays concurrent; a guessed/refused origin returns promptly with no wasted outbound crawl. A discovery JoinError (panic) degrades to a discovery_error, never a hard failure. Full suite: 121 passed. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh
The open_app "Next" line implied run_canister_oql_query accepts app_url, but the OQL tools (run_canister_oql_query / get_canister_oql_schema) take only derivation_origin; app_url is a call_canister parameter. Reworded so call_canister is shown taking app_url OR derivation_origin, and the OQL tools taking derivation_origin — no unsupported-parameter dead end. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh
…irect
The SSRF redirect policy permits hops to global IP literals, so a non-IC
origin could 302 to another public host/IP that echoes a valid
x-ic-canister-id and borrow its IC-ness, wrongly passing the
guessed-domain gate. IC evidence is now counted only when the response
came from the probed origin's own host: split header_is_ic_principal
(value check) from ic_evidence_from(resp, expected_host) (value check AND
resp.url() host == origin host), used by both the manifest and origin-root
probes. Also aligned the README wording ("origin root", value-checked,
from the origin itself — not "the app URL itself").
Full suite: 121 passed.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh
…tool-discovery-si0bx7 # Conflicts: # src/main.rs
ic_evidence_from compared only host_str(), but redirect_hop_ok permits same-host different-PORT redirects, so evidence could be borrowed from a different origin (an origin is scheme+host+port). Now it compares the response's canonical Url::origin().ascii_serialization() against the probed application origin — exact scheme+host+port match, default-port- and case-normalized. Both probe call sites pass application_origin. Full suite: 122 passed. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh
…not prevents) The comment claimed the spawn+abort avoids "crawling a site we're about to reject", but discovery runs concurrently with the gate, so a few requests may already be in flight before abort(). Reworded to state accurately that abort makes a refused origin return promptly and cancels the REST of the crawl (bounded by discover's own caps), and that fully preventing the residual I/O would require serializing resolve+discover — which the happy path would pay for. No behavior change. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh
aterga
pushed a commit
that referenced
this pull request
Jul 16, 2026
Follow-up to the guessed-domain work (#57). The identity-bearing tools no longer accept an `app_url` to auto-resolve — they take ONLY `derivation_origin`: - call_canister, get_app_principal, list_app_accounts: `app_url` removed. - run_canister_oql_query / get_canister_oql_schema were already derivation_origin-only; NOT extended with app_url (the earlier "uniformity via app_url" idea, reversed). Rationale: a derivation origin is a STABLE per-app value, and the server is stateless, so accepting a URL on every call re-resolved it (a network round-trip) every time — and having two ways to identify an app invites the inefficient path. Now the app is resolved ONCE via open_app / resolve_app (which run the guessed-domain gate and return the derivation origin) and that origin is reused across calls. One obvious way in; zero repeated resolution. The guessed-domain gate is unaffected: it lives at the resolver step (open_app/resolve_app), which is on the critical path anyway (you resolve to get the canister id). `derivation_origin` remains trusted verbatim (ungated) — that's the deliberate escape hatch — so this opens no new hole (a fabricated derivation_origin was always ungated); it removes a gated shortcut in favor of efficiency + a single contract. resolve_identity_target is now derivation_origin-only and synchronous; IdentityTarget drops the unused application_origin field; identity_annotation drops its now-unreachable app_url_default branch; derivation_origin_source on these tools is always "explicit" (the declared/known/app_url_default sources are reported by the resolver tools). Tool descriptions, arg schemas, server instructions, and README updated; app_url-path unit tests retargeted to clean_app_url. Full suite: 119 passed. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh
aterga
added a commit
that referenced
this pull request
Jul 17, 2026
…nce, reuse (#64) * Identity tools take derivation_origin only (drop app_url); resolve once Follow-up to the guessed-domain work (#57). The identity-bearing tools no longer accept an `app_url` to auto-resolve — they take ONLY `derivation_origin`: - call_canister, get_app_principal, list_app_accounts: `app_url` removed. - run_canister_oql_query / get_canister_oql_schema were already derivation_origin-only; NOT extended with app_url (the earlier "uniformity via app_url" idea, reversed). Rationale: a derivation origin is a STABLE per-app value, and the server is stateless, so accepting a URL on every call re-resolved it (a network round-trip) every time — and having two ways to identify an app invites the inefficient path. Now the app is resolved ONCE via open_app / resolve_app (which run the guessed-domain gate and return the derivation origin) and that origin is reused across calls. One obvious way in; zero repeated resolution. The guessed-domain gate is unaffected: it lives at the resolver step (open_app/resolve_app), which is on the critical path anyway (you resolve to get the canister id). `derivation_origin` remains trusted verbatim (ungated) — that's the deliberate escape hatch — so this opens no new hole (a fabricated derivation_origin was always ungated); it removes a gated shortcut in favor of efficiency + a single contract. resolve_identity_target is now derivation_origin-only and synchronous; IdentityTarget drops the unused application_origin field; identity_annotation drops its now-unreachable app_url_default branch; derivation_origin_source on these tools is always "explicit" (the declared/known/app_url_default sources are reported by the resolver tools). Tool descriptions, arg schemas, server instructions, and README updated; app_url-path unit tests retargeted to clean_app_url. Full suite: 119 passed. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh * Address review: make derivation_origin a required String on get_app_principal/list_app_accounts These two tools always act as an app account — they errored at runtime when derivation_origin was omitted — but modeling it as Option<String> with #[serde(default)] advertised it as OPTIONAL in the generated MCP schema, so a client/model could omit it and only hit the requirement at call time. It's now a required `String` (keeping the `domain` alias), so the schema marks it required and validation fails up front. Handlers pass Some(derivation_origin) into resolve_identity_target. call_canister keeps Option<String> — there, omitting it is a valid anonymous call. Full suite: 119 passed. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh --------- Co-authored-by: Claude <[email protected]>
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
Given only an app name ("what's my current situation in multidex?"), a model guessed domains —
multidex.com,multidex.app,multi.dex— instead of callingicp_find_app_by_name(which maps "multidex" →https://multidex.aioffline). The connector rewarded the guesses:resolve_appresolved any reachable https origin to a "success" with theapp_url_defaultassumption and a buried note, so the model kept guessing until DNS failed, then gave up and asked the user.An MCP server can't control a model's tool choice, but it can (a) make the wrong path fail loudly and self-correct, and (b) remove the seam where the wrong choice happens. This PR does both.
1. Runtime gate — the guess can no longer succeed
resolve_app_identitygathers IC evidence whenever the derivation origin would have to be assumed (app_url_default): the gateway'sx-ic-canister-idheader — validated as a real canister principal, not merely present — captured for free from theic-app.jsonresponse, with one fallback header-only fetch of the origin root. Declared/known origins skip the probe (no extra latency). A fetch error propagates as an error (an unreachable IC app isn't misclassified as non-IC).An origin with no IC evidence that would need the assumption is refused with a corrective error — by
resolve_app,open_app, and everyapp_urlidentity route (get_app_principal,list_app_accounts,call_canister) — instead of resolving a guessed lookalike to a plausible-but-wrong (or squatter-controlled) identity. A genuinely non-IC-hosted app that uses Internet Identity can still be targeted deliberately via explicitderivation_origin. (This is a heuristic, not a security boundary — headers are forgeable — but it defeats accidental/lazy false positives.)2.
open_app— collapse the entry path so there's no seam to guess inNew one-call tool:
open_app(name-or-URL)resolves the derivation origin and discovers the canisters together (runsresolve_app+discover_app_canistersconcurrently under the hood).multidex.com) repairs to the canonical URL.https://URL → resolved as given (so a deliberately-typed guess still hits the IC-evidence gate + repair on that exact origin).This removes the branch where the model invented a domain: given a name, its only move is to hand the name over. The narrower tools (
icp_find_app_by_name,resolve_app,discover_app_canisters) remain for single-step use and areopen_app's implementation. Accounts/principal stay separate (auth + side effects).3. "Did you mean" repair — one-step convergence
discover::similar_known_app()token-matches a guessed host against the registry (multidex.com/multidex.app/multi.dex→ MULTI/DEX; real hosts and boundary-safe non-matches likenoisy.comreturn nothing). The repair is attached everywhere a guess surfaces: the no-IC-evidence refusal, fetch/DNS errors, emptydiscover_app_canistersresults, and IC-hosted lookalike successes (a CAUTION note).4. Prompt-level steering
Server instructions + typical-flow now lead with
open_appand an explicit "names are not URLs — never fabricate a domain" rule;icp_find_app_by_nameopens with "call this FIRST";resolve_app/discover_app_canistersdescriptions and everyapp_urlarg schema carry the anti-guess directive and mention the refusal.Output shape
ResolveAppOutputgainsapplication_is_ic. NewOpenAppOutputreturnsapp_url(+app_url_source), the derivation context,alternative_origins, and the discoveredcanisters. Theresolve_appnote logic is factored into a sharedresolution_note()soopen_appandresolve_appstay in lock-step.Tests
similar_known_appmatching/boundaries;classify_app_queryrouting (name / wrong-TLD / explicit-URL / unknown);x-ic-canister-idvalue validation; refusal + fetch-error message content.example.com(never IC) refused with guidance; known apps skip the probe; existing discovery/identity suite unchanged.open_appin the read-only set). Full suite: 121 passed, 0 failed.🤖 Generated with Claude Code
https://claude.ai/code/session_01NDKdKM6Nhp3z8xxJEDqToh