Impoved validation of parent page id to prevent infinite loop
authorMarcel Werk <burntime@woltlab.com>
Wed, 19 Apr 2017 17:14:00 +0000 (19:14 +0200)
committerMarcel Werk <burntime@woltlab.com>
Wed, 19 Apr 2017 17:14:00 +0000 (19:14 +0200)
wcfsetup/install/files/lib/acp/form/PageEditForm.class.php

index 0aee81208fa53f45d9f93c27c2fe2948956176d1..f0220ec032695fc2f3c5ef32155560abcfd542c8 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\acp\form;
 use wcf\data\page\Page;
 use wcf\data\page\PageAction;
+use wcf\data\page\PageCache;
 use wcf\form\AbstractForm;
 use wcf\system\acl\simple\SimpleAclHandler;
 use wcf\system\exception\IllegalLinkException;
@@ -107,6 +108,20 @@ class PageEditForm extends PageAddForm {
                }
                else {
                        parent::validateParentPageID();
+                       
+                       if ($this->parentPageID) {
+                               if ($this->parentPageID == $this->pageID) {
+                                       throw new UserInputException('parentPageID', 'invalid');
+                               }
+                               
+                               $page = PageCache::getInstance()->getPage($this->parentPageID);
+                               while ($page->parentPageID !== null) {
+                                       $page = PageCache::getInstance()->getPage($page->parentPageID);
+                                       if ($page->pageID == $this->pageID) {
+                                               throw new UserInputException('parentPageID', 'invalid');
+                                       }
+                               }
+                       }
                }
        }