
* validate urls before deeplink or link click * tests for isValidURL utility function * review change - invert condition * add validation for loaded files bounds-info.json, app-state.json, config.json * further validation and tweaks certificate.json, permission.json * add 2 more files for validation * parse and validate deeplinks - includes fix for windows deeplink when app is open * disable auto-updator when in dev * Squirrel is not used anymore * fix validating allowedProtocols * discard any args following a deeplink url * tweaks * update test * support scheme’s with and without slashes * stop after finding the first occurance of a deep link * test updates * updates to run tests successfully * port updates to validation from 4.2 * url validation updates changed validation package to better support internal domains and punycode domains
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
// Copyright (c) 2015-2016 Yuya Ochiai
|
|
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
import url from 'url';
|
|
|
|
import {isUri, isHttpUri, isHttpsUri} from 'valid-url';
|
|
|
|
function getDomain(inputURL) {
|
|
const parsedURL = url.parse(inputURL);
|
|
return `${parsedURL.protocol}//${parsedURL.host}`;
|
|
}
|
|
|
|
function isValidURL(testURL) {
|
|
return Boolean(isHttpUri(testURL) || isHttpsUri(testURL));
|
|
}
|
|
|
|
function isValidURI(testURL) {
|
|
return Boolean(isUri(testURL));
|
|
}
|
|
|
|
// isInternalURL determines if the target url is internal to the application.
|
|
// - currentURL is the current url inside the webview
|
|
// - basename is the global export from the Mattermost application defining the subpath, if any
|
|
function isInternalURL(targetURL, currentURL, basename = '/') {
|
|
if (targetURL.host !== currentURL.host) {
|
|
return false;
|
|
}
|
|
|
|
if (!(targetURL.pathname || '/').startsWith(basename)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
export default {
|
|
getDomain,
|
|
isValidURL,
|
|
isValidURI,
|
|
isInternalURL,
|
|
};
|