Plugin Directory

Changeset 3262717


Ignore:
Timestamp:
03/27/2025 10:12:17 AM (12 months ago)
Author:
jidaikobo
Message:

Update to version 3.1.9

Location:
dashi
Files:
1 deleted
6 edited
8 copied

Legend:

Unmodified
Added
Removed
  • dashi/tags/3.1.9/classes/Posttype/PublicForm.php

    r2244334 r3262717  
    212212        $retVal['dashi_uploaded_file'] = true;
    213213
     214        $wp_filetype = wp_check_filetype_and_ext($file['tmp_name'], $file['name']);
     215        if (!$wp_filetype['ext'] || !$wp_filetype['type']) {
     216            $retVal['errors'][] = __('This file type is not allowed.', 'dashi');
     217            return $retVal;
     218        }
     219
    214220        // 拡張子
    215221        $ext = substr($file['name'], strrpos($file['name'], '.'), strlen($file['name']));
     
    282288
    283289        // ファイル名を予測が難しいものにする
    284         $name = wp_unique_filename( DASHI_TMP_UPLOAD_DIR, $name );
     290        $name = wp_unique_filename( DASHI_TMP_UPLOAD_DIR, $file['name']);
    285291
    286292        $retVal['name'] = $name;
     
    526532                foreach ($each_errors as $error)
    527533                {
    528                     $html.= '<li><a href="#dashi_'.$k.'">'.$error.'</a></li>';
     534                    $html.= '<li><a href="#dashi_'.$k.'">'.esc_html($error).'</a></li>';
    529535                }
    530536            }
     
    557563            if (isset($attrs['type']) && ! in_array($attrs['type'], array('checkbox', 'radio')))
    558564            {
    559                 $label = '<label for="dashi_'.$field.'">'.$label.'</label>';
     565                $label = '<label for="dashi_'.$field.'">'.esc_html($label).'</label>';
    560566            }
    561567
     
    715721            if (isset($v['private_form_only']) && $v['private_form_only'] == true) continue;
    716722
    717             $html.= '<dt>'.$v['label'].'</dt>';
     723            $html.= '<dt>'.esc_html($v['label']).'</dt>';
    718724            $html.= '<dd>';
    719725            if (isset($vals->$k))
     
    762768                        else
    763769                        {
    764                             $html.= join(', ', $vals->$k);
     770                            $html.= join(', ', array_map('esc_html', $vals->$k));
    765771                        }
    766772                    }
  • dashi/tags/3.1.9/dashi.php

    r3261519 r3262717  
    77Text Domain: dashi
    88Domain Path: /languages/
    9 Version: 3.1.8
     9Version: 3.1.9
    1010Author URI: http://www.jidaikobo.com/
    1111thx: https://github.com/trentrichardson/jQuery-Timepicker-Addon/tree/master/src
     
    3131if (defined('WP_INSTALLING') && WP_INSTALLING)
    3232{
    33     return;
     33    return;
    3434}
    3535
    3636// language
    3737add_action(
    38     'init',
    39     function () {
    40         load_plugin_textdomain(
    41             'dashi',
    42             FALSE,
    43             plugin_basename(__DIR__).'/languages'
    44         );
    45     }
     38    'init',
     39    function () {
     40        load_plugin_textdomain(
     41            'dashi',
     42            FALSE,
     43            plugin_basename(__DIR__).'/languages'
     44        );
     45    }
    4646);
    4747
     
    5656define('DASHI_FILE', __FILE__);
    5757define('DASHI_DIR', __DIR__);
    58 define('DASHI_TMP_UPLOAD_DIR', dirname(WP_PLUGIN_DIR).'/dashi_uploads/');
     58
     59$upload_dir = wp_upload_dir();
     60define('DASHI_TMP_UPLOAD_DIR', trailingslashit($upload_dir['basedir']) . 'dashi_uploads/');
    5961
    6062// forge to init
     
    7274// option menu
    7375add_action(
    74     'admin_menu',
    75     function ()
    76     {
    77         add_options_page(
    78             __('Dashi Framework', 'dashi'),
    79             __('Dashi Framework', 'dashi'),
    80             'level_10',
    81             'dashi_options',
    82             array('\\Dashi\\Core\\Option', 'setting')
    83         );
    84     });
    85 
    86 // dashi environmental check
    87 // add_action(
    88 //  'admin_menu',
    89 //  function ()
    90 //  {
    91 //      $n = '<span id="dashi_env_chk" data-dashi-ajax-url="'.admin_url('admin-ajax.php').'"><span></span></span>';
    92 // //       $n = '<span class="update-plugins count-1" id="dashi_env_chk" data-dashi-ajax-url="'.admin_url('admin-ajax.php').'"><span class="update-count"></span></span>';
    93 //      add_submenu_page(
    94 //          'index.php',
    95 //          __('Dashi Framework', 'dashi'),
    96 //          __('Dashi Framework', 'dashi').$n,
    97 //          'level_10',
    98 //          'dashi_todos',
    99 //          array('\\Dashi\\Core\\Option', 'setting')
    100 //      );
    101 //  });
    102 
    103 // add_action(
    104 //  'wp_ajax_dashi_ajax_env_check',
    105 //  function ()
    106 //  {
    107 //      ob_start();
    108 //      \Dashi\Core\Notation::ajax();
    109 //      $buffer = ob_get_contents();
    110 //      ob_end_clean();
    111 //      wp_send_json_success($buffer);
    112 //  }
    113 // );
     76    'admin_menu',
     77    function ()
     78    {
     79        add_options_page(
     80            __('Dashi Framework', 'dashi'),
     81            __('Dashi Framework', 'dashi'),
     82            'manage_options',
     83            'dashi_options',
     84            array('\\Dashi\\Core\\Option', 'setting')
     85        );
     86    });
    11487
    11588// activation hook
    11689register_activation_hook(
    117     DASHI_FILE,
    118     function ($network_wide)
    119     {
    120         $update = function ()
    121         {
    122             // update option - default on
    123             foreach (array_keys(\Dashi\Core\Option::getOptions()) as $v)
    124             {
    125                 if ($v == 'dashi_google_map_api_key') continue;
    126                 if ($v == 'dashi_server_accesslog_is_ok') continue;
    127                 if ($v == 'dashi_backup_is_ok') continue;
    128                 if ($v == 'dashi_allow_comments') continue;
    129                 if ($v == 'dashi_allow_xmlrpc') continue;
    130                 if ($v == 'dashi_keep_ssl_connection') continue;
    131                 if ($v == 'dashi_specify_search_index') continue;
    132                 if ($v == 'dashi_no_need_analytics') continue;
    133                 if ($v == 'dashi_no_need_security_plugin') continue;
    134                 if ($v == 'dashi_no_need_sitemap_plugin') continue;
    135                 if ($v == 'dashi_no_need_dev_plugin') continue;
    136                 if ($v == 'dashi_no_need_acc_plugin') continue;
    137                 if ($v == 'dashi_do_not_heavy_dashboard_check') continue;
    138                 if ($v == 'dashi_sitemap_page_upsidedown') continue;
    139                 if ($v == 'dashi_do_eliminate_utf_separation') continue;
    140                 if ($v == 'dashi_sitemap_home_string') continue;
    141                 update_option($v, 1);
    142             }
    143         };
    144 
    145         if (is_multisite() && $network_wide)
    146         {
    147             global $wpdb;
    148 
    149             foreach ($wpdb->get_col("SELECT blog_id FROM $wpdb->blogs") as $blog_id) {
    150                 switch_to_blog($blog_id);
    151                 $update();
    152                 restore_current_blog();
    153             }
    154         } else {
    155             $update();
    156         }
    157     }
     90    DASHI_FILE,
     91    function ($network_wide)
     92    {
     93        $update = function ()
     94        {
     95            // update option - default on
     96            foreach (array_keys(\Dashi\Core\Option::getOptions()) as $v)
     97            {
     98                if ($v == 'dashi_google_map_api_key') continue;
     99                if ($v == 'dashi_server_accesslog_is_ok') continue;
     100                if ($v == 'dashi_backup_is_ok') continue;
     101                if ($v == 'dashi_allow_comments') continue;
     102                if ($v == 'dashi_allow_xmlrpc') continue;
     103                if ($v == 'dashi_keep_ssl_connection') continue;
     104                if ($v == 'dashi_specify_search_index') continue;
     105                if ($v == 'dashi_no_need_analytics') continue;
     106                if ($v == 'dashi_no_need_security_plugin') continue;
     107                if ($v == 'dashi_no_need_sitemap_plugin') continue;
     108                if ($v == 'dashi_no_need_dev_plugin') continue;
     109                if ($v == 'dashi_no_need_acc_plugin') continue;
     110                if ($v == 'dashi_do_not_heavy_dashboard_check') continue;
     111                if ($v == 'dashi_sitemap_page_upsidedown') continue;
     112                if ($v == 'dashi_do_eliminate_utf_separation') continue;
     113                if ($v == 'dashi_sitemap_home_string') continue;
     114                update_option($v, 1);
     115            }
     116        };
     117
     118        if (is_multisite() && $network_wide)
     119        {
     120            global $wpdb;
     121
     122            foreach ($wpdb->get_col("SELECT blog_id FROM $wpdb->blogs") as $blog_id) {
     123                switch_to_blog($blog_id);
     124                $update();
     125                restore_current_blog();
     126            }
     127        } else {
     128            $update();
     129        }
     130    }
    158131);
    159132
     
    161134if (get_option('dashi_keep_ssl_connection'))
    162135{
    163     add_action(
    164         'template_redirect',
    165         function()
    166         {
    167             // HTTPS
    168             if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == "on") return;
    169 
    170             // GuzzleHttp
    171             if (
    172                 isset($_SERVER['HTTP_USER_AGENT']) &&
    173                 strpos($_SERVER['HTTP_USER_AGENT'], 'GuzzleHttp') !== false
    174             ) return;
    175 
    176             // redirect
    177             $location = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    178             wp_safe_redirect($location, '301'); //Moved Permanently
    179             exit;
    180         }
    181     );
     136    add_action(
     137        'template_redirect',
     138        function()
     139        {
     140            // HTTPS
     141            if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == "on") return;
     142
     143            // GuzzleHttp
     144            if (
     145                isset($_SERVER['HTTP_USER_AGENT']) &&
     146                strpos($_SERVER['HTTP_USER_AGENT'], 'GuzzleHttp') !== false
     147            ) return;
     148
     149            // redirect
     150            $location = esc_url_raw("https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
     151            wp_safe_redirect($location, '301'); //Moved Permanently
     152            exit;
     153        }
     154    );
    182155}
    183156
    184157// add Shortcode - is_user_logged_in area
    185158add_shortcode(
    186     'loggedin',
    187     array('\\Dashi\\Core\\Shortcode', 'is_user_logged_in')
     159    'loggedin',
     160    array('\\Dashi\\Core\\Shortcode', 'is_user_logged_in')
    188161);
    189162
    190163// sticky
    191164add_action(
    192     'post_date_column_status',
    193     array('\\Dashi\\Core\\Posttype\\Sticky', 'column'),
    194     2,
    195     10
     165    'post_date_column_status',
     166    array('\\Dashi\\Core\\Posttype\\Sticky', 'column'),
     167    2,
     168    10
    196169);
    197170
     
    199172// thx http://www.warna.info/archives/2593/
    200173add_filter('admin_body_class',
    201     function ($admin_body_class)
    202     {
    203         global $current_user;
    204         if ( ! $admin_body_class ) {
    205             $admin_body_class .= ' ';
    206         }
    207         $admin_body_class .= 'role-' . urlencode( $current_user->roles[0] );
    208         return $admin_body_class;
    209     }
     174    function ($admin_body_class)
     175    {
     176        global $current_user;
     177        if ( ! $admin_body_class ) {
     178            $admin_body_class .= ' ';
     179        }
     180        $admin_body_class .= 'role-' . urlencode( $current_user->roles[0] );
     181        return $admin_body_class;
     182    }
    210183);
    211184
     
    213186if (get_option('dashi_show_wp_version'))
    214187{
    215     add_action(
    216         'admin_bar_menu',
    217         function ($wp_admin_bar)
    218         {
    219             $title = sprintf(
    220                 '<span class="ab-icon"></span><span class="ab-label">ver. %s</span>',
    221                 get_bloginfo('version')
    222             );
    223             $wp_admin_bar->add_menu(array(
    224                     'id'    => 'dashi_show_wp_version',
    225                     'meta'  => array(),
    226                     'title' => $title,
    227                     'href'  => admin_url('update-core.php')
    228                 ));
    229         },
    230         9999
    231     );
     188    add_action(
     189        'admin_bar_menu',
     190        function ($wp_admin_bar)
     191        {
     192            $title = sprintf(
     193                '<span class="ab-icon"></span><span class="ab-label">ver. %s</span>',
     194                get_bloginfo('version')
     195            );
     196            $wp_admin_bar->add_menu(array(
     197                    'id'    => 'dashi_show_wp_version',
     198                    'meta'  => array(),
     199                    'title' => $title,
     200                    'href'  => admin_url('update-core.php')
     201                ));
     202        },
     203        9999
     204    );
    232205}
    233206
     
    235208if (get_option('dashi_auto_update_core'))
    236209{
    237     add_filter('allow_major_auto_core_updates', '__return_true');
     210    add_filter('allow_major_auto_core_updates', '__return_true');
    238211}
    239212
    240213if (get_option('dashi_auto_update_theme'))
    241214{
    242     add_filter('auto_update_theme', '__return_true');
     215    add_filter('auto_update_theme', '__return_true');
    243216}
    244217
    245218if (get_option('dashi_auto_update_plugin'))
    246219{
    247     add_filter('auto_update_plugin', '__return_true');
     220    add_filter('auto_update_plugin', '__return_true');
    248221}
    249222
    250223if (get_option('dashi_auto_update_language'))
    251224{
    252     add_filter('auto_update_translation', '__return_true');
     225    add_filter('auto_update_translation', '__return_true');
    253226}
    254227
     
    256229if (get_option('dashi_do_eliminate_control_codes'))
    257230{
    258     add_action(
    259         'init',
    260         function () {
    261             remove_action('template_redirect', 'wp_redirect_admin_locations', 1000);
    262         }
    263     );
    264 }
     231    add_action(
     232        'init',
     233        function () {
     234            remove_action('template_redirect', 'wp_redirect_admin_locations', 1000);
     235        }
     236    );
     237}
  • dashi/tags/3.1.9/file.php

    r1738272 r3262717  
    11<?php
    2 // too heavy...
    3 // include dirname(dirname(dirname(dirname(__FILE__)))).'/wp-blog-header.php';
    4 // if ( ! is_user_logged_in()) die();
     2// WordPress のルートパスを指定して読み込む
     3require_once dirname(__FILE__, 4) . '/wp-load.php';
    54
    6 // tiny check
    7 // $ok = false;
    8 // if (isset($_COOKIE))
    9 // {
    10 //  foreach (array_keys($_COOKIE) as $k)
    11 //  {
    12 //      if (substr($k, 0, 20) == 'wordpress_logged_in_')
    13 //      {
    14 //          $ok = TRUE;
    15 //          break;
    16 //      }
    17 //  }
    18 // }
     5// アップロードディレクトリのパスを取得(WordPressの /uploads/dashi_uploads/ 配下に限定)
     6$upload_dir = wp_upload_dir();
     7$base_dir = trailingslashit($upload_dir['basedir']) . 'dashi_uploads/';
    198
    20 $ok = true;
    21 $image_file = isset($_GET['path']) ? dirname(dirname(__DIR__)).'/dashi_uploads/'.$_GET['path'] : '';
     9// ファイル名を取得(basename でパストラバーサル防止)
     10$filename = basename($_GET['path'] ?? '');
    2211
     12// 許可拡張子をチェック
     13$allowed_ext = ['jpg', 'jpeg', 'pdf'];
     14$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
     15if (!in_array($ext, $allowed_ext, true)) {
     16    status_header(403);
     17    exit('Forbidden: Invalid file type.');
     18}
     19
     20// 絶対パスを組み立てて検証
     21$filepath = realpath($base_dir . $filename);
    2322if (
    24     $ok &&
    25     file_exists($image_file) &&
    26     in_array(substr(strtolower($image_file), -4), array('.jpg', 'jpeg', '.pdf'))
    27 )
    28 {
    29     $size = filesize($image_file);
    30     header("Content-Length: $size");
    31     if (substr(strtolower($image_file), -3) == 'pdf')
    32     {
    33         header("Content-type: application/pdf");
    34     }
    35     else
    36     {
    37         header("Content-type: image/jpeg");
    38     }
    39     readfile($image_file);
     23    $filepath === false || // ファイルが存在しない
     24    strpos($filepath, realpath($base_dir)) !== 0 || // アップロードディレクトリ外を指している
     25    !file_exists($filepath)
     26) {
     27    status_header(404);
     28    exit('File not found.');
    4029}
    41 else
    42 {
    43     header("HTTP/1.0 404 Not Found");
    44     die();
    45 }
     30
     31// 適切な Content-Type を送信
     32$content_types = [
     33    'jpg' => 'image/jpeg',
     34    'jpeg' => 'image/jpeg',
     35    'pdf' => 'application/pdf',
     36];
     37header('Content-Type: ' . $content_types[$ext]);
     38header('Content-Length: ' . filesize($filepath));
     39
     40// ファイル出力
     41readfile($filepath);
     42exit;
  • dashi/tags/3.1.9/readme.txt

    r3261519 r3262717  
    55Requires at least: 4.9.7
    66Tested up to: 6.7.1
    7 Stable tag: 3.1.8
     7Stable tag: 3.1.9
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    4444== Changelog ==
    4545
     46= 3.1.9 =
     47fix path traversal
     48
    4649= 3.1.8 =
    4750fix sashikae issue
  • dashi/trunk/classes/Posttype/PublicForm.php

    r2244334 r3262717  
    212212        $retVal['dashi_uploaded_file'] = true;
    213213
     214        $wp_filetype = wp_check_filetype_and_ext($file['tmp_name'], $file['name']);
     215        if (!$wp_filetype['ext'] || !$wp_filetype['type']) {
     216            $retVal['errors'][] = __('This file type is not allowed.', 'dashi');
     217            return $retVal;
     218        }
     219
    214220        // 拡張子
    215221        $ext = substr($file['name'], strrpos($file['name'], '.'), strlen($file['name']));
     
    282288
    283289        // ファイル名を予測が難しいものにする
    284         $name = wp_unique_filename( DASHI_TMP_UPLOAD_DIR, $name );
     290        $name = wp_unique_filename( DASHI_TMP_UPLOAD_DIR, $file['name']);
    285291
    286292        $retVal['name'] = $name;
     
    526532                foreach ($each_errors as $error)
    527533                {
    528                     $html.= '<li><a href="#dashi_'.$k.'">'.$error.'</a></li>';
     534                    $html.= '<li><a href="#dashi_'.$k.'">'.esc_html($error).'</a></li>';
    529535                }
    530536            }
     
    557563            if (isset($attrs['type']) && ! in_array($attrs['type'], array('checkbox', 'radio')))
    558564            {
    559                 $label = '<label for="dashi_'.$field.'">'.$label.'</label>';
     565                $label = '<label for="dashi_'.$field.'">'.esc_html($label).'</label>';
    560566            }
    561567
     
    715721            if (isset($v['private_form_only']) && $v['private_form_only'] == true) continue;
    716722
    717             $html.= '<dt>'.$v['label'].'</dt>';
     723            $html.= '<dt>'.esc_html($v['label']).'</dt>';
    718724            $html.= '<dd>';
    719725            if (isset($vals->$k))
     
    762768                        else
    763769                        {
    764                             $html.= join(', ', $vals->$k);
     770                            $html.= join(', ', array_map('esc_html', $vals->$k));
    765771                        }
    766772                    }
  • dashi/trunk/dashi.php

    r3261519 r3262717  
    77Text Domain: dashi
    88Domain Path: /languages/
    9 Version: 3.1.8
     9Version: 3.1.9
    1010Author URI: http://www.jidaikobo.com/
    1111thx: https://github.com/trentrichardson/jQuery-Timepicker-Addon/tree/master/src
     
    3131if (defined('WP_INSTALLING') && WP_INSTALLING)
    3232{
    33     return;
     33    return;
    3434}
    3535
    3636// language
    3737add_action(
    38     'init',
    39     function () {
    40         load_plugin_textdomain(
    41             'dashi',
    42             FALSE,
    43             plugin_basename(__DIR__).'/languages'
    44         );
    45     }
     38    'init',
     39    function () {
     40        load_plugin_textdomain(
     41            'dashi',
     42            FALSE,
     43            plugin_basename(__DIR__).'/languages'
     44        );
     45    }
    4646);
    4747
     
    5656define('DASHI_FILE', __FILE__);
    5757define('DASHI_DIR', __DIR__);
    58 define('DASHI_TMP_UPLOAD_DIR', dirname(WP_PLUGIN_DIR).'/dashi_uploads/');
     58
     59$upload_dir = wp_upload_dir();
     60define('DASHI_TMP_UPLOAD_DIR', trailingslashit($upload_dir['basedir']) . 'dashi_uploads/');
    5961
    6062// forge to init
     
    7274// option menu
    7375add_action(
    74     'admin_menu',
    75     function ()
    76     {
    77         add_options_page(
    78             __('Dashi Framework', 'dashi'),
    79             __('Dashi Framework', 'dashi'),
    80             'level_10',
    81             'dashi_options',
    82             array('\\Dashi\\Core\\Option', 'setting')
    83         );
    84     });
    85 
    86 // dashi environmental check
    87 // add_action(
    88 //  'admin_menu',
    89 //  function ()
    90 //  {
    91 //      $n = '<span id="dashi_env_chk" data-dashi-ajax-url="'.admin_url('admin-ajax.php').'"><span></span></span>';
    92 // //       $n = '<span class="update-plugins count-1" id="dashi_env_chk" data-dashi-ajax-url="'.admin_url('admin-ajax.php').'"><span class="update-count"></span></span>';
    93 //      add_submenu_page(
    94 //          'index.php',
    95 //          __('Dashi Framework', 'dashi'),
    96 //          __('Dashi Framework', 'dashi').$n,
    97 //          'level_10',
    98 //          'dashi_todos',
    99 //          array('\\Dashi\\Core\\Option', 'setting')
    100 //      );
    101 //  });
    102 
    103 // add_action(
    104 //  'wp_ajax_dashi_ajax_env_check',
    105 //  function ()
    106 //  {
    107 //      ob_start();
    108 //      \Dashi\Core\Notation::ajax();
    109 //      $buffer = ob_get_contents();
    110 //      ob_end_clean();
    111 //      wp_send_json_success($buffer);
    112 //  }
    113 // );
     76    'admin_menu',
     77    function ()
     78    {
     79        add_options_page(
     80            __('Dashi Framework', 'dashi'),
     81            __('Dashi Framework', 'dashi'),
     82            'manage_options',
     83            'dashi_options',
     84            array('\\Dashi\\Core\\Option', 'setting')
     85        );
     86    });
    11487
    11588// activation hook
    11689register_activation_hook(
    117     DASHI_FILE,
    118     function ($network_wide)
    119     {
    120         $update = function ()
    121         {
    122             // update option - default on
    123             foreach (array_keys(\Dashi\Core\Option::getOptions()) as $v)
    124             {
    125                 if ($v == 'dashi_google_map_api_key') continue;
    126                 if ($v == 'dashi_server_accesslog_is_ok') continue;
    127                 if ($v == 'dashi_backup_is_ok') continue;
    128                 if ($v == 'dashi_allow_comments') continue;
    129                 if ($v == 'dashi_allow_xmlrpc') continue;
    130                 if ($v == 'dashi_keep_ssl_connection') continue;
    131                 if ($v == 'dashi_specify_search_index') continue;
    132                 if ($v == 'dashi_no_need_analytics') continue;
    133                 if ($v == 'dashi_no_need_security_plugin') continue;
    134                 if ($v == 'dashi_no_need_sitemap_plugin') continue;
    135                 if ($v == 'dashi_no_need_dev_plugin') continue;
    136                 if ($v == 'dashi_no_need_acc_plugin') continue;
    137                 if ($v == 'dashi_do_not_heavy_dashboard_check') continue;
    138                 if ($v == 'dashi_sitemap_page_upsidedown') continue;
    139                 if ($v == 'dashi_do_eliminate_utf_separation') continue;
    140                 if ($v == 'dashi_sitemap_home_string') continue;
    141                 update_option($v, 1);
    142             }
    143         };
    144 
    145         if (is_multisite() && $network_wide)
    146         {
    147             global $wpdb;
    148 
    149             foreach ($wpdb->get_col("SELECT blog_id FROM $wpdb->blogs") as $blog_id) {
    150                 switch_to_blog($blog_id);
    151                 $update();
    152                 restore_current_blog();
    153             }
    154         } else {
    155             $update();
    156         }
    157     }
     90    DASHI_FILE,
     91    function ($network_wide)
     92    {
     93        $update = function ()
     94        {
     95            // update option - default on
     96            foreach (array_keys(\Dashi\Core\Option::getOptions()) as $v)
     97            {
     98                if ($v == 'dashi_google_map_api_key') continue;
     99                if ($v == 'dashi_server_accesslog_is_ok') continue;
     100                if ($v == 'dashi_backup_is_ok') continue;
     101                if ($v == 'dashi_allow_comments') continue;
     102                if ($v == 'dashi_allow_xmlrpc') continue;
     103                if ($v == 'dashi_keep_ssl_connection') continue;
     104                if ($v == 'dashi_specify_search_index') continue;
     105                if ($v == 'dashi_no_need_analytics') continue;
     106                if ($v == 'dashi_no_need_security_plugin') continue;
     107                if ($v == 'dashi_no_need_sitemap_plugin') continue;
     108                if ($v == 'dashi_no_need_dev_plugin') continue;
     109                if ($v == 'dashi_no_need_acc_plugin') continue;
     110                if ($v == 'dashi_do_not_heavy_dashboard_check') continue;
     111                if ($v == 'dashi_sitemap_page_upsidedown') continue;
     112                if ($v == 'dashi_do_eliminate_utf_separation') continue;
     113                if ($v == 'dashi_sitemap_home_string') continue;
     114                update_option($v, 1);
     115            }
     116        };
     117
     118        if (is_multisite() && $network_wide)
     119        {
     120            global $wpdb;
     121
     122            foreach ($wpdb->get_col("SELECT blog_id FROM $wpdb->blogs") as $blog_id) {
     123                switch_to_blog($blog_id);
     124                $update();
     125                restore_current_blog();
     126            }
     127        } else {
     128            $update();
     129        }
     130    }
    158131);
    159132
     
    161134if (get_option('dashi_keep_ssl_connection'))
    162135{
    163     add_action(
    164         'template_redirect',
    165         function()
    166         {
    167             // HTTPS
    168             if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == "on") return;
    169 
    170             // GuzzleHttp
    171             if (
    172                 isset($_SERVER['HTTP_USER_AGENT']) &&
    173                 strpos($_SERVER['HTTP_USER_AGENT'], 'GuzzleHttp') !== false
    174             ) return;
    175 
    176             // redirect
    177             $location = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    178             wp_safe_redirect($location, '301'); //Moved Permanently
    179             exit;
    180         }
    181     );
     136    add_action(
     137        'template_redirect',
     138        function()
     139        {
     140            // HTTPS
     141            if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == "on") return;
     142
     143            // GuzzleHttp
     144            if (
     145                isset($_SERVER['HTTP_USER_AGENT']) &&
     146                strpos($_SERVER['HTTP_USER_AGENT'], 'GuzzleHttp') !== false
     147            ) return;
     148
     149            // redirect
     150            $location = esc_url_raw("https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
     151            wp_safe_redirect($location, '301'); //Moved Permanently
     152            exit;
     153        }
     154    );
    182155}
    183156
    184157// add Shortcode - is_user_logged_in area
    185158add_shortcode(
    186     'loggedin',
    187     array('\\Dashi\\Core\\Shortcode', 'is_user_logged_in')
     159    'loggedin',
     160    array('\\Dashi\\Core\\Shortcode', 'is_user_logged_in')
    188161);
    189162
    190163// sticky
    191164add_action(
    192     'post_date_column_status',
    193     array('\\Dashi\\Core\\Posttype\\Sticky', 'column'),
    194     2,
    195     10
     165    'post_date_column_status',
     166    array('\\Dashi\\Core\\Posttype\\Sticky', 'column'),
     167    2,
     168    10
    196169);
    197170
     
    199172// thx http://www.warna.info/archives/2593/
    200173add_filter('admin_body_class',
    201     function ($admin_body_class)
    202     {
    203         global $current_user;
    204         if ( ! $admin_body_class ) {
    205             $admin_body_class .= ' ';
    206         }
    207         $admin_body_class .= 'role-' . urlencode( $current_user->roles[0] );
    208         return $admin_body_class;
    209     }
     174    function ($admin_body_class)
     175    {
     176        global $current_user;
     177        if ( ! $admin_body_class ) {
     178            $admin_body_class .= ' ';
     179        }
     180        $admin_body_class .= 'role-' . urlencode( $current_user->roles[0] );
     181        return $admin_body_class;
     182    }
    210183);
    211184
     
    213186if (get_option('dashi_show_wp_version'))
    214187{
    215     add_action(
    216         'admin_bar_menu',
    217         function ($wp_admin_bar)
    218         {
    219             $title = sprintf(
    220                 '<span class="ab-icon"></span><span class="ab-label">ver. %s</span>',
    221                 get_bloginfo('version')
    222             );
    223             $wp_admin_bar->add_menu(array(
    224                     'id'    => 'dashi_show_wp_version',
    225                     'meta'  => array(),
    226                     'title' => $title,
    227                     'href'  => admin_url('update-core.php')
    228                 ));
    229         },
    230         9999
    231     );
     188    add_action(
     189        'admin_bar_menu',
     190        function ($wp_admin_bar)
     191        {
     192            $title = sprintf(
     193                '<span class="ab-icon"></span><span class="ab-label">ver. %s</span>',
     194                get_bloginfo('version')
     195            );
     196            $wp_admin_bar->add_menu(array(
     197                    'id'    => 'dashi_show_wp_version',
     198                    'meta'  => array(),
     199                    'title' => $title,
     200                    'href'  => admin_url('update-core.php')
     201                ));
     202        },
     203        9999
     204    );
    232205}
    233206
     
    235208if (get_option('dashi_auto_update_core'))
    236209{
    237     add_filter('allow_major_auto_core_updates', '__return_true');
     210    add_filter('allow_major_auto_core_updates', '__return_true');
    238211}
    239212
    240213if (get_option('dashi_auto_update_theme'))
    241214{
    242     add_filter('auto_update_theme', '__return_true');
     215    add_filter('auto_update_theme', '__return_true');
    243216}
    244217
    245218if (get_option('dashi_auto_update_plugin'))
    246219{
    247     add_filter('auto_update_plugin', '__return_true');
     220    add_filter('auto_update_plugin', '__return_true');
    248221}
    249222
    250223if (get_option('dashi_auto_update_language'))
    251224{
    252     add_filter('auto_update_translation', '__return_true');
     225    add_filter('auto_update_translation', '__return_true');
    253226}
    254227
     
    256229if (get_option('dashi_do_eliminate_control_codes'))
    257230{
    258     add_action(
    259         'init',
    260         function () {
    261             remove_action('template_redirect', 'wp_redirect_admin_locations', 1000);
    262         }
    263     );
    264 }
     231    add_action(
     232        'init',
     233        function () {
     234            remove_action('template_redirect', 'wp_redirect_admin_locations', 1000);
     235        }
     236    );
     237}
  • dashi/trunk/file.php

    r1738272 r3262717  
    11<?php
    2 // too heavy...
    3 // include dirname(dirname(dirname(dirname(__FILE__)))).'/wp-blog-header.php';
    4 // if ( ! is_user_logged_in()) die();
     2// WordPress のルートパスを指定して読み込む
     3require_once dirname(__FILE__, 4) . '/wp-load.php';
    54
    6 // tiny check
    7 // $ok = false;
    8 // if (isset($_COOKIE))
    9 // {
    10 //  foreach (array_keys($_COOKIE) as $k)
    11 //  {
    12 //      if (substr($k, 0, 20) == 'wordpress_logged_in_')
    13 //      {
    14 //          $ok = TRUE;
    15 //          break;
    16 //      }
    17 //  }
    18 // }
     5// アップロードディレクトリのパスを取得(WordPressの /uploads/dashi_uploads/ 配下に限定)
     6$upload_dir = wp_upload_dir();
     7$base_dir = trailingslashit($upload_dir['basedir']) . 'dashi_uploads/';
    198
    20 $ok = true;
    21 $image_file = isset($_GET['path']) ? dirname(dirname(__DIR__)).'/dashi_uploads/'.$_GET['path'] : '';
     9// ファイル名を取得(basename でパストラバーサル防止)
     10$filename = basename($_GET['path'] ?? '');
    2211
     12// 許可拡張子をチェック
     13$allowed_ext = ['jpg', 'jpeg', 'pdf'];
     14$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
     15if (!in_array($ext, $allowed_ext, true)) {
     16    status_header(403);
     17    exit('Forbidden: Invalid file type.');
     18}
     19
     20// 絶対パスを組み立てて検証
     21$filepath = realpath($base_dir . $filename);
    2322if (
    24     $ok &&
    25     file_exists($image_file) &&
    26     in_array(substr(strtolower($image_file), -4), array('.jpg', 'jpeg', '.pdf'))
    27 )
    28 {
    29     $size = filesize($image_file);
    30     header("Content-Length: $size");
    31     if (substr(strtolower($image_file), -3) == 'pdf')
    32     {
    33         header("Content-type: application/pdf");
    34     }
    35     else
    36     {
    37         header("Content-type: image/jpeg");
    38     }
    39     readfile($image_file);
     23    $filepath === false || // ファイルが存在しない
     24    strpos($filepath, realpath($base_dir)) !== 0 || // アップロードディレクトリ外を指している
     25    !file_exists($filepath)
     26) {
     27    status_header(404);
     28    exit('File not found.');
    4029}
    41 else
    42 {
    43     header("HTTP/1.0 404 Not Found");
    44     die();
    45 }
     30
     31// 適切な Content-Type を送信
     32$content_types = [
     33    'jpg' => 'image/jpeg',
     34    'jpeg' => 'image/jpeg',
     35    'pdf' => 'application/pdf',
     36];
     37header('Content-Type: ' . $content_types[$ext]);
     38header('Content-Length: ' . filesize($filepath));
     39
     40// ファイル出力
     41readfile($filepath);
     42exit;
  • dashi/trunk/readme.txt

    r3261519 r3262717  
    55Requires at least: 4.9.7
    66Tested up to: 6.7.1
    7 Stable tag: 3.1.8
     7Stable tag: 3.1.9
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    4444== Changelog ==
    4545
     46= 3.1.9 =
     47fix path traversal
     48
    4649= 3.1.8 =
    4750fix sashikae issue
Note: See TracChangeset for help on using the changeset viewer.