CVE-2017-20174 (published 2023-01-19T08:15Z)

A vulnerability was found in bastianallgeier Kirby Webmentions Plugin and classified as problematic. Affected by this issue is some unknown functionality. The manipulation leads to injection. The attack may be launched remotely. The complexity of an attack is rather high. The exploitation is known to be difficult. The patch is identified as 55bedea78ae9af916a9a41497bd9996417851502. It is recommended to apply a patch to fix this issue. VDB-218894 is the identifier assigned to this vulnerability.

CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-74
cwe_name: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
description: The product constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component.
extended_description: Software or other automated logic has certain assumptions about what constitutes data and control respectively. It is the lack of verification of these assumptions for user-controlled input that leads to injection problems. Injection problems encompass a wide variety of issues -- all mitigated in very different ways and usually attempted in order to alter the control flow of the process. For this reason, the most effective way to discuss these weaknesses is to note the distinct features that classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed.
         

Fix information:
repo_url: https://github.com/bastianallgeier/kirby-webmentions
commit_details: repo_url: https://github.com/bastianallgeier/kirby-webmentions
author: Bastian Allgeier
author_date: 2017-02-01 09:47:48+01:00
msg: Fixed remote image vulnerability
repository: repo_url: https://github.com/bastianallgeier/kirby-webmentions
repo_name: bastianallgeier/kirby-webmentions
description: This is the first draft of a Kirby webmentions plugin
repo_language: PHP
owner: bastianallgeier
file_changes: filename: author.php
change_type: ModificationType.MODIFY
diff: @@ -65,20 +65,29 @@ class Author extends Obj {
     $url       = kirby()->urls()->index() . '/' . $path . '/' . $filename;
     $photo     = new Media($root, $url);
     
-    if(!$photo->exists()) {    
+    // only allow images with a correct extension
+    if(in_array(strtolower($extension), ['jpg', 'jpeg', 'png', 'gif']) && !$photo->exists()) {    
 
       $image   = remote::get($this->data['photo']);
+      $mime    = a::get($image->headers, 'Content-Type');      
       $allowed = array('image/jpeg', 'image/png', 'image/gif');
-
-      f::write($root, $image->content());
-
-      if(!in_array($photo->mime(), $allowed) or $photo->size() == 0) {
-        $photo->delete();
+      
+      // check the mime type of the remote request response
+      if(in_array($mime, $allowed)) {
+
+        // write the file to disk
+        f::write($root, $image->content());
+  
+        // check the mime type and file size again to make sure it's all ok
+        if(!in_array($photo->mime(), $allowed) or $photo->size() == 0) {
+          $photo->delete();
+        }        
+      
       }
 
     }
 
-    if(!$photo->exists() or !$photo->type() == 'image') {
+    if(!$photo->exists() || $photo->type() !== 'image') {
       $photo = new Obj(array(
         'url'    => $this->data['photo'],
         'exists' => false
@@ -108,4 +117,4 @@ class Author extends Obj {
     return (string)$this->toHtml();
   }
 
-}
\ No newline at end of file
+}

programming_language: PHP