Headline
CVE-2022-0380: options-fotobook.php in fotobook/tags/3.2.3 – WordPress Plugin Repository
The Fotobook WordPress plugin is vulnerable to Reflected Cross-Site Scripting due to insufficient escaping and the use of $_SERVER[‘PHP_SELF’] found in the ~/options-fotobook.php file which allows attackers to inject arbitrary web scripts onto the page, in versions up to and including 3.2.3.
1<?php23/*4Fotobook Options Panel5*/678// get facebook authorization token9$facebook = new FacebookAPI;1011// authorize session12if(isset($_POST[‘activate-facebook’])) {13 $facebook->get_auth_session($_POST[‘activate-facebook’]);14}1516// remove the user17if(isset($_GET[‘deactivate-facebook’]) && isset($facebook->sessions[$_GET[‘deactivate-facebook’]])) {18 $facebook->remove_user($_GET[‘deactivate-facebook’]);19} 2021$this_page = $_SERVER[‘PHP_SELF’].’?page=’.$_GET[‘page’];2223// get styles24$styles = fb_get_styles();2526// update options if form is submitted27if (isset($_POST[‘submit’])) {28 fb_options_update_albums_page($_POST[‘fb_albums_page’]); 29 update_option('fb_number_rows’, $_POST[‘fb_number_rows’]);30 update_option('fb_style’, $_POST[‘fb_style’]);31 if($_POST[‘fb_number_cols’] != 0) {32 update_option('fb_number_cols’, $_POST[‘fb_number_cols’]);33 }34 if(is_numeric($_POST[‘fb_embedded_width’])) {35 update_option('fb_embedded_width’, $_POST[‘fb_embedded_width’]);36 }37 update_option('fb_thumb_size’, $_POST[‘fb_thumb_size’]);38 update_option('fb_albums_per_page’, $_POST[‘fb_albums_per_page’]);39 update_option('fb_hide_pages’, isset($_POST[‘fb_hide_pages’]) ? 1 : 0);40 if(isset($_POST[‘fb_album_cmts’])) {41 fb_options_toggle_comments(true);42 update_option('fb_album_cmts’, 1);43 } else {44 fb_options_toggle_comments(false);45 update_option(‘fb_album_cmts’, 0);46 }47 foreach($styles as $style) {48 $stylesheet = FB_PLUGIN_PATH.’styles/’.$style.’/style.css’;49 if(is_writable($stylesheet)) {50 file_put_contents($stylesheet, $_POST[$style.’_stylesheet’]);51 } 52 }53 $sidebar_stylesheet = FB_PLUGIN_PATH.’styles/sidebar-style.css’;54 if(is_writable($sidebar_stylesheet)) {55 file_put_contents($sidebar_stylesheet, $_POST[‘sidebar_stylesheet’]);56 }57}5859// add a photo album page if there is none60if(get_option(‘fb_albums_page’) == 0) {61 $page = array(62 ‘post_author’ => 1,63 ‘post_content’ =>’’,64 ‘post_title’ =>’Photos’,65 ‘post_name’ =>’photos’,66 ‘comment_status’ =>1,67 ‘post_parent’ =>068 );69 // add a photo album page 70 if(get_bloginfo(‘version’) >= 2.1) { 71 $page[‘post_status’] = ‘publish’;72 $page[‘post_type’] = ‘page’;73 } else {74 $page[‘post_status’] = ‘static’;75 }76 $page_id = wp_insert_post($page);77 update_option(‘fb_albums_page’, $page_id);78}7980// get options to fill in input fields81$fb_session = get_option(‘fb_facebook_session’);82$fb_albums_page = get_option(‘fb_albums_page’);83$fb_number_rows = get_option(‘fb_number_rows’);84$fb_number_cols = get_option(‘fb_number_cols’);85$fb_album_cmts = get_option(‘fb_album_cmts’);86$fb_thumb_size = get_option(‘fb_thumb_size’);87$fb_albums_per_page = get_option(‘fb_albums_per_page’);88$fb_style = get_option(‘fb_style’);89$fb_embedded_width = get_option(‘fb_embedded_width’);90$fb_hide_pages = get_option(‘fb_hide_pages’);9192?>9394<?php if($facebook->msg): ?>95<div id="message" class="<?php echo $facebook->error ? ‘error’ : ‘updated’ ?> fade"><p><?php echo $facebook->msg ?></p></div>96<?php endif; ?>9798<div class="wrap">99 <div id="fb-panel">100 <?php fb_info_box() ?>101 <h2 style="clear: none"><?php _e(‘Fotobook › Settings’) ?> <span><a href="<?php echo FB_MANAGE_URL ?>">Manage Albums »</a></span></h2>102 <p>This plugin links to your Facebook account and imports all of your albums into a page on your blog. To get 103 started you need to give permission to the plugin to access your Facebook account and then import 104 your albums on the management page.</p>105 <h3>Facebook</h3>106 <p>To use this plugin, you must link it to your Facebook account.</p>107 <table class="accounts">108 <tr>109 <td valign="top" width="170">110 <h3>Add an Account</h3>111 <?php if($facebook->token): ?>112 <form method="post" id="apply-permissions" action="<?php echo FB_OPTIONS_URL ?>">113 <input type="hidden" name="activate-facebook" value="<?php echo $facebook->token ?>" />114 <p><a id="grant-permissions" href="http://www.facebook.com/login.php?api_key=<?php echo FB_API_KEY ?>&v=1.0&auth_token=<?php echo $facebook->token ?>&popup=0&skipcookie=1&ext_perm=user_photos,offline_access,user_photo_video_tags" class="button-secondary" target="_blank">Step 1: Authenticate ></a></p>115 <p><a id="request-permissions" href="http://www.facebook.com/connect/prompt_permission.php?api_key=<?php echo FB_API_KEY ?>&next=<?php echo urlencode(‘http://www.facebook.com/desktopapp.php?api_key=’.FB_API_KEY.’&popup=1’) ?>&cancel=http://www.facebook.com/connect/login_failure.html&display=popup&ext_perm=offline_access,user_photos,user_photo_video_tags" class="button-secondary" target="_blank">Step 2: Get Permissions ></a></p>116 <p><input type="submit" class="button-secondary" value="Step 3: Apply Permissions >" /></p>117 </form>118 <?php else: ?>119 Unable to get authorization token.120 <?php endif ?>121 </td>122 <td valign="top">123 <h3>Current Accounts</h3>124 <?php 125 if($facebook->link_active()): 126 foreach($facebook->sessions as $key=>$value): 127 ?>128 <form action="<?php echo $_SERVER[‘PHP_SELF’] ?>" method="get">129 <img src="http://www.facebook.com/favicon.ico" align="absmiddle"> <a href="http://www.facebook.com/profile.php?id=<?php echo $facebook->sessions[$key][‘uid’] ?>" target="_blank"><?php echo $facebook->sessions[$key][‘name’]; ?></a>130 <input type="hidden" name="deactivate-facebook" value="<?php echo $key ?>">131 <input type="hidden" name="page" value="<?php echo $_GET[‘page’] ?>">132 <input type="submit" class="button-secondary" value="Remove" onclick="return confirm(‘Removing an account also removes all of the photos associated with the account. Would you like to continue?’)“>133 </form>134 <?php endforeach; ?>135 <?php else: ?>136 <p>There are currently no active Facebook accounts.</p>137 <?php endif; ?>138 <?php if($facebook->link_active()): ?>139 <p><small>This plugin has been given access to data from your Facebook account. You can revoke this access at any time by clicking remove above or by changing your <a href="http://www.facebook.com/privacy.php?view=platform&tab=ext” target="_blank">privacy</a> settings.</small></p>140 <?php endif; ?>141 </td>142 </tr>143 </table>144 145 <form method="post" action="<?php echo $this_page ?>&updated=true"> 146 <h3><?php _e(‘General’) ?></h3>147 <table class="form-table">148 <tr>149 <th scope="row"><?php _e(‘Albums Page’) ?></th>150 <td>151 <select name="fb_albums_page">152 <?php if(!fb_albums_page_is_set()): ?>153 <option value="0" selected>Please select…</option>154 <?php endif; ?>155 <?php fb_parent_dropdown($fb_albums_page); ?>156 </select><br />157 <small>Select the page you want to use to display the photo albums.</small>158 </td>159 </tr>160 <tr>161 <th scope="row"><?php _e(‘Albums Per Page’) ?></th>162 <td>163 <input name="fb_albums_per_page" type="text" value="<?php echo $fb_albums_per_page; ?>" size="3" />164 <small><?php _e(‘Number of albums to display on each page of the main gallery. Set to \’0\’ to show all.’) ?></small>165 </td>166 </tr>167 <tr>168 <th scope="row"><?php _e(‘Number of Rows’) ?></th>169 <td>170 <input name="fb_number_rows" type="text" value="<?php echo $fb_number_rows; ?>" size="3" />171 <small><?php _e(‘Set to \’0\’ to display all.’) ?></small>172 </td>173 </tr>174 <tr>175 <th scope="row"><?php _e(‘Number of Columns’) ?></th>176 <td>177 <input name="fb_number_cols" type="text" value="<?php echo $fb_number_cols; ?>" size="3" />178 <small><?php _e(‘The number of columns of pictures.’) ?></small>179 </td>180 </tr>181 <tr>182 <th scope="row"><?php _e(‘Display Style’) ?></th>183 <td>184 <select name="fb_style">185 <?php foreach($styles as $style): 186 $selected = $style == $fb_style ? ' selected’ : null; ?>187 <option value="<?php echo $style ?>"<?php echo $selected; ?>><?php echo $style ?></option>188 <?php endforeach; ?>189 </select>190 <small><?php _e(‘Select the style you want to use to display the albums.’) ?></small>191 </td>192 </tr>193 <tr>194 <th scope="row"><?php _e(‘Embedded Width’) ?></th>195 <td>196 <input name="fb_embedded_width" type="text" value="<?php echo $fb_embedded_width; ?>" size="3" />px197 <small><?php _e(‘Restrain the width of the embedded photo if it is too wide for your theme. Set to \’0\’ to display the full size.’) ?></small>198 </td>199 </tr>200 <tr>201 <th scope="row"><?php _e(‘Max Thumbnail Size’) ?></th>202 <td>203 <input name="fb_thumb_size" type="text" value="<?php echo $fb_thumb_size; ?>" size="3" />px204 <small><?php _e(‘The maximum size of the thumbnail. The default is 130px.’) ?></small>205 </td>206 </tr>207 <tr>208 <th scope="row"><?php _e(‘Album Commenting’) ?></th>209 <td>210 <label><input name="fb_album_cmts" type="checkbox" value="1" <?php if($fb_album_cmts) echo ‘checked’; ?> />211 <small><?php _e(‘Allow commenting on individual albums. This must be supported by your theme.’) ?></small></label>212 </td>213 </tr>214 <tr>215 <th scope="row"><?php _e(‘Hide Album Pages’) ?></th>216 <td>217 <label><input name="fb_hide_pages" type="checkbox" value="1" <?php if($fb_hide_pages) echo ‘checked’; ?> />218 <small><?php _e(‘Exclude album pages from being displayed in places where pages are listed.’) ?></small></label>219 </td>220 </tr>221 <tr>222 <th scope="row"><?php _e(‘Cron URL’) ?></th>223 <td>To setup automatic updates of your albums, create a cron job that regularly loads the following URL. If you are unsure how to setup a cron job, <a href="http://www.google.com/search?q=cron">Google</a> is your friend.<br /> <small><?php echo fb_cron_url() ?></small></td>224 </tr>225 </table>226227 <h3><?php _e(‘Stylesheets’) ?></h3>228 <table class="form-table">229 <tr><td>230 <div id="fb-stylesheets" class="editform" style="width: 98%">231 <p>Select:232 <select>233 <?php 234 $styles[] = ‘sidebar’;235 foreach($styles as $style): 236 $selected = $style == $fb_style ? ' selected’ : null; 237 ?>238 <option value="<?php echo $style ?>"<?php echo $selected; ?>><?php echo $style ?></option>239 <?php endforeach; ?>240 </select>241 </p>242 <?php 243 foreach($styles as $style): 244 $stylesheet = FB_PLUGIN_PATH.’styles/’.$style.’/style.css’;245 if($style == ‘sidebar’) $stylesheet = FB_PLUGIN_PATH.’styles/sidebar-style.css’;246 ?>247 <div id="<?php echo $style ?>-stylesheet"<?php echo $style != $fb_style ? ' style="display: none"’ : ‘’ ?>>248 <textarea name="<?php echo $style ?>_stylesheet" style="width: 100%; height: 250px"<?php echo is_writable($stylesheet) ? ‘’ : ' disabled="true"’ ?>><?php echo file_get_contents($stylesheet) ?></textarea>249 <?php echo is_writable($stylesheet) ? ‘’ : ‘<em>This file is not writable.</em>’ ?>250 </div>251 <?php endforeach; ?>252 </div>253 </td></tr>254 </table>255 256 <p><strong><a href="#" id="fb-debug">View Debug Info »</a></strong></p>257 <table class="form-table" id="fb-debug-info" style="display: none">258 <tr>259 <th>Fotobook Version</th>260 <td><?php echo FB_VERSION ?></td>261 </tr>262 <tr>263 <th>WordPress Version</th>264 <td><?php bloginfo(‘version’) ?></td>265 </tr>266 <tr>267 <th>PHP Version</th>268 <td><?php echo PHP_VERSION ?></td>269 </tr>270 <tr>271 <th>Allow URL fopen</th>272 <td><?php echo ini_get(‘allow_url_fopen’) ? ‘Enabled’ : ‘Disabled’ ?></td>273 </tr>274 <tr>275 <th>Curl</th>276 <td><?php echo extension_loaded(‘curl’) ? ‘Installed’ : ‘Not Installed’ ?></td>277 </tr>278 <tr>279 <th>Safe Mode</th>280 <td><?php echo ini_get(‘safe_mode’) ? ‘Enabled’ : ‘Disabled’ ?></td>281 </tr>282 <tr>283 <th>Max Execution Time</th>284 <td><?php echo ini_get(‘max_execution_time’) ?> seconds</td>285 </tr>286 </table>287 288 <p class="submit">289 <input type="submit" name="submit" value="<?php _e(‘Update Options’) ?> »" />290 </p>291 </form>292 </div>293</div>