From 06227a244d357e2969b52f01dda8ee13df286446 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Mon, 6 Apr 2020 18:24:22 +0200 Subject: [PATCH] fix: use safeURLs for api and local gw This fixes webui when embedded js-ifps is used in Brave. Without normalization, state.webuiRootUrl used 127.0.0.1 while gw one was localhost, and the script responsible for pointing webui at the correct (non-5001) API port was not called because webui root did not match. --- add-on/src/lib/ipfs-companion.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/add-on/src/lib/ipfs-companion.js b/add-on/src/lib/ipfs-companion.js index 33173b454..92ddbd78a 100644 --- a/add-on/src/lib/ipfs-companion.js +++ b/add-on/src/lib/ipfs-companion.js @@ -8,7 +8,7 @@ log.error = debug('ipfs-companion:main:error') const browser = require('webextension-polyfill') const toMultiaddr = require('uri-to-multiaddr') const pMemoize = require('p-memoize') -const { optionDefaults, storeMissingOptions, migrateOptions, guiURLString } = require('./options') +const { optionDefaults, storeMissingOptions, migrateOptions, guiURLString, safeURL } = require('./options') const { initState, offlinePeerCount } = require('./state') const { createIpfsPathValidator, sameGateway } = require('./ipfs-path') const createDnslinkResolver = require('./dnslink') @@ -626,7 +626,7 @@ module.exports = async function init () { state[key] = change.newValue break case 'ipfsApiUrl': - state.apiURL = new URL(change.newValue) + state.apiURL = safeURL(change.newValue, { useLocalhostName: false }) // go-ipfs returns 403 if IP is beautified to 'localhost' state.apiURLString = state.apiURL.toString() shouldRestartIpfsClient = true break @@ -634,7 +634,7 @@ module.exports = async function init () { setApiStatusUpdateInterval(change.newValue) break case 'customGatewayUrl': - state.gwURL = new URL(change.newValue) + state.gwURL = safeURL(change.newValue, { useLocalhostName: state.useSubdomains }) state.gwURLString = state.gwURL.toString() break case 'publicGatewayUrl':