Skip to content

Commit

Permalink
Merge pull request #605 from cloudinary/fix-is-remote-url-test-regex-…
Browse files Browse the repository at this point in the history
…on-substring

fix: isRemoteUrl check improved to reduce false positives
  • Loading branch information
cloudinary-pkoniu committed May 2, 2023
2 parents f57b1ed + f839798 commit 5bc9323
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib-es5/utils/isRemoteUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ var isString = require('lodash/isString');
* @returns {boolean} true if the given url is a remote location or data
*/
function isRemoteUrl(url) {
return isString(url) && /^ftp:|^https?:|^gs:|^s3:|^data:/.test(url);
var SUBSTRING_LENGTH = 120;
var urlSubstring = isString(url) && url.substring(0, SUBSTRING_LENGTH);
return isString(url) && /^ftp:|^https?:|^gs:|^s3:|^data:([\w-.]+\/[\w-.]+(\+[\w-.]+)?)?(;[\w-.]+=[\w-.]+)*;base64,([a-zA-Z0-9\/+\n=]+)$/.test(urlSubstring);
}

module.exports = isRemoteUrl;
4 changes: 3 additions & 1 deletion lib/utils/isRemoteUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const isString = require('lodash/isString');
* @returns {boolean} true if the given url is a remote location or data
*/
function isRemoteUrl(url) {
return isString(url) && /^ftp:|^https?:|^gs:|^s3:|^data:/.test(url);
const SUBSTRING_LENGTH = 120;
const urlSubstring = isString(url) && url.substring(0, SUBSTRING_LENGTH);
return isString(url) && /^ftp:|^https?:|^gs:|^s3:|^data:([\w-.]+\/[\w-.]+(\+[\w-.]+)?)?(;[\w-.]+=[\w-.]+)*;base64,([a-zA-Z0-9\/+\n=]+)$/.test(urlSubstring);
}

module.exports = isRemoteUrl;

0 comments on commit 5bc9323

Please sign in to comment.