Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit 6b0d144

Browse files
committed
Replace noscript with javascript content setting
Fix #2671 Follow-up: restore the 'Allow scripts once' functionality Auditors: @bbondy, @bridiver
1 parent 440e93f commit 6b0d144

File tree

9 files changed

+36
-135
lines changed

9 files changed

+36
-135
lines changed

app/extensions.js

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ let generateBraveManifest = () => {
5353
'content/scripts/adInsertion.js',
5454
'content/scripts/passwordManager.js',
5555
'content/scripts/flashListener.js',
56+
'content/scripts/noScript.js',
5657
'content/scripts/themeColor.js'
5758
]
5859
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
if (chrome.contentSettings.javascript == 'block') {
6+
document.querySelectorAll('script').forEach((s) => {
7+
// TODO: Send all of these in one IPC call
8+
chrome.ipc.sendToHost('scripts-blocked',
9+
s.src ? s.src : window.location.href)
10+
})
11+
}

app/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const PackageLoader = require('./package-loader')
3030
const Extensions = require('./extensions')
3131
const Filtering = require('./filtering')
3232
const TrackingProtection = require('./trackingProtection')
33-
const NoScript = require('./noScript')
3433
const AdBlock = require('./adBlock')
3534
const HttpsEverywhere = require('./httpsEverywhere')
3635
const SiteHacks = require('./siteHacks')
@@ -366,7 +365,6 @@ app.on('ready', () => {
366365
Extensions.init()
367366
Filtering.init()
368367
SiteHacks.init()
369-
NoScript.init()
370368
spellCheck.init()
371369
HttpsEverywhere.init()
372370
TrackingProtection.init()

app/noScript.js

-92
This file was deleted.

js/components/frame.js

+5-19
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const debounce = require('../lib/debounce.js')
2525
const getSetting = require('../settings').getSetting
2626
const settings = require('../constants/settings')
2727
const FindBar = require('./findbar.js')
28-
const consoleStrings = require('../constants/console')
2928
const { aboutUrls, isSourceAboutUrl, isTargetAboutUrl, getTargetAboutUrl, getBaseUrl } = require('../lib/appUrlUtil')
3029
const { isFrameError } = require('../lib/errorUtil')
3130
const locale = require('../l10n')
@@ -503,6 +502,11 @@ class Frame extends ImmutableComponent {
503502
windowActions.setBlockedBy(this.props.frame, 'fingerprintingProtection', description)
504503
}
505504
break
505+
case messages.SCRIPTS_BLOCKED:
506+
method = (src) => {
507+
windowActions.setBlockedBy(this.props.frame, 'noScript', src)
508+
}
509+
break
506510
case messages.THEME_COLOR_COMPUTED:
507511
method = (computedThemeColor) =>
508512
windowActions.setThemeColor(this.props.frame, undefined, computedThemeColor || null)
@@ -737,14 +741,6 @@ class Frame extends ImmutableComponent {
737741
this.webview.addEventListener('media-paused', ({title}) => {
738742
windowActions.setAudioPlaybackActive(this.props.frame, false)
739743
})
740-
this.webview.addEventListener('console-message', (e) => {
741-
if (this.props.enableNoScript && e.level === 2 &&
742-
e.message && e.message.includes(consoleStrings.SCRIPT_BLOCKED)) {
743-
// Note that the site was blocked
744-
windowActions.setBlockedBy(this.props.frame,
745-
'noScript', this.getScriptLocation(e.message))
746-
}
747-
})
748744
this.webview.addEventListener('did-change-theme-color', ({themeColor}) => {
749745
// Due to a bug in Electron, after navigating to a page with a theme color
750746
// to a page without a theme color, the background is sent to us as black
@@ -772,16 +768,6 @@ class Frame extends ImmutableComponent {
772768
this.webview.addEventListener('mousewheel', this.onMouseWheel.bind(this))
773769
}
774770

775-
getScriptLocation (msg) {
776-
const defaultMsg = '[Inline script]'
777-
if (msg.includes(consoleStrings.EXTERNAL_SCRIPT_BLOCKED)) {
778-
let match = /'.+?'/.exec(msg)
779-
return match ? match[0].replace(/'/g, '') : defaultMsg
780-
} else {
781-
return defaultMsg
782-
}
783-
}
784-
785771
goBack () {
786772
this.webview.goBack()
787773
}

js/components/noScriptInfo.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,12 @@ class NoScriptInfo extends ImmutableComponent {
5050
<div>
5151
<div className='truncate' data-l10n-args={JSON.stringify(l10nArgs)}
5252
data-l10n-id={this.numberBlocked === 1 ? 'scriptBlocked' : 'scriptsBlocked'} />
53-
<div>
54-
<Button l10nId='allowScriptsOnce' className='actionButton'
55-
onClick={this.onAllowOnce.bind(this)} />
56-
</div>
5753
<div>
5854
{
55+
// TODO: restore the allow-once button
5956
// TODO: If this is a private tab, this should only allow scripts
6057
// temporarily. Depends on #1824
61-
<Button l10nId='allowScripts' className='subtleButton'
58+
<Button l10nId='allow' className='actionButton'
6259
onClick={this.onAllow.bind(this, false)} />
6360
}
6461
</div>

js/constants/console.js

-13
This file was deleted.

js/constants/messages.js

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const messages = {
6868
APP_STATE_CHANGE: _,
6969
STOP_LOAD: _,
7070
THEME_COLOR_COMPUTED: _,
71+
SCRIPTS_BLOCKED: _, /** @arg {string} src */
7172
HIDE_CONTEXT_MENU: _,
7273
LEAVE_FULL_SCREEN: _,
7374
ENTER_FULL_SCREEN: _,

js/state/contentSettings.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,18 @@ const getContentSettingsFromSiteSettings = (appState) => {
7979
setting: getPasswordManagerEnabled(appState) ? 'allow' : 'block',
8080
primaryPattern: '*'
8181
}],
82-
javascript: [],
82+
javascript: [{
83+
setting: braveryDefaults.noScript ? 'block' : 'allow',
84+
primaryPattern: '*'
85+
}, {
86+
setting: 'allow',
87+
secondaryPattern: '*',
88+
primaryPattern: 'file:///*'
89+
}, {
90+
setting: 'allow',
91+
secondaryPattern: '*',
92+
primaryPattern: 'chrome-extension://*'
93+
}],
8394
canvasFingerprinting: [{
8495
setting: braveryDefaults.fingerprintingProtection ? 'block' : 'allow',
8596
primaryPattern: '*'
@@ -97,9 +108,10 @@ const getContentSettingsFromSiteSettings = (appState) => {
97108
let hostSettings = appState.get('siteSettings').toJS()
98109
for (var hostPattern in hostSettings) {
99110
let hostSetting = hostSettings[hostPattern]
100-
if (hostSetting.noScript) {
101-
// TODO(bridiver) - enable this when we support temporary overrides
102-
// addContentSettings(contentSettings.javascript, hostPattern)
111+
if (typeof hostSetting.noScript === 'boolean') {
112+
// TODO: support temporary override
113+
addContentSettings(contentSettings.javascript, hostPattern, '*',
114+
hostSetting.noScript ? 'block' : 'allow')
103115
}
104116
if (hostSetting.cookieControl) {
105117
if (hostSetting.cookieControl === 'block3rdPartyCookie') {

0 commit comments

Comments
 (0)