diff --git a/package-lock.json b/package-lock.json index 0587c9915..e950a7ff1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6735,6 +6735,11 @@ } } }, + "unhomoglyph": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/unhomoglyph/-/unhomoglyph-1.0.2.tgz", + "integrity": "sha1-1p5fWmocayEZQaCIm4HrqGWVwlM=" + }, "union-value": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.0.tgz", diff --git a/package.json b/package.json index 916c1d861..71a43fc99 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,8 @@ "content-type": "^1.0.2", "loglevel": "1.6.1", "qs": "^6.5.2", - "request": "^2.88.0" + "request": "^2.88.0", + "unhomoglyph": "^1.0.2" }, "devDependencies": { "babel-cli": "^6.18.0", diff --git a/src/utils.js b/src/utils.js index 8ee81ed3e..265ce218e 100644 --- a/src/utils.js +++ b/src/utils.js @@ -19,6 +19,8 @@ limitations under the License. * @module utils */ +const unhomoglyph = require('unhomoglyph'); + /** * Encode a dictionary of query parameters. * @param {Object} params A dict of key/values to encode e.g. @@ -665,11 +667,12 @@ module.exports.isNumber = function(value) { /** * Removes zero width chars, diacritics and whitespace from the string + * Also applies an unhomoglyph on the string, to prevent similar looking chars * @param {string} str the string to remove hidden characters from * @return {string} a string with the hidden characters removed */ module.exports.removeHiddenChars = function(str) { - return str.normalize('NFD').replace(removeHiddenCharsRegex, ''); + return unhomoglyph(str.normalize('NFD').replace(removeHiddenCharsRegex, '')); }; const removeHiddenCharsRegex = /[\u200B-\u200D\u0300-\u036f\uFEFF\s]/g;