I have an app A that allows everybody to create a frontend (assets) canister F and backend canister B.
I’m having a hard time to code user’s ability to create a bookmark storing F # ":" # B in a bookmark.
The problem is that the bookmark should be accessible by the user’s a principal in app A. To reliably authenticate that the user has this principal, need to do it from app A. But to initialize the canister B with a correct owner’s (user’s) principal, need to initialize B in F (not in A) because the owner’s principal is seen only from F. So, only F can initialize B, but this is after the user already left A. How to get value B in A without allowing a hacker to break it?
The best idea that I came up with is: In app A create the canister B but don’t install_code. So, in F we have the principal of B (to compute F # ":" # B). And in F we initialize B with a correct owner. But this idea is convoluted.
Is there a straightforward way to solve this? (maybe, something with identity delegation?)
“do you mean principal obtained from II login?” Yes.
“Are the frontends A and F related to each other, so would it be ok if the user gets the same principal from II in both?” No, because F and B can be created in unlimited quantities by my system and likewise can be created by a hacker who substitutes to B or F malicious code.
Agree. Just wanted to understand a hypothetical solution first that is correct. Then I will propose an improvement that doesn’t require copy & paste.
You mean accidentally or maliciously? Accidentally will be removed by a solution without copy&paste. Maliciously I would say isn’t possible because the user is still logged in on A in the same session that created F an B. So the pasted principal is securely linked to the user on A, to F and to B. You cannot take over someone else’s F and B.
It can be done maliciously, because a user can create a fake (not created by A) pair F:B. Then he uses a wrong idenitity. Also, pasted principal cannot be securely linked to the user on A, because the user can paste any principal.
What do you mean by “the same sessions”? Principals in A and B are different for the same user.
The user is logged in as P1 when he pastes P2. So the call from A’s frontend to A’s backend to submit P2 is made as identity P1. It is not an anonymous call. A’s backend has the map P1 → (F,B) stored. It looks up who called (which is P1), then finds (F,B), then configures B to give access to the pasted principal.