]> git.eshelyaron.com Git - emacs.git/commitdiff
ipv6 addresses aren't suspicious
authorLars Ingebrigtsen <larsi@gnus.org>
Tue, 29 Mar 2022 15:12:01 +0000 (17:12 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 29 Mar 2022 15:12:01 +0000 (17:12 +0200)
* lisp/international/textsec.el (textsec--ipvx-address-p): New
function.
(textsec-domain-suspicious-p): Use it to say that ipv6 addresses
aren't suspicious (bug#54624).

lisp/international/textsec.el
test/lisp/international/textsec-tests.el

index 6985f4f3efed8093ba5d65432719d7cbd0d53298..cca49986fc43faa527badd70c21cc58170eecfb4 100644 (file)
@@ -231,6 +231,15 @@ The scripts are as defined by the Unicode Standard Annex 24 (UAX#24)."
        (textsec-single-script-p string1)
        (textsec-single-script-p string2)))
 
+(defun textsec--ipvx-address-p (domain)
+  "Return non-nil if DOMAIN is an ipv4 or ipv6 address."
+  (or (string-match-p "\\`\\([0-9]\\{1,3\\}\\.?\\)\\{1,4\\}\\'" domain)
+      (let ((ipv6 "\\([0-9a-f]\\{0,4\\}:?\\)\\{1,8\\}"))
+        ;; With brackets.
+        (or (string-match-p (format "\\`\\[%s\\]\\'" ipv6) domain)
+            ;; Without.
+            (string-match-p (format "\\`%s\\'" ipv6) domain)))))
+
 (defun textsec-domain-suspicious-p (domain)
   "Say whether DOMAIN's name looks suspicious.
 Return nil if it isn't suspicious.  If it is, return a string explaining
@@ -241,6 +250,9 @@ that can look similar to other characters when displayed, or
 use characters that are not allowed by Unicode's IDNA mapping,
 or use certain other unusual mixtures of characters."
   (catch 'found
+    ;; Plain domains aren't suspicious.
+    (when (textsec--ipvx-address-p domain)
+      (throw 'found nil))
     (seq-do
      (lambda (char)
        (when (eq (elt idna-mapping-table char) t)
index 5bf9a3dcfb3a4f9f6dc6dee2c22385850cf66b4f..9216d334f871eae8c724e551012ba3b7dc4111d8 100644 (file)
   (should (textsec-domain-suspicious-p "f\N{LEFT-TO-RIGHT ISOLATE}oo.org"))
 
   (should (textsec-domain-suspicious-p "Сгсе.ru"))
-  (should-not (textsec-domain-suspicious-p "фСгсе.ru")))
+  (should-not (textsec-domain-suspicious-p "фСгсе.ru"))
+
+  (should-not (textsec-domain-suspicious-p
+               "21a:34aa:c782:3ad2:1bf8:73f8:141:66e8"))
+  (should (textsec-domain-suspicious-p
+               "21a:34aa:c782:3ad2:1bf8:73f8:141:66e8:66e8"))
+  (should-not (textsec-domain-suspicious-p
+               "[21a:34aa:c782:3ad2:1bf8:73f8:141:66e8]"))
+  (should (textsec-domain-suspicious-p
+           "[21a:34aa:c782:3ad2:1bf8:73f8:141:66e8")))
 
 (ert-deftest test-suspicious-local ()
   (should-not (textsec-local-address-suspicious-p "larsi"))