CVE-2022-0896: Improper Control of Generation of Code ('Code Injection') (CWE-94)
value: Improper Neutralization of Special Elements Used in a Template Engine in GitHub repository microweber/microweber prior to 1.3.
CWE description: The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
CVSS v3 base score: 8.8
Published: 2022-03-09T12:15Z
Repository: https://github.com/microweber/microweber
Language: PHP
Files changed: src/MicroweberPackages/Comment/Http/Controllers/Admin/AdminCommentController.php
Commit date: 2022-03-09 13:17:21 +0200
Commit message: Update AdminCommentController.php

Diff: diff --git a/src/MicroweberPackages/Comment/Http/Controllers/Admin/AdminCommentController.php b/src/MicroweberPackages/Comment/Http/Controllers/Admin/AdminCommentController.php
index f58adbd444d..4bf237d5807 100644
--- a/src/MicroweberPackages/Comment/Http/Controllers/Admin/AdminCommentController.php
+++ b/src/MicroweberPackages/Comment/Http/Controllers/Admin/AdminCommentController.php
@@ -16,22 +16,20 @@ use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Notification;
 use MicroweberPackages\App\Http\Controllers\AdminController;
 use MicroweberPackages\Comment\Models\Comment;
 use MicroweberPackages\Comment\Events\NewComment;
 use MicroweberPackages\Comment\Notifications\NewCommentNotification;
+use MicroweberPackages\Helper\HTMLClean;
 use MicroweberPackages\User\Models\User;
 use MicroweberPackages\Utils\Mail\MailSender;
 
-
 class AdminCommentController extends AdminController
 {
     public function index(Request $request)
     {
-
         $contents = $this->getComments($request);
 
-
         return $this->view('comment::admin.comments.index', ['contents' => $contents]);
     }
 
     public function getComments(Request $request)
     {
@@ -40,11 +38,10 @@ class AdminCommentController extends AdminController
 
         if (!empty($filter)) {
             $contents = $contents->filter($filter);
         }
 
-
         $contents = $contents->paginate($request->get('limit', 30))
             ->appends($request->except('page'));
 
         foreach ($contents as $content) {
             $content->allComments = Comment::where('rel_type', $content['rel_type'])
@@ -146,16 +143,12 @@ class AdminCommentController extends AdminController
             $data['comment_body'] = '';
         }
 
         $comment_body = $data['comment_body'];
 
-        // Claer HTML
-        $comment_body = $this->app->format->clean_html($comment_body);
-
-        // Clear XSS
-        $evil = ['(?<!\w)on\w*', 'xmlns', 'formaction', 'xlink:href', 'FSCommand', 'seekSegmentTime'];
-        $comment_body = $this->app->format->clean_xss($comment_body, true, $evil, 'removeEvilAttributes');
+        $cleanHtml = new HTMLClean();
+        $comment_body = $cleanHtml->onlyTags($comment_body);
 
         if (!empty($comment_body) and !empty($data['format']) and $data['format'] == 'markdown') {
             $comment_body = Markdown::convertToHtml($comment_body);
         }
 

Vulnerable code: 



        // Claer HTML
        $comment_body = $this->app->format->clean_html($comment_body);

        // Clear XSS
        $evil = ['(?<!\w)on\w*', 'xmlns', 'formaction', 'xlink:href', 'FSCommand', 'seekSegmentTime'];
        $comment_body = $this->app->format->clean_xss($comment_body, true, $evil, 'removeEvilAttributes');
Fixed code: use MicroweberPackages\Helper\HTMLClean;
        $cleanHtml = new HTMLClean();
        $comment_body = $cleanHtml->onlyTags($comment_body);