diff --git a/config/default.js b/config/default.js index d27c55ae5e..e67e780634 100644 --- a/config/default.js +++ b/config/default.js @@ -472,4 +472,5 @@ module.exports = { ACCOUNT_SETTINGS_REDIRECT_URL: 'https://account-settings.topcoder-dev.com', INNOVATION_CHALLENGES_TAG: 'Innovation Challenge', PLATFORM_SITE_URL: 'https://platform.topcoder-dev.com', + TOPGEAR_ALLOWED_SUBMISSIONS_DOMAINS: ['wipro365.sharepoint.com', 'wipro365-my.sharepoint.com'], }; diff --git a/src/shared/components/SubmissionPage/FilestackFilePicker/index.jsx b/src/shared/components/SubmissionPage/FilestackFilePicker/index.jsx index f2db4d3d9a..b3ecfc0746 100644 --- a/src/shared/components/SubmissionPage/FilestackFilePicker/index.jsx +++ b/src/shared/components/SubmissionPage/FilestackFilePicker/index.jsx @@ -35,6 +35,7 @@ class FilestackFilePicker extends React.Component { this.state = { inputUrl: '', invalidUrl: false, + invalidDomain: false, }; } @@ -105,8 +106,10 @@ class FilestackFilePicker extends React.Component { if (!isChallengeBelongToTopgearGroup) { return; } - if (this.isValidUrl(inputUrl)) { - this.setState({ invalidUrl: false }); + const validUrl = this.isValidUrl(inputUrl); + const validDomain = this.isDomainAllowed(inputUrl); + if (validUrl && validDomain) { + this.setState({ invalidUrl: false, invalidDomain: false }); const path = this.generateFilePath(); const filename = inputUrl.substring(inputUrl.lastIndexOf('/') + 1); setDragged(false); @@ -119,7 +122,7 @@ class FilestackFilePicker extends React.Component { originalPath: inputUrl, }, path); } else { - this.setState({ invalidUrl: true }); + this.setState({ invalidUrl: true, invalidDomain: !validDomain }); } } @@ -132,6 +135,11 @@ class FilestackFilePicker extends React.Component { return /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(url); /* eslint-disable-line no-useless-escape */ } + isDomainAllowed(url) { + const domainReg = new RegExp(`^https?://(${config.TOPGEAR_ALLOWED_SUBMISSIONS_DOMAINS.join('|')})/.+`); + return !!url.match(domainReg); + } + /** * Returns the path where the picked up file should be stored. * @return {String} @@ -157,6 +165,7 @@ class FilestackFilePicker extends React.Component { const { invalidUrl, + invalidDomain, inputUrl, } = this.state; @@ -207,6 +216,14 @@ class FilestackFilePicker extends React.Component { isChallengeBelongToTopgearGroup && (