From a270a24b911ea833ec5087b3f0552bcb481b1711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eV=20=28=E3=8B=8E=29?= Date: Sat, 25 Feb 2017 01:36:39 +0000 Subject: [PATCH] fix #2988, unblocking of scripts from urls containing ip addresses --- js/state/contentSettings.js | 7 ++++- test/components/noScriptInfoTest.js | 44 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/js/state/contentSettings.js b/js/state/contentSettings.js index cf1616ba762..b7a788d7986 100644 --- a/js/state/contentSettings.js +++ b/js/state/contentSettings.js @@ -18,12 +18,17 @@ const siteSettings = require('./siteSettings') const {registerUserPrefs} = require('./userPrefs') const {getSetting} = require('../settings') const {getFlashResourceId} = require('../flash') +const net = require('net') // backward compatibility with appState siteSettings const parseSiteSettingsPattern = (pattern) => { let normalizedPattern = pattern.replace('https?', 'https') let parsed = urlParse(normalizedPattern) - return '[*.]' + parsed.host + if (net.isIP(parsed.hostname)) { + return parsed.host + } else { + return '[*.]' + parsed.host + } } const toContentSetting = (primaryPattern, secondaryPattern = undefined, setting = 'block', resourceId = undefined) => { diff --git a/test/components/noScriptInfoTest.js b/test/components/noScriptInfoTest.js index 7d9f2b54b29..96f69c8a8ca 100644 --- a/test/components/noScriptInfoTest.js +++ b/test/components/noScriptInfoTest.js @@ -74,4 +74,48 @@ describe('noscript info', function () { .loadUrl(this.url) .waitForTextValue(result, '2') }) + + it('can allow scripts when the url host is an ipv4 address', function * () { + const host = '127.0.0.1' + const modifiedUrl = this.url.replace('localhost', host) + yield this.app.client + .tabByIndex(0) + .loadUrl(modifiedUrl) + .waitForTextValue(result, '0') + .windowByUrl(Brave.browserWindowUrl) + .waitForVisible(noScriptNavButton) + .click(noScriptNavButton) + .waitForVisible(noScriptInfo) + .waitUntil(function () { + return this.getText('.blockedOriginsList') + .then((text) => { return text.includes('http://' + host + ':') }) + }) + .waitForVisible(noScriptAllowOnceButton) + .click(noScriptAllowOnceButton) // unblock cloudflare + .tabByIndex(0) + .loadUrl(modifiedUrl) + .waitForTextValue(result, '2') + }) + + it('can allow scripts when the url host is an ipv6 address', function * () { + const host = '[::1]' + const modifiedUrl = this.url.replace('localhost', host) + yield this.app.client + .tabByIndex(0) + .loadUrl(modifiedUrl) + .waitForTextValue(result, '0') + .windowByUrl(Brave.browserWindowUrl) + .waitForVisible(noScriptNavButton) + .click(noScriptNavButton) + .waitForVisible(noScriptInfo) + .waitUntil(function () { + return this.getText('.blockedOriginsList') + .then((text) => { return text.includes('http://' + host + ':') }) + }) + .waitForVisible(noScriptAllowOnceButton) + .click(noScriptAllowOnceButton) // unblock cloudflare + .tabByIndex(0) + .loadUrl(modifiedUrl) + .waitForTextValue(result, '2') + }) })