Skip to content

Commit 06227a2

Browse files
committed
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.
1 parent 8a2a95a commit 06227a2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

add-on/src/lib/ipfs-companion.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ log.error = debug('ipfs-companion:main:error')
88
const browser = require('webextension-polyfill')
99
const toMultiaddr = require('uri-to-multiaddr')
1010
const pMemoize = require('p-memoize')
11-
const { optionDefaults, storeMissingOptions, migrateOptions, guiURLString } = require('./options')
11+
const { optionDefaults, storeMissingOptions, migrateOptions, guiURLString, safeURL } = require('./options')
1212
const { initState, offlinePeerCount } = require('./state')
1313
const { createIpfsPathValidator, sameGateway } = require('./ipfs-path')
1414
const createDnslinkResolver = require('./dnslink')
@@ -626,15 +626,15 @@ module.exports = async function init () {
626626
state[key] = change.newValue
627627
break
628628
case 'ipfsApiUrl':
629-
state.apiURL = new URL(change.newValue)
629+
state.apiURL = safeURL(change.newValue, { useLocalhostName: false }) // go-ipfs returns 403 if IP is beautified to 'localhost'
630630
state.apiURLString = state.apiURL.toString()
631631
shouldRestartIpfsClient = true
632632
break
633633
case 'ipfsApiPollMs':
634634
setApiStatusUpdateInterval(change.newValue)
635635
break
636636
case 'customGatewayUrl':
637-
state.gwURL = new URL(change.newValue)
637+
state.gwURL = safeURL(change.newValue, { useLocalhostName: state.useSubdomains })
638638
state.gwURLString = state.gwURL.toString()
639639
break
640640
case 'publicGatewayUrl':

0 commit comments

Comments
 (0)