mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Adding setting for disabling Eth Phishing Detection (#8125)
This commit is contained in:
parent
f5f6f7b2d5
commit
64aef5033d
@ -1553,6 +1553,12 @@
|
|||||||
"usedByClients": {
|
"usedByClients": {
|
||||||
"message": "Used by a variety of different clients"
|
"message": "Used by a variety of different clients"
|
||||||
},
|
},
|
||||||
|
"usePhishingDetection": {
|
||||||
|
"message": "Use Phishing Detection"
|
||||||
|
},
|
||||||
|
"usePhishingDetectionDescription": {
|
||||||
|
"message": "Display a warning for phishing domains targeting Ethereum users"
|
||||||
|
},
|
||||||
"userName": {
|
"userName": {
|
||||||
"message": "Username"
|
"message": "Username"
|
||||||
},
|
},
|
||||||
|
@ -36,6 +36,7 @@ class PreferencesController {
|
|||||||
suggestedTokens: {},
|
suggestedTokens: {},
|
||||||
useBlockie: false,
|
useBlockie: false,
|
||||||
useNonceField: false,
|
useNonceField: false,
|
||||||
|
usePhishDetect: true,
|
||||||
|
|
||||||
// WARNING: Do not use feature flags for security-sensitive things.
|
// WARNING: Do not use feature flags for security-sensitive things.
|
||||||
// Feature flag toggling is available in the global namespace
|
// Feature flag toggling is available in the global namespace
|
||||||
@ -103,6 +104,16 @@ class PreferencesController {
|
|||||||
this.store.updateState({ useNonceField: val })
|
this.store.updateState({ useNonceField: val })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for the `usePhishDetect` property
|
||||||
|
*
|
||||||
|
* @param {boolean} val - Whether or not the user prefers phishing domain protection
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
setUsePhishDetect (val) {
|
||||||
|
this.store.updateState({ usePhishDetect: val })
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setter for the `participateInMetaMetrics` property
|
* Setter for the `participateInMetaMetrics` property
|
||||||
*
|
*
|
||||||
|
@ -446,6 +446,7 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
setCurrentCurrency: this.setCurrentCurrency.bind(this),
|
setCurrentCurrency: this.setCurrentCurrency.bind(this),
|
||||||
setUseBlockie: this.setUseBlockie.bind(this),
|
setUseBlockie: this.setUseBlockie.bind(this),
|
||||||
setUseNonceField: this.setUseNonceField.bind(this),
|
setUseNonceField: this.setUseNonceField.bind(this),
|
||||||
|
setUsePhishDetect: this.setUsePhishDetect.bind(this),
|
||||||
setIpfsGateway: this.setIpfsGateway.bind(this),
|
setIpfsGateway: this.setIpfsGateway.bind(this),
|
||||||
setParticipateInMetaMetrics: this.setParticipateInMetaMetrics.bind(this),
|
setParticipateInMetaMetrics: this.setParticipateInMetaMetrics.bind(this),
|
||||||
setMetaMetricsSendCount: this.setMetaMetricsSendCount.bind(this),
|
setMetaMetricsSendCount: this.setMetaMetricsSendCount.bind(this),
|
||||||
@ -1470,9 +1471,10 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
* @param {MessageSender} sender - The sender of the messages on this stream
|
* @param {MessageSender} sender - The sender of the messages on this stream
|
||||||
*/
|
*/
|
||||||
setupUntrustedCommunication (connectionStream, sender) {
|
setupUntrustedCommunication (connectionStream, sender) {
|
||||||
|
const { usePhishDetect } = this.preferencesController.store.getState()
|
||||||
const hostname = (new URL(sender.url)).hostname
|
const hostname = (new URL(sender.url)).hostname
|
||||||
// Check if new connection is blacklisted
|
// Check if new connection is blacklisted if phishing detection is on
|
||||||
if (this.phishingController.test(hostname)) {
|
if (usePhishDetect && this.phishingController.test(hostname)) {
|
||||||
log.debug('MetaMask - sending phishing warning for', hostname)
|
log.debug('MetaMask - sending phishing warning for', hostname)
|
||||||
this.sendPhishingWarning(connectionStream, hostname)
|
this.sendPhishingWarning(connectionStream, hostname)
|
||||||
return
|
return
|
||||||
@ -1988,6 +1990,20 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether or not to use phishing detection.
|
||||||
|
* @param {boolean} val
|
||||||
|
* @param {Function} cb
|
||||||
|
*/
|
||||||
|
setUsePhishDetect (val, cb) {
|
||||||
|
try {
|
||||||
|
this.preferencesController.setUsePhishDetect(val)
|
||||||
|
cb(null)
|
||||||
|
} catch (err) {
|
||||||
|
cb(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the IPFS gateway to use for ENS content resolution.
|
* Sets the IPFS gateway to use for ENS content resolution.
|
||||||
* @param {string} val - the host of the gateway to set
|
* @param {string} val - the host of the gateway to set
|
||||||
|
@ -110,7 +110,8 @@
|
|||||||
"suggestedTokens": {},
|
"suggestedTokens": {},
|
||||||
"tokens": [],
|
"tokens": [],
|
||||||
"useBlockie": false,
|
"useBlockie": false,
|
||||||
"useNonceField": false
|
"useNonceField": false,
|
||||||
|
"usePhishDetect": true
|
||||||
},
|
},
|
||||||
"config": {},
|
"config": {},
|
||||||
"firstTimeInfo": {
|
"firstTimeInfo": {
|
||||||
|
@ -543,5 +543,17 @@ describe('preferences controller', function () {
|
|||||||
assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [])
|
assert.deepEqual(preferencesController.store.getState().frequentRpcListDetail, [])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
|
describe('setUsePhishDetect', function () {
|
||||||
|
it('should default to true', function () {
|
||||||
|
const state = preferencesController.store.getState()
|
||||||
|
assert.equal(state.usePhishDetect, true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should set the usePhishDetect property in state', function () {
|
||||||
|
assert.equal(preferencesController.store.getState().usePhishDetect, true)
|
||||||
|
preferencesController.setUsePhishDetect(false)
|
||||||
|
assert.equal(preferencesController.store.getState().usePhishDetect, false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
@ -13,10 +13,12 @@ export default class SecurityTab extends PureComponent {
|
|||||||
static propTypes = {
|
static propTypes = {
|
||||||
warning: PropTypes.string,
|
warning: PropTypes.string,
|
||||||
history: PropTypes.object,
|
history: PropTypes.object,
|
||||||
participateInMetaMetrics: PropTypes.bool,
|
participateInMetaMetrics: PropTypes.bool.isRequired,
|
||||||
setParticipateInMetaMetrics: PropTypes.func,
|
setParticipateInMetaMetrics: PropTypes.func.isRequired,
|
||||||
showIncomingTransactions: PropTypes.bool,
|
showIncomingTransactions: PropTypes.bool.isRequired,
|
||||||
setShowIncomingTransactionsFeatureFlag: PropTypes.func,
|
setShowIncomingTransactionsFeatureFlag: PropTypes.func.isRequired,
|
||||||
|
setUsePhishDetect: PropTypes.func.isRequired,
|
||||||
|
usePhishDetect: PropTypes.bool.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
renderSeedWords () {
|
renderSeedWords () {
|
||||||
@ -105,6 +107,32 @@ export default class SecurityTab extends PureComponent {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderPhishingDetectionToggle () {
|
||||||
|
const { t } = this.context
|
||||||
|
const { usePhishDetect, setUsePhishDetect } = this.props
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="settings-page__content-row">
|
||||||
|
<div className="settings-page__content-item">
|
||||||
|
<span>{ t('usePhishingDetection') }</span>
|
||||||
|
<div className="settings-page__content-description">
|
||||||
|
{ t('usePhishingDetectionDescription') }
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="settings-page__content-item">
|
||||||
|
<div className="settings-page__content-item-col">
|
||||||
|
<ToggleButton
|
||||||
|
value={usePhishDetect}
|
||||||
|
onToggle={(value) => setUsePhishDetect(!value)}
|
||||||
|
offLabel={t('off')}
|
||||||
|
onLabel={t('on')}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
renderContent () {
|
renderContent () {
|
||||||
const { warning } = this.props
|
const { warning } = this.props
|
||||||
|
|
||||||
@ -113,6 +141,7 @@ export default class SecurityTab extends PureComponent {
|
|||||||
{ warning && <div className="settings-tab__error">{ warning }</div> }
|
{ warning && <div className="settings-tab__error">{ warning }</div> }
|
||||||
{ this.renderSeedWords() }
|
{ this.renderSeedWords() }
|
||||||
{ this.renderIncomingTransactionsOptIn() }
|
{ this.renderIncomingTransactionsOptIn() }
|
||||||
|
{ this.renderPhishingDetectionToggle() }
|
||||||
{ this.renderMetaMetricsOptIn() }
|
{ this.renderMetaMetricsOptIn() }
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -5,6 +5,7 @@ import { withRouter } from 'react-router-dom'
|
|||||||
import {
|
import {
|
||||||
setFeatureFlag,
|
setFeatureFlag,
|
||||||
setParticipateInMetaMetrics,
|
setParticipateInMetaMetrics,
|
||||||
|
setUsePhishDetect,
|
||||||
} from '../../../store/actions'
|
} from '../../../store/actions'
|
||||||
|
|
||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
@ -14,12 +15,14 @@ const mapStateToProps = (state) => {
|
|||||||
showIncomingTransactions,
|
showIncomingTransactions,
|
||||||
} = {},
|
} = {},
|
||||||
participateInMetaMetrics,
|
participateInMetaMetrics,
|
||||||
|
usePhishDetect,
|
||||||
} = metamask
|
} = metamask
|
||||||
|
|
||||||
return {
|
return {
|
||||||
warning,
|
warning,
|
||||||
showIncomingTransactions,
|
showIncomingTransactions,
|
||||||
participateInMetaMetrics,
|
participateInMetaMetrics,
|
||||||
|
usePhishDetect,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +30,7 @@ const mapDispatchToProps = (dispatch) => {
|
|||||||
return {
|
return {
|
||||||
setParticipateInMetaMetrics: (val) => dispatch(setParticipateInMetaMetrics(val)),
|
setParticipateInMetaMetrics: (val) => dispatch(setParticipateInMetaMetrics(val)),
|
||||||
setShowIncomingTransactionsFeatureFlag: (shouldShow) => dispatch(setFeatureFlag('showIncomingTransactions', shouldShow)),
|
setShowIncomingTransactionsFeatureFlag: (shouldShow) => dispatch(setFeatureFlag('showIncomingTransactions', shouldShow)),
|
||||||
|
setUsePhishDetect: (val) => dispatch(setUsePhishDetect(val)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ describe('Security Tab', function () {
|
|||||||
privacyMode: true,
|
privacyMode: true,
|
||||||
warning: '',
|
warning: '',
|
||||||
participateInMetaMetrics: false,
|
participateInMetaMetrics: false,
|
||||||
|
setUsePhishDetect: sinon.spy(),
|
||||||
|
usePhishDetect: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@ -46,8 +48,14 @@ describe('Security Tab', function () {
|
|||||||
assert(props.setShowIncomingTransactionsFeatureFlag.calledOnce)
|
assert(props.setShowIncomingTransactionsFeatureFlag.calledOnce)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('toggles phishing detection', function () {
|
||||||
|
const phishDetect = wrapper.find({ type: 'checkbox' }).at(1)
|
||||||
|
phishDetect.simulate('click')
|
||||||
|
assert(props.setUsePhishDetect.calledOnce)
|
||||||
|
})
|
||||||
|
|
||||||
it('toggles metaMetrics', function () {
|
it('toggles metaMetrics', function () {
|
||||||
const metaMetrics = wrapper.find({ type: 'checkbox' }).at(1)
|
const metaMetrics = wrapper.find({ type: 'checkbox' }).at(2)
|
||||||
|
|
||||||
metaMetrics.simulate('click')
|
metaMetrics.simulate('click')
|
||||||
assert(props.setParticipateInMetaMetrics.calledOnce)
|
assert(props.setParticipateInMetaMetrics.calledOnce)
|
||||||
|
@ -349,6 +349,10 @@ export function getUseNonceField (state) {
|
|||||||
return Boolean(state.metamask.useNonceField)
|
return Boolean(state.metamask.useNonceField)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getUsePhishDetect (state) {
|
||||||
|
return Boolean(state.metamask.usePhishDetect)
|
||||||
|
}
|
||||||
|
|
||||||
export function getCustomNonceValue (state) {
|
export function getCustomNonceValue (state) {
|
||||||
return String(state.metamask.customNonceValue)
|
return String(state.metamask.customNonceValue)
|
||||||
}
|
}
|
||||||
|
@ -2125,6 +2125,19 @@ export function setUseNonceField (val) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setUsePhishDetect (val) {
|
||||||
|
return (dispatch) => {
|
||||||
|
dispatch(showLoadingIndication())
|
||||||
|
log.debug(`background.setUsePhishDetect`)
|
||||||
|
background.setUsePhishDetect(val, (err) => {
|
||||||
|
dispatch(hideLoadingIndication())
|
||||||
|
if (err) {
|
||||||
|
return dispatch(displayWarning(err.message))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function setIpfsGateway (val) {
|
export function setIpfsGateway (val) {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(showLoadingIndication())
|
dispatch(showLoadingIndication())
|
||||||
|
Loading…
Reference in New Issue
Block a user