Skip to content

Commit 384eb3d

Browse files
authored
improve(internet-identity): add derivationOrigin anti-pattern pitfall (#146)
Add mistake `#7`: icp0.io and ic0.app produce the same principal (II auto-rewrites). Adding derivationOrigin or ii-alternative-origins for this breaks auth. Different principal = different passkey/device. Add eval for the domain equivalence diagnostic scenario. Addresses #136 (F3).
1 parent 76ca0e3 commit 384eb3d

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

evaluations/internet-identity.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@
5959
"Explains that top-level await requires ES2022+ and Vite defaults to es2020",
6060
"Shows a concrete example of wrapping the auth initialization in an async function"
6161
]
62+
},
63+
{
64+
"name": "Different principal after login on icp0.io vs ic0.app",
65+
"prompt": "A user reports getting a different principal when accessing my app via icp0.io compared to ic0.app. Should I add derivationOrigin to fix this?",
66+
"expected_behaviors": [
67+
"Explains that icp0.io and ic0.app produce the same principal — II auto-rewrites icp0.io to ic0.app during delegation",
68+
"Advises NOT to add derivationOrigin or ii-alternative-origins for this",
69+
"Suggests the different principal is likely caused by a different passkey or device"
70+
]
6271
}
6372
],
6473

skills/internet-identity/SKILL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Internet Identity (II) is the Internet Computer's native authentication system.
3939

4040
6. **Passing principal as string to backend.** The `AuthClient` gives you an `Identity` object. Backend canister methods receive the caller principal automatically via the IC protocol -- you do not pass it as a function argument. The caller principal is available on the backend via `shared(msg) { msg.caller }` in Motoko or `ic_cdk::api::msg_caller()` in Rust. For backend access control patterns, see the **canister-security** skill.
4141

42+
7. **Adding `derivationOrigin` or `ii-alternative-origins` to handle `icp0.io` vs `ic0.app`.** Internet Identity automatically rewrites `icp0.io` to `ic0.app` during delegation, so both domains produce the same principal. Do not add `derivationOrigin` or `ii-alternative-origins` configuration to handle this — it will break authentication. If a user reports getting a different principal, the cause is almost certainly a different passkey or device, not the domain.
43+
4244
## Using II during local development
4345

4446
### icp.yaml Configuration

0 commit comments

Comments
 (0)