diff --git a/src/simpleguardhome/templates/index.html b/src/simpleguardhome/templates/index.html index 7276c8b..af5c544 100644 --- a/src/simpleguardhome/templates/index.html +++ b/src/simpleguardhome/templates/index.html @@ -46,9 +46,37 @@ } } + function preprocessDomain(input) { + // Strip http:// or https:// from the beginning + let domain = input.replace(/^https?:\/\//i, ''); + + // Strip any paths or query parameters + domain = domain.split('/')[0]; + + // Basic domain validation + const domainRegex = /^[a-zA-Z0-9][a-zA-Z0-9.-]*[a-zA-Z0-9]$/; + if (!domainRegex.test(domain)) { + throw new Error('Invalid domain format. Please enter a valid domain name (e.g., example.com)'); + } + + return domain; + } + async function checkDomain(event) { event.preventDefault(); - const domain = DOMPurify.sanitize(document.getElementById('domain').value); + const rawInput = DOMPurify.sanitize(document.getElementById('domain').value); + let domain; + try { + domain = preprocessDomain(rawInput); + } catch (error) { + resultDiv.innerHTML = ` +
Invalid Input
+${escapeHtml(error.message)}
+