-
Notifications
You must be signed in to change notification settings - Fork 1.2k
HTTP API of jsipfs daemon
rejects IpfsHttpClient access on NW.js window
#3277
Comments
Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review.
Finally, remember to use https://discuss.ipfs.io if you just need general support. |
This is because the request that is sent uses a browser user agent but contains no referrer or origin and fails the test ported from ipfs/go-ipfs-cmds#193 cc @lidel |
@bellbind you need to safelist specific Origin to give it access to the API inside a web browser context: $ jsipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://origin-you-want-to-safelist.example.com", "http://127.0.0.1:5001"]'
$ jsipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "POST"]' Example: $ curl -X POST -A "Mozilla" http://127.0.0.1:5002/api/v0/id
{"Message":"Forbidden","Code":1,"Type":"error
$ curl -X POST -A "Mozilla" -H "Origin: http://origin-you-want-to-safelist.example.com" http://127.0.0.1:5002/api/v0/
{ "ID": ... } |
Until #3275 lands, the CORS origin is effectively set to NW.js is an Electron-like environment that doesn't send a referer or origin and uses a generic browser user agent string (e.g. doesn't append My point is, it's like the electron renderer stuff we discussed on ipfs/go-ipfs-cmds#201 except we can't use the user agent to allow the request through. |
@achingbrain I see – thanks for this context! The way I see it:
|
Even after #3275 ships configuring the CORS allowed origins still won't work because NW.js doesn't send an origin or a referer. What needs to happen is for either NW.js to not use the default user agent since we can't tell it apart from regular browsers, or for us not to use the User Agent to allow or deny requests. @bellbind in the meantime you can work around this by changing the default user agent for outgoing requests. Add a user-agent field to your
|
Thank you @achingbrain. It worked with adding |
- HTTP API of jsipfs requires some `User-Agent` request header field to access - see: ipfs/js-ipfs#3277
Severity: Low
(if HTTP API of jsipfs is optional)
Description:
IpfsHttpClient
on NW.js cannot access HTTP API ofjsipfs daemon
, as:(On Chrome and Firefox, IpfsHttpClient can access HTTP API of same
jsipfs daemon
)Steps to reproduce the error:
IpfsHttpClient
:package.json
:index.html
:npm install
on the directory of thepackage.json
and theindex.html
:$ $(npm bin)/jsipfs daemon Initializing IPFS daemon... js-ipfs version: 0.50.2 System version: x64/darwin Node.js version: 14.9.0 Swarm listening on /ip4/127.0.0.1/tcp/4002/p2p/Qmbywf2eDSoksSj4rBSBfr95Em5naYsg9hhwXGNYfSnYD3 Swarm listening on /ip4/192.168.10.6/tcp/4002/p2p/Qmbywf2eDSoksSj4rBSBfr95Em5naYsg9hhwXGNYfSnYD3 Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/p2p/Qmbywf2eDSoksSj4rBSBfr95Em5naYsg9hhwXGNYfSnYD3 API listening on /ip4/127.0.0.1/tcp/5002/http Gateway (read only) listening on /ip4/127.0.0.1/tcp/9090/http Web UI available at http://127.0.0.1:5002/webui Daemon is ready
index.html
on nw.js:$ $(npm bin)/nw
Then, a main window and a DevTools window are opened.
Console
tab on DevTools window: display above errors:Failed to load resource...
My Experiments:
index.html
works on chrome-87 or on firefox-80:jsipfs daemon
and its Peer ID)Console
tab of DevTools window,await fetch("http://127.0.0.1:8000/", {method: "POST"})
can successfully access to nodejs http server:server.cjs
:fetch
HTTP API URL from the Console tab of Devtools windowThe text was updated successfully, but these errors were encountered: