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

Commit

Permalink
add advanced webrtc IP handling preference
Browse files Browse the repository at this point in the history
fix #13668

Test Plan:
1. go to about:preferences#advanced
2. at the bottom, it should show a webrtc policy select menu which defaults
   to 'default'
3. turn on fingerprinting protection to 'block all'
4. go to https://browserleaks.com/webrtc. it should not show any IPs
5. turn off fingerprinting protection on that page. now it should show IPs
6. in about:preferences#advanced, set webrtc policy to 'default public
   interface only'
7. reload https://browserleaks.com/webrtc. it should only show the
   public IP.
8. in about:preferences#advanced, set webrtc policy to 'disable
   non-proxied UDP'
9. reload https://browserleaks.com/webrtc. it should show no IPs.
10. in about:preferences#advanced, set webrtc policy to 'default public
    and private interfaces'
11. reload https://browserleaks.com/webrtc. it should show both IPs.
  • Loading branch information
diracdeltas committed Apr 10, 2018
1 parent a3d80eb commit 1482a2e
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 10 deletions.
18 changes: 12 additions & 6 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ const updateState = require('../../common/state/updateState')
const appConfig = require('../../../js/constants/appConfig')
const appConstants = require('../../../js/constants/appConstants')
const windowConstants = require('../../../js/constants/windowConstants')
const webrtcConstants = require('../../../js/constants/webrtcConstants')
const dragTypes = require('../../../js/constants/dragTypes')
const tabActionConsts = require('../../common/constants/tabAction')
const appActions = require('../../../js/actions/appActions')
const settings = require('../../../js/constants/settings')

// Utils
const tabs = require('../tabs')
Expand All @@ -37,23 +39,27 @@ const flash = require('../../../js/flash')
const {isSourceAboutUrl, isTargetAboutUrl, isNavigatableAboutPage} = require('../../../js/lib/appUrlUtil')
const {shouldDebugTabEvents} = require('../../cmdLine')

const WEBRTC_DEFAULT = 'default'
const WEBRTC_DISABLE_NON_PROXY = 'disable_non_proxied_udp'

const getWebRTCPolicy = (state, tabId) => {
const webrtcSetting = state.getIn(['settings', settings.WEBRTC_POLICY])
if (webrtcSetting && webrtcSetting !== webrtcConstants.default) {
// Global webrtc setting overrides fingerprinting shield setting
return webrtcSetting
}

const tabValue = tabState.getByTabId(state, tabId)
if (tabValue == null) {
return WEBRTC_DEFAULT
return webrtcConstants.default
}

const allSiteSettings = siteSettingsState.getAllSiteSettings(state, tabValue.get('incognito') === true)
const tabSiteSettings =
siteSettings.getSiteSettingsForURL(allSiteSettings, tabValue.get('url'))
const activeSiteSettings = siteSettings.activeSettings(tabSiteSettings, state, appConfig)

if (!activeSiteSettings || activeSiteSettings.fingerprintingProtection !== true) {
return WEBRTC_DEFAULT
return webrtcConstants.default
} else {
return WEBRTC_DISABLE_NON_PROXY
return webrtcConstants.disableNonProxiedUdp
}
}

Expand Down
6 changes: 5 additions & 1 deletion app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ dashboardShowImages=Show images
dashlane=Dashlane® (requires application)
date=Date
default=Default
default=Default
defaultBrowser=Brave is your default browser.
defaultWalletStatus=Thanks for helping support your favorite websites!
defaultZoomLevel=Default zoom level
deletedSitesHeader=Deleted Sites
disableNonProxiedUdp=Disable non-proxied UDP
disableTitleMode=Always show the URL bar
disconnect=Disconnect
dollarsPaid=Amount
Expand Down Expand Up @@ -262,6 +262,8 @@ promotionClaimedErrorMessage=The promotion has ended.
promotionClaimedErrorText=There may be additional Basic Attention Token promotions in the future so stay tuned
promotionClaimedErrorTitle=Sorry!
protocolRegistrationPermission=Protocol registration
publicOnly=Default public interface only
publicPrivate=Default public and private interfaces
publisher=Site
publisherMediaName={{publisherName}} on {{provider}}
publishers=Publishers
Expand Down Expand Up @@ -390,6 +392,8 @@ viewPaymentHistory= {{date}}
views=Views
visit=visit
visits=Visits
webrtcPolicy=WebRTC IP Handling Policy
webrtcPolicyExplanation=What do these policies mean?
wideURLbar=Use wide URL bar
widevine=Run Google Widevine
widevineSection=Google Widevine Support
33 changes: 33 additions & 0 deletions app/renderer/components/preferences/advancedTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const locale = require('../../../../js/l10n')

// Actions
const {getSetting} = require('../../../../js/settings')
const aboutActions = require('../../../../js/about/aboutActions')

// Components
const {SettingsList, SettingItem, SettingCheckbox} = require('../common/settings')
Expand All @@ -19,6 +20,7 @@ const {DefaultSectionTitle} = require('../common/sectionTitle')

// Constants
const settings = require('../../../../js/constants/settings')
const webrtcConstants = require('../../../../js/constants/webrtcConstants')
const {scaleSize} = require('../../../common/constants/toolbarUserInterfaceScale')

// Utils
Expand Down Expand Up @@ -153,6 +155,30 @@ class AdvancedTab extends ImmutableComponent {
/>
{this.spellCheckLanguages}
</SettingsList>
<DefaultSectionTitle data-l10n-id='webrtcPolicy' />
<SettingsList>
<SettingDropdown
value={(
getSetting(settings.WEBRTC_POLICY, this.props.settings)
)}
onChange={changeSetting.bind(
null,
this.props.onChangeSetting,
settings.WEBRTC_POLICY
)}>
{
Object.keys(webrtcConstants)
.map((policy) => <option data-l10n-id={policy} value={webrtcConstants[policy]} />)
}
</SettingDropdown>
<div
className={css(styles.link)}
data-l10n-id='webrtcPolicyExplanation'
onClick={aboutActions.createTabRequested.bind(null, {
url: 'https://cs.chromium.org/chromium/src/content/public/common/webrtc_ip_handling_policy.h'
})}
/>
</SettingsList>
</main>
<footer className={css(styles.moreInfo)}>
<div data-l10n-id='requiresRestart' className={css(commonStyles.requiresRestart)} />
Expand All @@ -179,6 +205,13 @@ const styles = StyleSheet.create({
marginLeft: '5px'
},

link: {
cursor: 'pointer',
fontSize: '14px',
lineHeight: '3em',
textDecoration: 'underline'
},

moreInfo: {
display: 'flex',
flex: 1,
Expand Down
2 changes: 2 additions & 0 deletions js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
const Immutable = require('immutable')
const {getTargetAboutUrl} = require('../lib/appUrlUtil')
const webrtcConstants = require('./webrtcConstants')

// BRAVE_UPDATE_HOST should be set to the host name for the auto-updater server
const updateHost = process.env.BRAVE_UPDATE_HOST || 'https://laptop-updates.brave.com'
Expand Down Expand Up @@ -217,6 +218,7 @@ module.exports = {
'advanced.toolbar-ui-scale': 'normal',
'advanced.swipe-nav-distance': 101,
'advanced.payments-allow-promotions': true,
'advanced.webrtc.policy': webrtcConstants.default,
'shutdown.clear-history': false,
'shutdown.clear-downloads': false,
'shutdown.clear-cache': false,
Expand Down
1 change: 1 addition & 0 deletions js/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const settings = {
TOOLBAR_UI_SCALE: 'advanced.toolbar-ui-scale',
SWIPE_NAV_DISTANCE: 'advanced.swipe-nav-distance',
PAYMENTS_ALLOW_PROMOTIONS: 'advanced.payments-allow-promotions',
WEBRTC_POLICY: 'advanced.webrtc.policy',
// Sync settings
SYNC_ENABLED: 'sync.enabled',
SYNC_DEVICE_NAME: 'sync.device-name',
Expand Down
21 changes: 21 additions & 0 deletions js/constants/webrtcConstants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

// https://developer.chrome.com/extensions/privacy#type-IPHandlingPolicy
// see src/content/public/common/webrtc_ip_handling_policy.h for descriptions
module.exports = {
// This is the default behavior of Chrome. Currently, WebRTC has the right to
// enumerate all interfaces and bind them to discover public interfaces.
default: 'default',
// WebRTC should only use the default route used by http. This also exposes
// the associated default private address. Default route is the route chosen
// by the OS on a multi-homed endpoint.
publicPrivate: 'default_public_and_private_interfaces',
// WebRTC should only use the default route used by http. This doesn't
// expose any local addresses.
publicOnly: 'default_public_interface_only',
// WebRTC should only use TCP to contact peers or servers unless the proxy
// server supports UDP. This doesn't expose any local addresses either.
disableNonProxiedUdp: 'disable_non_proxied_udp'
}
10 changes: 7 additions & 3 deletions test/unit/app/browser/reducers/tabsReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ describe('tabsReducer unit tests', function () {
useCleanCache: true
})
this.state = Immutable.fromJS({
settings: [],
settings: {
'advanced.webrtc.policy': 'disable_non_proxied_udp'
},
tabs: [{
tabId: 1,
index: 0,
Expand Down Expand Up @@ -80,7 +82,7 @@ describe('tabsReducer unit tests', function () {
isDevToolsFocused: (tabId) => {
return tabId === 1
},
setWebRTCIPHandlingPolicy: sinon.mock(),
setWebRTCIPHandlingPolicy: sinon.spy(),
toggleDevTools: sinon.mock(),
closeTab: sinon.mock(),
moveTo: sinon.mock(),
Expand Down Expand Up @@ -158,7 +160,9 @@ describe('tabsReducer unit tests', function () {
})

it('updates the setWebRTCIPHandlingPolicy', function () {
assert(this.tabsAPI.setWebRTCIPHandlingPolicy.calledOnce)
assert.deepEqual(this.tabsAPI.setWebRTCIPHandlingPolicy.args, [
[1, 'disable_non_proxied_udp']
])
})
})

Expand Down

0 comments on commit 1482a2e

Please sign in to comment.