Merge pull request #881 from mattermost/mm12800
MM-12800 Remove partial ability to use file:// links
This commit is contained in:
@@ -22,25 +22,6 @@ const preloadJS = `file://${remote.app.getAppPath()}/browser/webview/mattermost_
|
|||||||
const ERR_NOT_IMPLEMENTED = -11;
|
const ERR_NOT_IMPLEMENTED = -11;
|
||||||
const U2F_EXTENSION_URL = 'chrome-extension://kmendfapggjehodndflmmgagdbamhnfd/u2f-comms.html';
|
const U2F_EXTENSION_URL = 'chrome-extension://kmendfapggjehodndflmmgagdbamhnfd/u2f-comms.html';
|
||||||
|
|
||||||
function extractFileURL(message) {
|
|
||||||
const matched = message.match(/Not allowed to load local resource:\s*(.+)/);
|
|
||||||
if (matched) {
|
|
||||||
return matched[1];
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function isNetworkDrive(fileURL) {
|
|
||||||
const u = url.parse(fileURL);
|
|
||||||
if (u.protocol === 'file:' && u.host) {
|
|
||||||
// Disallow localhost, 127.0.0.1, ::1.
|
|
||||||
if (!u.host.match(/^localhost$|^127\.0\.0\.1$|^\[::1\]$/)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class MattermostView extends React.Component {
|
export default class MattermostView extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
@@ -191,19 +172,9 @@ export default class MattermostView extends React.Component {
|
|||||||
case 1:
|
case 1:
|
||||||
console.warn(message);
|
console.warn(message);
|
||||||
break;
|
break;
|
||||||
case 2: {
|
case 2:
|
||||||
const fileURL = extractFileURL(e.message);
|
console.error(message);
|
||||||
if (isNetworkDrive(fileURL)) {
|
|
||||||
// Network drive: Should be allowed.
|
|
||||||
if (!shell.openExternal(decodeURI(fileURL))) {
|
|
||||||
console.log(`[${this.props.name}] shell.openExternal failed: ${fileURL}`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Local drive such as 'C:\Windows': Should not be allowed.
|
|
||||||
console.error(message);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
console.log(message);
|
console.log(message);
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user