Skip to content

Commit

Permalink
fix brave#2988, unblocking of scripts from urls containing ip addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
evq committed Feb 25, 2017
1 parent b9d6361 commit a270a24
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
7 changes: 6 additions & 1 deletion js/state/contentSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
44 changes: 44 additions & 0 deletions test/components/noScriptInfoTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

0 comments on commit a270a24

Please sign in to comment.