Fixed a regex in the editor causing catastrophic backtracing
authorAlexander Ebert <ebert@woltlab.com>
Wed, 25 Jan 2017 12:08:45 +0000 (13:08 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 25 Jan 2017 12:08:45 +0000 (13:08 +0100)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabLink.js

index 8ece922a18f00082244832a371e74071566e523f..58ac0b67793b4781b48140e60b794d8b84f68b00 100644 (file)
@@ -5,6 +5,31 @@ $.Redactor.prototype.WoltLabLink = function() {
        
        return {
                init: function() {
+                       this.link.isUrl = (function(url) {
+                               //var pattern = '((xn--)?[\\W\\w\\D\\d]+(-[\\W\\w\\D\\d]+)*\\.)+[\\W\\w]{2,}';
+                               // WoltLab modification: prevent catastrophic backtracing
+                               var pattern = '((xn--)?[\\W\\w\\D\\d]+(-(?!-[\\W\\w\\D\\d])+)*\\.)+[\\W\\w]{2,}';
+                               
+                               var re1 = new RegExp('^(http|ftp|https)://' + pattern, 'i');
+                               var re2 = new RegExp('^' + pattern, 'i');
+                               var re3 = new RegExp('\.(html|php)$', 'i');
+                               var re4 = new RegExp('^/', 'i');
+                               var re5 = new RegExp('^tel:(.*?)', 'i');
+                               
+                               // add protocol
+                               if (url.search(re1) === -1 && url.search(re2) !== -1 && url.search(re3) === -1 && url.substring(0, 1) !== '/')
+                               {
+                                       url = 'http://' + url;
+                               }
+                               
+                               if (url.search(re1) !== -1 || url.search(re3) !== -1 || url.search(re4) !== -1 || url.search(re5) !== -1)
+                               {
+                                       return url;
+                               }
+                               
+                               return false;
+                       }).bind(this);
+                       
                        this.link.show = this.WoltLabLink.show.bind(this);
                        
                        require(['WoltLabSuite/Core/Ui/Redactor/Link'], function(UiRedactorLink) {