Skip to content

Expose IPFS API as window.ipfs #330

@lidel

Description

@lidel

There is an area of interest that can be summarized as..

..exposing a subset of IPFS APIs as window.ipfs on every webpage ✨

tl;dr If we have it, websites could detect that window.ipfs already exists and use it instead of spawning own js-ipfs node (saves resources, battery etc).

We had discussions in ipfs-inactive/js-ipfs-http-client#387 and #37, ipfs/in-web-browsers#9, ipfs/in-web-browsers#35 but the consensus at the time was that it is not safe without some kind of access-control (eg. via proposed API Tokens: ipfs/kubo#1532).

@victorbjelkholm suggested a simple solution to the lack of access controls in the API itself:
On the first use of window.ipfs user could be prompted with something like "Do you want to allow scripts at <website> to access API of your IPFS node?". The choice would be remembered eg. for the page til the end of browsing session. There could also be an additional "remember for this site" checkbox to make UX better for users who wants to make permission persist between browser restarts.

Tasks

  • Create a content script that creates a proxy object under window.ipfs of the page it is injected into
    • This object should expose a subset of IPFS APIs

      <victorbjelkholm> there is of course a lot more once there is a full ipfs node in the browser, but if we only have the simplest and most useful functions (add, cat, pubsub subscribe/publish, dag get/put), it suddenly becomes a lot simpler and useful quickly

    • Operations performed on window.ipfs should be proxied to the real IPFS API object present in webextension's Background page (requires robust (de)serialization, we don't want to mangle upload data etc)
    • First use of window.ipfs should trigger a dialog where user confirms that access to IPFS API is granted to requesting site (and decides if permission is for this session only or permanent)
  • Add a checkbox under "Preferences/Experiments" to control if content script is injected to every visited page, make it disabled by default initially
  • Write documentation, namely provide code snippet that enables apps to use the IPFS Companion IPFS node if it is available

Potential problems

  • Something to investigate and solve before we make window.ipfs enabled by default: make sure it is not possible for a website to approve itself 🙃 This may mean we can't inject dialog to the tab itself and the dialog needs to be displayed in a new Tab or via other means.

Metadata

Metadata

Assignees

Labels

area/window-ipfsIssues related to IPFS API exposed on every pagekind/enhancementA net-new feature or improvement to an existing featurestatus/in-progressIn progresstopic/securityWork related to security

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions