diff --git a/appveyor.yml b/appveyor.yml index 7d0499c69..b15cd2620 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,7 +13,7 @@ init: - git config --global core.autocrlf input install: - - ps: Install-Product node 10 x64 + - ps: Install-Product node 12 x64 - npm install build_script: diff --git a/package.json b/package.json index 9e5c44673..1ba3d2112 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "start": "cross-env NODE_ENV=development electron src/index.js", "lint": "standard", "test": "cross-env NODE_ENV=test mocha test/unit/**/*.spec.js", - "test:e2e": "xvfb-maybe cross-env NODE_ENV=test mocha test/e2e/**/*.e2e.js --exit", + "test:e2e": "xvfb-maybe cross-env NODE_ENV=test LIBP2P_ALLOW_WEAK_RSA_KEYS=1 mocha test/e2e/**/*.e2e.js --exit", "postinstall": "run-s install-app-deps build:webui", "install-app-deps": "electron-builder install-app-deps", "clean:webui": "shx rm -rf assets/webui/", @@ -102,6 +102,6 @@ "yargs": "^15.3.1" }, "go-ipfs": { - "version": "v0.4.23" + "version": "v0.5.0-rc3" } } diff --git a/src/daemon/config.js b/src/daemon/config.js index 1954bd6c8..a3d329e28 100644 --- a/src/daemon/config.js +++ b/src/daemon/config.js @@ -109,7 +109,7 @@ const parseCfgMultiaddr = (addr) => (addr.includes('/http') async function checkIfAddrIsDaemon (addr) { const options = { - method: 'GET', + method: 'POST', host: addr.address, port: addr.port, path: '/api/v0/refs?arg=/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' diff --git a/src/webui/index.js b/src/webui/index.js index 8de0c76d0..b3a7b31ac 100644 --- a/src/webui/index.js +++ b/src/webui/index.js @@ -1,12 +1,14 @@ const { screen, BrowserWindow, ipcMain, app, session } = require('electron') const { join } = require('path') const { URL } = require('url') +const toUri = require('multiaddr-to-uri') const serve = require('electron-serve') const os = require('os') const openExternal = require('./open-external') const logger = require('../common/logger') const store = require('../common/store') const dock = require('../utils/dock') +const { VERSION } = require('../common/consts') serve({ scheme: 'webui', directory: join(__dirname, '../../assets/webui') }) @@ -59,6 +61,16 @@ const createWindow = () => { return window } +// Converts a Multiaddr to a valid value for Origin HTTP header +const apiOrigin = (apiMultiaddr) => { + // Return opaque origin when there is no API yet + // https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque + if (!apiMultiaddr) return 'null' + // Return the Origin of HTTP API + const apiUri = toUri(apiMultiaddr, { assumeHttp: true }) + return new URL(apiUri).origin +} + module.exports = async function (ctx) { openExternal() @@ -109,7 +121,9 @@ module.exports = async function (ctx) { }) session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => { - delete details.requestHeaders.Origin + // Avoid setting CORS by acting like /webui loaded from API port + details.requestHeaders.Origin = apiOrigin(apiAddress) + details.requestHeaders['User-Agent'] = `ipfs-desktop/${VERSION}` callback({ cancel: false, requestHeaders: details.requestHeaders }) // eslint-disable-line })