Skip to content

Commit

Permalink
Allow Web Editor to connect to localhost from HTTPS context
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Jul 10, 2024
1 parent 6f21718 commit ea7ee46
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/components/ConnectForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,8 @@ export default {
...Utils.mapState(['connectionError', 'authProviders', 'isAuthenticated']),
...Utils.mapGetters(['isConnected', 'isDiscovered', 'title']),
...Utils.mapState('editor', ['storedServers']),
isLocal() {
return Boolean(
window.location.hostname === 'localhost' ||
window.location.hostname === '[::1]' ||
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
);
},
httpsUrl() {
if (this.$config.showHttpWarning && !this.isLocal && window.location.protocol === 'http:') {
if (this.$config.showHttpWarning && !this.isLocalUrl(window.location) && window.location.protocol === 'http:') {
return window.location.toString()
.replace(/^http:/i, 'https:')
.replace(/([\?&]server=http)(:|%3A)/, '$1s$2');
Expand Down Expand Up @@ -244,6 +237,14 @@ export default {
...Utils.mapMutations(['reset']),
...Utils.mapMutations('editor', ['addServer', 'removeServer']),
isLocalUrl(url) {
return Boolean(
url.hostname === 'localhost' ||
url.hostname === '[::1]' ||
url.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
);
},
showHelp() {
if (!this.isConnected) {
this.broadcast('showTour', 'connect');
Expand Down Expand Up @@ -314,11 +315,14 @@ export default {
if (!serverUrl.match(/^https?:\/\//i)) {
serverUrl = `https://${serverUrl}`;
}
if (!Utils.isUrl(serverUrl)) {
Utils.error(this, 'The server given is not a valid URL.');
return;
}
else if (window.location.protocol === 'https:' && serverUrl.toLowerCase().substr(0,6) !== 'https:') {
const url = new URL(serverUrl);
if (window.location.protocol === 'https:' && url.protocol !== 'https:' && !this.isLocalUrl(url)) {
Utils.error(this, 'You are trying to connect to a server with HTTP instead of HTTPS, which is insecure and prohibited by web browsers. Please use HTTPS instead.');
return;
}
Expand Down

0 comments on commit ea7ee46

Please sign in to comment.