Skip to content

Commit ee922a8

Browse files
committed
Bugfix
1 parent 3d2310f commit ee922a8

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

app/Http/Controllers/UserController.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use DB;
1515
use ZipArchive;
1616
use File;
17+
use DOMDocument;
1718

1819
use App\Models\User;
1920
use App\Models\Button;
@@ -720,8 +721,34 @@ public function editPage(request $request)
720721

721722
$profilePhoto = $request->file('image');
722723
$pageName = $request->littlelink_name;
723-
$pageDescription = strip_tags($request->pageDescription,'<a><p><strong><i><ul><ol><li><blockquote><h2><h3><h4>');
724-
$pageDescription = preg_replace("/<a([^>]*)>/i", "<a $1 rel=\"noopener noreferrer nofollow\">", $pageDescription);
724+
$pageDescription = $request->pageDescription;
725+
726+
// Strip HTML tags except for allowed tags
727+
$pageDescription = strip_tags($pageDescription, '<a><p><strong><i><ul><ol><li><blockquote><h2><h3><h4>');
728+
729+
// Sanitize attributes and remove JavaScript code
730+
if (!empty($pageDescription)) {
731+
$document = new DOMDocument();
732+
$document->loadHTML($pageDescription, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
733+
734+
// Find all elements that have attributes
735+
$elements = $document->getElementsByTagName('*');
736+
foreach ($elements as $element) {
737+
// Check each attribute of the element
738+
foreach ($element->attributes as $attribute) {
739+
$attributeName = $attribute->nodeName;
740+
741+
// Remove attributes that contain "on" followed by an event name
742+
if (strpos($attributeName, 'on') === 0) {
743+
$element->removeAttribute($attributeName);
744+
}
745+
}
746+
}
747+
748+
// Get the sanitized HTML back
749+
$pageDescription = $document->saveHTML();
750+
}
751+
725752
$name = $request->name;
726753
$checkmark = $request->checkmark;
727754
$sharebtn = $request->sharebtn;

0 commit comments

Comments
 (0)