emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master fbf2ed9a64: ipv6 addresses aren't suspicious


From: Lars Ingebrigtsen
Subject: master fbf2ed9a64: ipv6 addresses aren't suspicious
Date: Tue, 29 Mar 2022 11:12:34 -0400 (EDT)

branch: master
commit fbf2ed9a648d9c0f64519900acf1574d0d74692b
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    ipv6 addresses aren't suspicious
    
    * 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            | 12 ++++++++++++
 test/lisp/international/textsec-tests.el | 11 ++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/lisp/international/textsec.el b/lisp/international/textsec.el
index 6985f4f3ef..cca49986fc 100644
--- a/lisp/international/textsec.el
+++ b/lisp/international/textsec.el
@@ -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)
diff --git a/test/lisp/international/textsec-tests.el 
b/test/lisp/international/textsec-tests.el
index 5bf9a3dcfb..9216d334f8 100644
--- a/test/lisp/international/textsec-tests.el
+++ b/test/lisp/international/textsec-tests.el
@@ -117,7 +117,16 @@
   (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"))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]