Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning about mixed content issues #650

Merged
merged 4 commits into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions add-on/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@
"message": "URL of preferred HTTP2IPFS Gateway",
"description": "An option description on the Preferences screen (option_customGatewayUrl_description)"
},
"option_customGatewayUrl_warning": {
"message": "IPFS content will be blocked from loading on HTTPS websites unless your gateway URL starts with “http://127.0.0.1”, “http://[::1]” or “https://”",
"description": "A warning on the Preferences screen, displayed when URL does not belong to Secure Context (option_customGatewayUrl_warning)"
},
"option_useCustomGateway_title": {
"message": "Use Custom Gateway",
"description": "An option title on the Preferences screen (option_useCustomGateway_title)"
Expand Down
10 changes: 9 additions & 1 deletion add-on/src/options/forms/gateways-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const browser = require('webextension-polyfill')
const html = require('choo/html')
const { normalizeGatewayURL } = require('../../lib/options')

// Warn about mixed content issues when changing the gateway
// https://github.com/ipfs-shipyard/ipfs-companion/issues/648
const secureContextUrl = /^https:\/\/|^http:\/\/127.0.0.1|^http:\/\/\[::1\]/

function gatewaysForm ({
ipfsNodeType,
customGatewayUrl,
Expand All @@ -15,6 +19,7 @@ function gatewaysForm ({
const onCustomGatewayUrlChange = onOptionChange('customGatewayUrl', normalizeGatewayURL)
const onUseCustomGatewayChange = onOptionChange('useCustomGateway')
const onPublicGatewayUrlChange = onOptionChange('publicGatewayUrl', normalizeGatewayURL)
const mixedContentWarning = !secureContextUrl.test(customGatewayUrl)

return html`
<form>
Expand All @@ -25,7 +30,9 @@ function gatewaysForm ({
<label for="customGatewayUrl">
<dl>
<dt>${browser.i18n.getMessage('option_customGatewayUrl_title')}</dt>
<dd>${browser.i18n.getMessage('option_customGatewayUrl_description')}</dd>
<dd>${browser.i18n.getMessage('option_customGatewayUrl_description')}
${mixedContentWarning ? html`<p class="red i">${browser.i18n.getMessage('option_customGatewayUrl_warning')}</p>` : null}
</dd>
</dl>
</label>
<input
Expand All @@ -38,6 +45,7 @@ function gatewaysForm ({
title="Enter URL without any sub-path"
onchange=${onCustomGatewayUrlChange}
value=${customGatewayUrl} />

</div>
` : null}
${ipfsNodeType === 'external' ? html`
Expand Down