From e41f3cfd134a071dbc6cd561bbb3277a780e0a89 Mon Sep 17 00:00:00 2001 From: selsta Date: Mon, 13 Nov 2023 02:27:15 +0100 Subject: [PATCH] TxUtils: use regex to check for valid domain --- js/TxUtils.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/js/TxUtils.js b/js/TxUtils.js index 28f25ef6eb..14a7d51937 100644 --- a/js/TxUtils.js +++ b/js/TxUtils.js @@ -70,11 +70,14 @@ function checkSignature(signature) { } function isValidOpenAliasAddress(address) { - address = address.trim() - // we can get an awful lot of valid domains, including non ASCII chars... accept anything - // there should be something after the . - // make sure it is not some kind of floating number - return address.length > 2 && isNaN(parseFloat(address)) && address.indexOf('.') >= 0 + var regex = /^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)+$/; // Basic domain structure + + if (!regex.test(address)) { + return false; + } + + const lastPart = address.substring(address.lastIndexOf('.') + 1); + return isNaN(parseInt(lastPart)) || lastPart !== parseInt(lastPart).toString(); } function handleOpenAliasResolution(address, descriptionText) {