Jelajahi Sumber

fix xss / GH-2252

ref https://github.com/serghey-rodin/vesta/issues/2252
divinity76 3 tahun lalu
induk
melakukan
0682f7b10c
1 mengubah file dengan 7 tambahan dan 0 penghapusan
  1. 7 0
      web/api/v1/upload/UploadHandler.php

+ 7 - 0
web/api/v1/upload/UploadHandler.php

@@ -1191,6 +1191,13 @@ class UploadHandler
                     ));
                 }
             }
+            if(!headers_sent()){
+                // this is the most likely/expected path.
+                header("Content-Type: text/javascript; charset=UTF-8");
+            } else {
+                // html-encode json to prevent xss...
+                $json = htmlentities($json, ENT_QUOTES | ENT_SUBSTITUTE | ENT_DISALLOWED | ENT_HTML401);
+            }
             $this->body($json);
         }
         return $content;