Skip to content

fix: drop hardcoded host from HttpAgent options in example frontends - #1488

Merged
marc0olo merged 1 commit into
masterfrom
chore/drop-agent-host
Sep 23, 2026
Merged

marc0olo merged 1 commit into
masterfrom
chore/drop-agent-host

Conversation

@marc0olo

@marc0olo marc0olo commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Removes host: window.location.origin from the HttpAgent / createActor options in all example frontends (34 examples).

@icp-sdk/core already resolves the API host from the page: the page origin on localhost (incl. the Vite dev-server proxy), ic0.app and icp0.io, and https://icp-api.io everywhere else. A hardcoded origin breaks frontends served from a custom domain, which doesn't serve /api. The icp-cli skill dropped this pattern for the same reason (dfinity/icskills#303); the examples still carried it from before.

Since calls no longer always go to the page origin (localhost:8000 locally, icp-api.io on icp.net), rust/qrcode and rust/image-classification extend their CSP connect-src. Without that, local calls are blocked (reproduced on qrcode). The other CSPs already allow both.

Tested locally in a browser: motoko/hello_world and rust/qrcode. All touched frontends build. Mainnet not tested.

The Internet Identity auth client got the same change in #1487 (merged); this PR is rebased on it.

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.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified that would block approval.

Review effort: Lite
Findings: None

What changed in this PR

Removes hardcoded window.location.origin API hosts so SDK host resolution works on custom domains, with CSP updates for local/API endpoints.

Changes:

  • Removes hardcoded hosts from Motoko and Rust frontend agents.
  • Removes obsolete host wiring from motoko/ic-pos.
  • Expands CSP connect-src for qrcode and image-classification.
File Description
rust/​who_am_i/​src/​frontend/​src/​actor.js Updated as part of this pull request.
rust/​vetkeys/​password_manager/​frontend/​src/​lib/​encrypted_maps.ts Updated as part of this pull request.
rust/​vetkeys/​password_manager_with_metadata/​frontend/​src/​lib/​password_manager.ts Updated as part of this pull request.
rust/​vetkeys/​encrypted_notes_app_vetkd/​frontend/​src/​lib/​actor.ts Updated as part of this pull request.
rust/​vetkeys/​basic_vetkd/​frontend/​src/​main.js Updated as part of this pull request.
rust/​vetkeys/​basic_timelock_ibe/​frontend/​src/​main.ts Updated as part of this pull request.
rust/​vetkeys/​basic_ibe/​frontend/​src/​main.ts Updated as part of this pull request.
rust/​vetkeys/​basic_bls_signing/​frontend/​src/​main.ts Updated as part of this pull request.
rust/​qrcode/​frontend/​src/​actor.js Updated as part of this pull request.
rust/​qrcode/​frontend/​public/​_headers Updated as part of this pull request.
rust/​photo_gallery/​frontend/​src/​actor.ts Updated as part of this pull request.
rust/​llm_chatbot/​frontend/​src/​actor.js Updated as part of this pull request.
rust/​image-classification/​frontend/​src/​actor.js Updated as part of this pull request.
rust/​image-classification/​frontend/​public/​_headers Updated as part of this pull request.
rust/​hello_world/​frontend/​src/​actor.js Updated as part of this pull request.
rust/​flying_ninja/​frontend/​src/​actor.js Updated as part of this pull request.
rust/​face-recognition/​frontend/​src/​actor.js Updated as part of this pull request.
rust/​evm_block_explorer/​frontend/​src/​actor.js Updated as part of this pull request.
rust/​daily_planner/​frontend/​src/​actor.js Updated as part of this pull request.
motoko/​who_am_i/​src/​frontend/​src/​actor.js Updated as part of this pull request.
motoko/​vetkeys/​password_manager/​frontend/​src/​lib/​encrypted_maps.ts Updated as part of this pull request.
motoko/​vetkeys/​password_manager_with_metadata/​frontend/​src/​lib/​password_manager.ts Updated as part of this pull request.
motoko/​vetkeys/​encrypted_notes_app_vetkd/​frontend/​src/​lib/​actor.ts Updated as part of this pull request.
motoko/​vetkeys/​basic_vetkd/​frontend/​src/​main.js Updated as part of this pull request.
motoko/​vetkeys/​basic_ibe/​frontend/​src/​main.ts Updated as part of this pull request.
motoko/​vetkeys/​basic_bls_signing/​frontend/​src/​main.ts Updated as part of this pull request.
motoko/​superheroes/​frontend/​src/​actor.js Updated as part of this pull request.
motoko/​random_maze/​frontend/​src/​actor.js Updated as part of this pull request.
motoko/​llm_chatbot/​frontend/​src/​actor.js Updated as part of this pull request.
motoko/​ic-pos/​frontend/​src/​lib/​env.ts Updated as part of this pull request.
motoko/​ic-pos/​frontend/​src/​actors.tsx Updated as part of this pull request.
motoko/​hello_world/​frontend/​src/​actor.js Updated as part of this pull request.
motoko/​flying_ninja/​frontend/​src/​actor.js Updated as part of this pull request.
motoko/​filevault/​frontend/​src/​actor.js Updated as part of this pull request.
motoko/​evm_block_explorer/​frontend/​src/​actor.js Updated as part of this pull request.
motoko/​daily_planner/​frontend/​src/​actor.js Updated as part of this pull request.
motoko/​cert-var/​frontend/​src/​actor.js Updated as part of this pull request.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@marc0olo
marc0olo marked this pull request as ready for review September 23, 2026 12:47
@marc0olo
marc0olo requested review from a team as code owners September 23, 2026 12:47
@icp-sdk/core resolves the API host from the page: the page origin on
localhost, ic0.app and icp0.io, and https://icp-api.io elsewhere. A
hardcoded window.location.origin breaks frontends served from a custom
domain, which does not serve /api.

qrcode and image-classification extend connect-src, since calls now leave
the page origin (localhost:8000 locally, icp-api.io on icp.net).
@marc0olo
marc0olo force-pushed the chore/drop-agent-host branch from e0cddec to cec8fc3 Compare September 23, 2026 14:15
@marc0olo
marc0olo merged commit 9720f12 into master Sep 23, 2026
39 checks passed
@marc0olo
marc0olo deleted the chore/drop-agent-host branch September 23, 2026 15:24
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.

4 participants