Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/mangboard/includes/functions/func.api.php
+++ b/mangboard/includes/functions/func.api.php
@@ -910,7 +910,7 @@
}else if($file_size>$limit_size){
mbw_error_message("MSG_UPLOAD_SIZE_ERROR", mbw_get_option("upload_file_size"),"1503");
}else if(mbw_get_result_data("state")!="error"){
- $file_name = $upload_data["name"];
+ $file_name = $upload_data["name"];
$tmp_name = preg_replace("/[^_.0-9a-zA-Z-,]/u", "", $upload_data["name"]);
if(strlen($tmp_name) != strlen($file_name)) $file_name = mt_rand().".".$file_ext;
@@ -1036,9 +1036,12 @@
$file_pid = $file_item[$mb_fields["files"]["fn_pid"]];
$upload_data["pid"] = $file_pid;
$upload_data["path"] = $file_item[$mb_fields["files"]["fn_file_path"]];
- $datePath = substr($upload_data["path"],0,11);
- $file_name = substr($upload_data["path"],11);
- $upload_data["name"] = $file_item[$mb_fields["files"]["fn_file_name"]];
+
+ $file_name = basename($upload_data["path"]);
+ $datePath = preg_replace('/[^0-9a-zA-Z/]/', '', str_replace($file_name, "", $upload_data["path"]));
+ $file_name = mbw_check_upload_filename($file_name);
+ $upload_data["name"] = mbw_check_upload_filename($file_item[$mb_fields["files"]["fn_file_name"]]);
+
if($file_item[$mb_fields["files"]["fn_file_description"]]!="img64"){
return $upload_data;
}else{
--- a/mangboard/includes/functions/func.board.php
+++ b/mangboard/includes/functions/func.board.php
@@ -44,19 +44,22 @@
}
}
- if($user_id!=""){
+ if ( $user_id != "" ) {
if( mbw_get_vars("mb_".$user_id."_auth_key") != "" ) {
- $user_auth_key = mbw_get_vars("mb_".$user_id."_auth_key");
+ $user_auth_key = mbw_get_vars("mb_".$user_id."_auth_key");
} else {
$user_auth_key = $mdb->get_var($mdb->prepare("select ".$mb_fields["users"]["fn_user_auth_key"]." from `".$mb_admin_tables["users"]."` where `".$mb_fields["users"]["fn_user_id"]."`=%s;", $user_id));
+ if ( empty($user_auth_key) ) {
+ return "";
+ }
mbw_set_vars("mb_".$user_id."_auth_key",$user_auth_key);
}
- }else{
+ } else {
$user_id = "guest";
$user_auth_key = "guest";
- }
+ }
$tmp_tag = $tag;
- if($tag=="nonce" && mbw_get_board_name()!=""){
+ if ( $tag == "nonce" && mbw_get_board_name() != "" ) {
global $mb_table_prefix;
$table_name = mbw_get_board_table_name(mbw_get_board_name());
$table_name = substr($table_name,strlen($mb_table_prefix));
@@ -1199,9 +1202,9 @@
$store_path = mbw_value_filter($store_path, "path");
}
if ( $store_path != "" && is_file(WP_CONTENT_DIR.$store_path."plugins/user/css/login.css") ) {
- loadStyle(MBW_CONTENT_URL.$store_path."plugins/user/css/login.css");
+ mbw_load_style(MBW_CONTENT_URL.$store_path."plugins/user/css/login.css");
}else{
- loadStyle(MBW_PLUGIN_URL."plugins/user/css/login.css");
+ mbw_load_style(MBW_PLUGIN_URL."plugins/user/css/login.css");
}
mbw_set_result_data(array("state"=>"login","script"=>""));
mbw_set_option("user_login_redirect_url","reload");
@@ -1266,9 +1269,9 @@
if(strpos($entry,'.')!==0 && is_file($path."/".$entry)){
if(substr($entry, -3) === '.js'){
if($entry=="common.js"){
- loadScript(MBW_PLUGIN_URL.'assets/js/'.$entry, $localize_name);
+ mbw_load_script(MBW_PLUGIN_URL.'assets/js/'.$entry, $localize_name);
}else{
- loadScript(MBW_PLUGIN_URL.'assets/js/'.$entry);
+ mbw_load_script(MBW_PLUGIN_URL.'assets/js/'.$entry);
}
}
}
@@ -1278,7 +1281,7 @@
while (false !== ($entry = $dir->read())){
if(strpos($entry,'.')!==0 && is_file($path."/".$entry)){
if(substr($entry, -4) === '.css'){
- loadStyle(MBW_PLUGIN_URL.'assets/css/'.$entry);
+ mbw_load_style(MBW_PLUGIN_URL.'assets/css/'.$entry);
}
}
}
@@ -1601,7 +1604,9 @@
function mbw_generate_auth_cookie($user_id="",$user_mode="MB",$expire=0){
global $mstore,$mdb,$mb_fields,$mb_admin_tables;
- if(empty($user_id)) return;
+ if ( empty($user_id) ) {
+ return;
+ }
$auth_cookie_name = $mstore->get_auth_cookie_name();
mbw_set_wp_user_data($user_id, $user_mode);
@@ -1612,6 +1617,9 @@
$user_auth_key = mbw_get_vars("mb_".$user_id."_auth_key");
} else {
$user_auth_key = $mdb->get_var($mdb->prepare("select ".$mb_fields["users"]["fn_user_auth_key"]." from `".$mb_admin_tables["users"]."` where `".$mb_fields["users"]["fn_user_id"]."`=%s;", $user_id));
+ if ( empty($user_auth_key) ) {
+ return;
+ }
mbw_set_vars("mb_".$user_id."_auth_key",$user_auth_key);
}
$auth_key = md5($user_id.'|'.$expiration.'|'.$user_auth_key);
@@ -1624,13 +1632,11 @@
if(!function_exists('mbw_refresh_auth_cookie')){
function mbw_refresh_auth_cookie(){
global $mstore,$mdb,$mb_admin_tables,$mb_fields;
-
- if ( !mbw_is_login_cookie() )
+ if ( !mbw_is_login_cookie() ) {
return false;
-
- $cookie = mbw_get_login_cookie();
- $cookie_elements = explode('|', $cookie);
-
+ }
+ $cookie = mbw_get_login_cookie();
+ $cookie_elements = explode('|', $cookie);
if ( count($cookie_elements) != 5 ) {
return false;
}
@@ -1638,21 +1644,28 @@
list($user_id, $expiration, $hmac, $user_mode, $auth_key) = $cookie_elements;
$user_access_token = "";
$user_auth_key = "";
- if( !empty($user_id) ) {
+ if ( !empty($user_id) ) {
if( mbw_get_vars("mb_".$user_id."_access_token") != "" && mbw_get_vars("mb_".$user_id."_auth_key") != "" ) {
$user_access_token = mbw_get_vars("mb_".$user_id."_access_token");
$user_auth_key = mbw_get_vars("mb_".$user_id."_auth_key");
} else {
$row = $mdb->get_row($mdb->prepare("select ".$mb_fields["users"]["fn_user_access_token"].",".$mb_fields["users"]["fn_user_auth_key"]." from `".$mb_admin_tables["users"]."` where `".$mb_fields["users"]["fn_user_id"]."`=%s;", $user_id), ARRAY_A);
- if(!empty($row)){
+ if ( !empty($row) ) {
$user_access_token = $row[$mb_fields["users"]["fn_user_access_token"]];
$user_auth_key = $row[$mb_fields["users"]["fn_user_auth_key"]];
+ if ( empty($user_auth_key) ) {
+ return false;
+ }
mbw_set_vars("mb_".$user_id."_access_token",$user_access_token);
mbw_set_vars("mb_".$user_id."_auth_key",$user_auth_key);
+ } else {
+ return false;
}
}
+ } else {
+ return false;
}
- if( !empty($auth_key) && $auth_key == md5($user_id.'|'.$expiration.'|'.$user_auth_key) ){
+ if ( !empty($auth_key) && $auth_key == md5($user_id.'|'.$expiration.'|'.$user_auth_key) ){
$hash = mbw_get_hash_key("cookie",$expiration,$user_id,$user_access_token);
$hash2 = mbw_get_hash_key("cookie",$expiration,$user_id);
@@ -1672,8 +1685,7 @@
return true;
}
- global $mstore,$mdb;
- global $mb_admin_tables,$mb_fields;
+ global $mstore,$mdb,$mb_admin_tables,$mb_fields;
if ( !mbw_is_login_cookie() ) {
return false;
}
@@ -1692,24 +1704,35 @@
$user_auth_key = mbw_get_vars("mb_".$user_id."_auth_key");
} else {
$row = $mdb->get_row($mdb->prepare("select ".$mb_fields["users"]["fn_user_access_token"].",".$mb_fields["users"]["fn_user_auth_key"]." from `".$mb_admin_tables["users"]."` where `".$mb_fields["users"]["fn_user_id"]."`=%s;", $user_id), ARRAY_A);
- if(!empty($row)){
+ if ( !empty($row) ) {
$user_access_token = $row[$mb_fields["users"]["fn_user_access_token"]];
$user_auth_key = $row[$mb_fields["users"]["fn_user_auth_key"]];
+ if ( empty($user_auth_key) ) {
+ return false;
+ }
mbw_set_vars("mb_".$user_id."_access_token",$user_access_token);
mbw_set_vars("mb_".$user_id."_auth_key",$user_auth_key);
+ } else {
+ return false;
}
}
+ } else {
+ return false;
}
if( empty($auth_key) || $auth_key != md5($user_id.'|'.$expiration.'|'.$user_auth_key) ){
return false;
}
$hash = mbw_get_hash_key("cookie",$expiration,$user_id,$user_access_token);
- if($hmac==$hash) return true;
- else{
+ if ( $hmac == $hash ) {
+ return true;
+ } else {
$hash2 = mbw_get_hash_key("cookie",$expiration,$user_id);
- if($hmac==$hash2) return true;
- else return false;
+ if ( $hmac == $hash2 ) {
+ return true;
+ } else {
+ return false;
+ }
}
}
}
--- a/mangboard/includes/functions/func.util.php
+++ b/mangboard/includes/functions/func.util.php
@@ -1,6 +1,11 @@
<?php
if(!function_exists('loadScript')){
function loadScript($src, $handle="",$deps=array('jquery')){
+ mbw_load_script($src, $handle, $deps);
+ }
+}
+if(!function_exists('mbw_load_script')){
+ function mbw_load_script($src, $handle="",$deps=array('jquery')){
// JS 파일 등록
if( mbw_is_ssl() ){
$src = str_replace("http://", "https://", $src);
@@ -28,6 +33,11 @@
}
if(!function_exists('loadStyle')){
function loadStyle($src, $handle="", $deps=array()){
+ mbw_load_style($src, $handle, $deps);
+ }
+}
+if(!function_exists('mbw_load_style')){
+ function mbw_load_style($src, $handle="", $deps=array()){
// CSS 파일 등록
if( mbw_is_ssl() ){
$src = str_replace("http://", "https://", $src);
@@ -65,10 +75,10 @@
if($type=="daum"){
if(mbw_is_ssl()){
wp_enqueue_script("kakao-postcode", "https://t1.kakaocdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js", array('jquery'), null);
- //loadScript("https://t1.kakaocdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js","kakao-postcode");
+ //mbw_load_script("https://t1.kakaocdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js","kakao-postcode");
}else{
wp_enqueue_script("kakao-postcode", "http://t1.kakaocdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js", array('jquery'), null);
- //loadScript("http://t1.kakaocdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js","kakao-postcode");
+ //mbw_load_script("http://t1.kakaocdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js","kakao-postcode");
}
}
}
--- a/mangboard/includes/mb-options.php
+++ b/mangboard/includes/mb-options.php
@@ -10,7 +10,7 @@
}else if(!empty($_REQUEST["lang"])){
$mb_locale = preg_replace("/[^0-9a-zA-Z_,-]/u", '', $_REQUEST["lang"]);
}else if(!is_admin() && !empty($_COOKIE["mb_locale"])){
- $mb_locale = $_COOKIE["mb_locale"];
+ $mb_locale = preg_replace("/[^0-9a-zA-Z_,-]/u", '', $_COOKIE["mb_locale"]);
}else{
$mb_uri = "";
if(!empty($_SERVER["REQUEST_URI"])) $mb_uri = strtolower($_SERVER["REQUEST_URI"]);
--- a/mangboard/includes/mb-version.php
+++ b/mangboard/includes/mb-version.php
@@ -1,5 +1,5 @@
<?php
-$mb_version = '2.4.8';
-$mb_index = '256';
+$mb_version = '2.4.9';
+$mb_index = '257';
$mb_db_version = '1.0.7';
?>
No newline at end of file
--- a/mangboard/mangboard.php
+++ b/mangboard/mangboard.php
@@ -3,7 +3,7 @@
* Plugin Name: MangBoard
* Plugin URI: https://mangboard.com/
* Description: MangBoard는 Wordpress에서 게시판을 생성/관리 할 수 있는 기능을 제공합니다
- * Version: 2.4.8
+ * Version: 2.4.9
* Author: Hometory
* Author URI: https://www.hometory.com/
* License: GPLv2 or later
--- a/mangboard/models/admin/files.php
+++ b/mangboard/models/admin/files.php
@@ -1,7 +1,7 @@
<?php
$desktop_model = array();
$tablet_model = array();
-$mobile_model = array();
+$mobile_model = array();
$desktop_model['version'] = "1.0.0";
$desktop_model['list'] = '
@@ -50,7 +50,7 @@
{"tpl":"tag","tag_name":"table","type":"end"}
';
-$tablet_model = $desktop_model;
+$tablet_model = $desktop_model;
$mobile_model = $desktop_model;
mbw_set_fields("select_board",$mb_fields["files"]);
@@ -59,34 +59,34 @@
function mbw_board_files_api_body(){
global $mdb,$mb_fields,$mb_admin_tables,$mstore;
$where_query = "";
- $query_command = "";
+ $query_command = "";
$field = $mb_fields["files"];
-
- if(mbw_is_admin()){
-
+
+ if ( mbw_is_admin() && current_user_can('administrator') ) {
if(mbw_get_param("board_action")=="delete"){
$query_command = "DELETE";
- $where_query = $mdb->prepare(" WHERE ".$field["fn_pid"]."=%d", mbw_get_param("board_pid") );
+ $where_query = $mdb->prepare(" WHERE ".$field["fn_pid"]."=%d", mbw_get_param("board_pid") );
}else if(mbw_get_param("board_action")=="multi_delete"){
$query_command = "DELETE";
- $pid_array = mbw_get_param("check_array");
+ $pid_array = mbw_get_param("check_array");
$pid_format = array();
foreach($pid_array as $key){
$pid_format[] = "%d";
}
- $where_query = $mdb->prepare(" WHERE ".$field["fn_pid"]." in (".implode(",",$pid_format).")", $pid_array );
+ $where_query = $mdb->prepare(" WHERE ".$field["fn_pid"]." in (".implode(",",$pid_format).")", $pid_array );
}
if($query_command=="DELETE"){
- $select_query = "SELECT * FROM ".$mb_admin_tables["files"].$where_query;
+ $select_query = "SELECT * FROM ".$mb_admin_tables["files"].$where_query;
$items = $mdb->get_results($select_query,ARRAY_A);
foreach($items as $item){
if($item[$field["fn_link_count"]]=="0" && !empty($item[$field["fn_file_path"]])){
- $file_path = MBW_UPLOAD_PATH.$item[$field["fn_file_path"]];
-
- if(is_file($file_path)){
+
+ $file_path = str_replace('..', '.', $item[$field["fn_file_path"]]);
+ $file_path = MBW_UPLOAD_PATH.$file_path;
+ if ( strpos(wp_normalize_path(realpath($file_path)), MBW_UPLOAD_PATH)===0 && is_file($file_path)) {
@unlink($file_path);
$file_path_small = substr($file_path,0,strrpos($file_path, "."))."_small".substr($file_path,strrpos($file_path, "."),strlen($file_path));
@@ -98,7 +98,7 @@
}
}
}
- }
+ }
}
}
}
--- a/mangboard/models/admin/users.php
+++ b/mangboard/models/admin/users.php
@@ -1,7 +1,7 @@
<?php
$desktop_model = array();
$tablet_model = array();
-$mobile_model = array();
+$mobile_model = array();
$desktop_model['version'] = "1.0.0";
$desktop_model['list'] = '
@@ -81,7 +81,7 @@
';
-$tablet_model = $desktop_model;
+$tablet_model = $desktop_model;
$mobile_model = $desktop_model;
mbw_set_fields("select_board",$mb_fields["users"]);
@@ -147,6 +147,20 @@
}
add_action('mbw_board_api_header', 'mbw_api_header_admin_modify_passwd');
+if(!function_exists('mbw_api_body_admin_auth_key')){
+ function mbw_api_body_admin_auth_key(){
+ if(mbw_get_param("mode")=="write"){
+ $user_id = mbw_get_param("user_id");
+ if(!empty($user_id)){
+ global $send_data,$mb_fields;
+ $send_data[$mb_fields["users"]["fn_user_auth_key"]] = mbw_get_user_auth_key($user_id);
+ $send_data[$mb_fields["users"]["fn_user_access_token"]] = mbw_generate_access_token($user_id);
+ }
+ }
+ }
+}
+add_action('mbw_board_api_body', 'mbw_api_body_admin_auth_key',5);
+
if(!function_exists('mbw_get_synchronize_template')){
function mbw_get_synchronize_template(){
echo '<div class="border-bottom-ccc-1" style="margin-bottom:10px !important;padding:10px 0 !important;text-align:right;">';
--- a/mangboard/plugins/conversion_tracking/conversion_tracking.php
+++ b/mangboard/plugins/conversion_tracking/conversion_tracking.php
@@ -2,7 +2,7 @@
if(!function_exists('mbw_init_conversion_tracking')){
function mbw_init_conversion_tracking(){
$plugin_url = plugins_url('', __FILE__)."/";
- loadScript($plugin_url."js/main.js");
+ mbw_load_script($plugin_url."js/main.js");
}
}
add_action('wp_enqueue_scripts', 'mbw_init_conversion_tracking',50);
--- a/mangboard/plugins/datepicker/datepicker.php
+++ b/mangboard/plugins/datepicker/datepicker.php
@@ -2,8 +2,8 @@
if(!function_exists('mbw_init_datepicker')){
function mbw_init_datepicker(){
$plugin_url = plugins_url('', __FILE__)."/";
- loadStyle($plugin_url."css/style.css");
- loadScript($plugin_url."js/datepicker.js");
+ mbw_load_style($plugin_url."css/style.css");
+ mbw_load_script($plugin_url."js/datepicker.js");
mbw_enqueue_style('jquery-ui-css', $plugin_url."css/jquery-ui.min.css");
if( mbw_is_admin_page() ) {
wp_enqueue_style('jquery-ui-css');
--- a/mangboard/plugins/editor_composer/editor_composer.php
+++ b/mangboard/plugins/editor_composer/editor_composer.php
@@ -2,7 +2,7 @@
if(!function_exists('mbw_footer_video_scripts')){
function mbw_footer_video_scripts(){
$plugin_url = plugins_url('', __FILE__)."/";
- loadScript($plugin_url."js/video.js","mb-editor-video");
+ mbw_load_script($plugin_url."js/video.js","mb-editor-video");
}
}
add_action('wp_footer', 'mbw_footer_video_scripts',15);
@@ -13,10 +13,10 @@
mbw_add_trace("mbw_init_editor_composer");
wp_enqueue_script( 'jquery-ui-widget', false, array('jquery') );
$plugin_url = plugins_url('', __FILE__)."/";
- loadStyle($plugin_url."css/evol-colorpicker.min.css");
- loadScript($plugin_url."js/evol-colorpicker.min.js","",array('jquery','jquery-ui-widget'));
- loadStyle($plugin_url."css/style.css");
- loadScript($plugin_url."js/main.js");
+ mbw_load_style($plugin_url."css/evol-colorpicker.min.css");
+ mbw_load_script($plugin_url."js/evol-colorpicker.min.js","",array('jquery','jquery-ui-widget'));
+ mbw_load_style($plugin_url."css/style.css");
+ mbw_load_script($plugin_url."js/main.js");
}
}
}
--- a/mangboard/plugins/popup/popup.php
+++ b/mangboard/plugins/popup/popup.php
@@ -2,14 +2,14 @@
if(!function_exists('mbw_init_popup')){
function mbw_init_popup(){
$plugin_url = plugins_url('', __FILE__)."/";
- loadScript($plugin_url."js/main.js");
+ mbw_load_script($plugin_url."js/main.js");
$device_type = mbw_get_vars("device_type");
if($device_type=="desktop"){
- loadStyle($plugin_url."css/style.css");
+ mbw_load_style($plugin_url."css/style.css");
}else if($device_type=="tablet"){
- loadStyle($plugin_url."css/style.css");
+ mbw_load_style($plugin_url."css/style.css");
}else if($device_type=="mobile"){
- loadStyle($plugin_url."css/style.css");
+ mbw_load_style($plugin_url."css/style.css");
}
}
}
--- a/mangboard/templates/mtpl.input.php
+++ b/mangboard/templates/mtpl.input.php
@@ -307,7 +307,7 @@
$checked = ' checked ';
}else $checked = "";
- $template_start .= '<label for="'.esc_attr($data["item_id"].($i+1)).'"><input'.$data["ext"].__STYLE($data["style"]).' type="checkbox" name="'.esc_attr($t_name).'" id="'.esc_attr($data["item_id"].($i+1)).'" value="'.esc_attr($t_data[$i]).'" '.esc_attr($checked).' /><span>'.wp_kses_post($t_label[$i]).'</span></label>';
+ $template_start .= '<label for="'.esc_attr($data["item_id"].($i+1)).'"><input'.$data["ext"].__STYLE($data["style"]).' type="checkbox" name="'.esc_attr($t_name).'" id="'.esc_attr($data["item_id"].($i+1)).'" value="'.esc_attr(trim($t_data[$i])).'" '.esc_attr($checked).' /><span>'.wp_kses_post($t_label[$i]).'</span></label>';
}
}else if(strpos($item_type,'checkbox')===0){
$delimiter = ",";
@@ -346,7 +346,7 @@
$checked = ' checked ';
}else $checked = "";
- $template_start .= '<label for="'.esc_attr($data["item_id"].($i+1)).'"><input'.$data["ext"].__STYLE($data["style"]).' type="radio" name="'.mbw_set_form_name($data["item_name"]).'" id="'.esc_attr($data["item_id"].($i+1)).'" value="'.esc_attr($t_data[$i]).'" '.esc_attr($checked).' /><span>'.wp_kses_post($t_label[$i]).'</span></label>';
+ $template_start .= '<label for="'.esc_attr($data["item_id"].($i+1)).'"><input'.$data["ext"].__STYLE($data["style"]).' type="radio" name="'.mbw_set_form_name($data["item_name"]).'" id="'.esc_attr($data["item_id"].($i+1)).'" value="'.esc_attr(trim($t_data[$i])).'" '.esc_attr($checked).' /><span>'.wp_kses_post($t_label[$i]).'</span></label>';
}
}else if(strpos($item_type,'select')===0){
if(!empty($data["width"])) $data["style"] = "width:".$data["width"]." !important;".$data["style"];
@@ -364,7 +364,7 @@
if(!isset($t_data[$i])) $t_data[$i] = "";
if(!isset($t_label[$i])) $t_label[$i] = "";
- $o_data = ' value="'.esc_attr($t_data[$i]).'"';
+ $o_data = ' value="'.esc_attr(trim($t_data[$i])).'"';
if(strpos($t_data[$i],'select-disabled-')===0){
$o_data = str_replace('select-disabled-',"",$o_data);
$o_data .= ' disabled';
@@ -373,10 +373,10 @@
$o_data .= ' selected';
$item_check = true;
}
- $template_start .= '<option'.$o_data.'>'.strip_tags($t_label[$i]).'</option>';
+ $template_start .= '<option'.$o_data.'>'.strip_tags(trim($t_label[$i])).'</option>';
}
if($data["value"]!="" && !$item_check){
- $template_start .= '<option value="'.esc_attr($data["value"]).'" selected>'.strip_tags($data["value"]).'</option>';
+ $template_start .= '<option value="'.esc_attr(trim($data["value"])).'" selected>'.strip_tags(trim($data["value"])).'</option>';
}
$template_start .= '</select>';