<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[17994] trunk: Sanitize guid on save and display.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/17994">17994</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2011-05-22 23:19:42 +0000 (Sun, 22 May 2011)</dd>
</dl>
<h3>Log Message</h3>
<pre>Sanitize guid on save and display. Sanitize mime type on save. Don't allow changing mime type via edit form handlers. Protect hidden meta.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminadminajaxphp">trunk/wp-admin/admin-ajax.php</a></li>
<li><a href="#trunkwpadminincludesmediaphp">trunk/wp-admin/includes/media.php</a></li>
<li><a href="#trunkwpadminincludespostphp">trunk/wp-admin/includes/post.php</a></li>
<li><a href="#trunkwpadminincludestemplatephp">trunk/wp-admin/includes/template.php</a></li>
<li><a href="#trunkwpincludesdefaultfiltersphp">trunk/wp-includes/default-filters.php</a></li>
<li><a href="#trunkwpincludesformattingphp">trunk/wp-includes/formatting.php</a></li>
<li><a href="#trunkwpincludesmetaphp">trunk/wp-includes/meta.php</a></li>
<li><a href="#trunkwpincludesthemephp">trunk/wp-includes/theme.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminadminajaxphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/admin-ajax.php (17993 => 17994)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/admin-ajax.php        2011-05-22 23:19:12 UTC (rev 17993)
+++ trunk/wp-admin/admin-ajax.php        2011-05-22 23:19:42 UTC (rev 17994)
</span><span class="lines">@@ -396,7 +396,7 @@
</span><span class="cx">         if ( !$meta = get_post_meta_by_id( $id ) )
</span><span class="cx">                 die('1');
</span><span class="cx">
</span><del>-        if ( !current_user_can( 'edit_post', $meta->post_id ) )
</del><ins>+        if ( !current_user_can( 'edit_post', $meta->post_id ) || is_protected_meta( $meta->meta_key ) )
</ins><span class="cx">                 die('-1');
</span><span class="cx">         if ( delete_meta( $meta->meta_id ) )
</span><span class="cx">                 die('1');
</span><span class="lines">@@ -865,6 +865,8 @@
</span><span class="cx">                         die('0'); // if meta doesn't exist
</span><span class="cx">                 if ( !current_user_can( 'edit_post', $meta->post_id ) )
</span><span class="cx">                         die('-1');
</span><ins>+                if ( is_protected_meta( $meta->meta_key ) )
+                        die('-1');
</ins><span class="cx">                 if ( $meta->meta_value != stripslashes($value) || $meta->meta_key != stripslashes($key) ) {
</span><span class="cx">                         if ( !$u = update_meta( $mid, $key, $value ) )
</span><span class="cx">                                 die('0'); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
</span></span></pre></div>
<a id="trunkwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/media.php (17993 => 17994)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/media.php        2011-05-22 23:19:12 UTC (rev 17993)
+++ trunk/wp-admin/includes/media.php        2011-05-22 23:19:42 UTC (rev 17994)
</span><span class="lines">@@ -1201,7 +1201,7 @@
</span><span class="cx">         $toggle_on = __( 'Show' );
</span><span class="cx">         $toggle_off = __( 'Hide' );
</span><span class="cx">
</span><del>-        $filename = basename( $post->guid );
</del><ins>+        $filename = esc_html( basename( $post->guid ) );
</ins><span class="cx">         $title = esc_attr( $post->post_title );
</span><span class="cx">
</span><span class="cx">         if ( $_tags = get_the_tags( $attachment_id ) ) {
</span></span></pre></div>
<a id="trunkwpadminincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/post.php (17993 => 17994)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/post.php        2011-05-22 23:19:12 UTC (rev 17993)
+++ trunk/wp-admin/includes/post.php        2011-05-22 23:19:42 UTC (rev 17994)
</span><span class="lines">@@ -138,6 +138,7 @@
</span><span class="cx">         $post_ID = (int) $post_data['post_ID'];
</span><span class="cx">         $post = get_post( $post_ID );
</span><span class="cx">         $post_data['post_type'] = $post->post_type;
</span><ins>+        $post_data['post_mime_type'] = $post->post_mime_type;
</ins><span class="cx">
</span><span class="cx">         $ptype = get_post_type_object($post_data['post_type']);
</span><span class="cx">         if ( !current_user_can( $ptype->cap->edit_post, $post_ID ) ) {
</span><span class="lines">@@ -199,6 +200,8 @@
</span><span class="cx">                                 continue;
</span><span class="cx">                         if ( $meta->post_id != $post_ID )
</span><span class="cx">                                 continue;
</span><ins>+                        if ( is_protected_meta( $key ) )
+                                continue;
</ins><span class="cx">                         update_meta( $key, $value['key'], $value['value'] );
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="lines">@@ -209,6 +212,8 @@
</span><span class="cx">                                 continue;
</span><span class="cx">                         if ( $meta->post_id != $post_ID )
</span><span class="cx">                                 continue;
</span><ins>+                        if ( is_protected_meta( $key ) )
+                                continue;
</ins><span class="cx">                         delete_meta( $key );
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="lines">@@ -527,6 +532,8 @@
</span><span class="cx">                         return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this site.' ) );
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        $_POST['post_mime_type'] = '';
+
</ins><span class="cx">         // Check for autosave collisions
</span><span class="cx">         // Does this need to be updated? ~ Mark
</span><span class="cx">         $temp_id = false;
</span><span class="lines">@@ -632,8 +639,6 @@
</span><span class="cx">         global $wpdb;
</span><span class="cx">         $post_ID = (int) $post_ID;
</span><span class="cx">
</span><del>-        $protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' );
-
</del><span class="cx">         $metakeyselect = isset($_POST['metakeyselect']) ? stripslashes( trim( $_POST['metakeyselect'] ) ) : '';
</span><span class="cx">         $metakeyinput = isset($_POST['metakeyinput']) ? stripslashes( trim( $_POST['metakeyinput'] ) ) : '';
</span><span class="cx">         $metavalue = isset($_POST['metavalue']) ? maybe_serialize( stripslashes_deep( $_POST['metavalue'] ) ) : '';
</span><span class="lines">@@ -650,7 +655,7 @@
</span><span class="cx">                 if ( $metakeyinput)
</span><span class="cx">                         $metakey = $metakeyinput; // default
</span><span class="cx">
</span><del>-                if ( in_array($metakey, $protected) )
</del><ins>+                if ( is_protected_meta( $metakey ) )
</ins><span class="cx">                         return false;
</span><span class="cx">
</span><span class="cx">                 wp_cache_delete($post_ID, 'post_meta');
</span><span class="lines">@@ -756,11 +761,9 @@
</span><span class="cx"> function update_meta( $meta_id, $meta_key, $meta_value ) {
</span><span class="cx">         global $wpdb;
</span><span class="cx">
</span><del>-        $protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' );
-
</del><span class="cx">         $meta_key = stripslashes($meta_key);
</span><span class="cx">
</span><del>-        if ( in_array($meta_key, $protected) )
</del><ins>+        if ( is_protected_meta( $meta_key ) )
</ins><span class="cx">                 return false;
</span><span class="cx">
</span><span class="cx">         if ( '' === trim( $meta_value ) )
</span></span></pre></div>
<a id="trunkwpadminincludestemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/template.php (17993 => 17994)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/template.php        2011-05-22 23:19:12 UTC (rev 17993)
+++ trunk/wp-admin/includes/template.php        2011-05-22 23:19:42 UTC (rev 17994)
</span><span class="lines">@@ -465,6 +465,10 @@
</span><span class="cx"> */
</span><span class="cx"> function _list_meta_row( $entry, &$count ) {
</span><span class="cx">         static $update_nonce = false;
</span><ins>+
+        if ( is_protected_meta( $entry['meta_key'] ) )
+                return;
+
</ins><span class="cx">         if ( !$update_nonce )
</span><span class="cx">                 $update_nonce = wp_create_nonce( 'add-meta' );
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludesdefaultfiltersphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/default-filters.php (17993 => 17994)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/default-filters.php        2011-05-22 23:19:12 UTC (rev 17993)
+++ trunk/wp-includes/default-filters.php        2011-05-22 23:19:42 UTC (rev 17994)
</span><span class="lines">@@ -58,14 +58,14 @@
</span><span class="cx">
</span><span class="cx"> // Save URL
</span><span class="cx"> foreach ( array( 'pre_comment_author_url', 'pre_user_url', 'pre_link_url', 'pre_link_image',
</span><del>-        'pre_link_rss' ) as $filter ) {
</del><ins>+        'pre_link_rss', 'pre_post_guid' ) as $filter ) {
</ins><span class="cx">         add_filter( $filter, 'wp_strip_all_tags' );
</span><span class="cx">         add_filter( $filter, 'esc_url_raw' );
</span><span class="cx">         add_filter( $filter, 'wp_filter_kses' );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // Display URL
</span><del>-foreach ( array( 'user_url', 'link_url', 'link_image', 'link_rss', 'comment_url' ) as $filter ) {
</del><ins>+foreach ( array( 'user_url', 'link_url', 'link_image', 'link_rss', 'comment_url', 'post_guid' ) as $filter ) {
</ins><span class="cx">         if ( is_admin() )
</span><span class="cx">                 add_filter( $filter, 'wp_strip_all_tags' );
</span><span class="cx">         add_filter( $filter, 'esc_url' );
</span><span class="lines">@@ -86,6 +86,10 @@
</span><span class="cx">         add_filter( $filter, 'sanitize_key' );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+// Mime types
+add_filter( 'pre_post_mime_type', 'sanitize_mime_type' );
+add_filter( 'post_mime_type', 'sanitize_mime_type' );
+
</ins><span class="cx"> // Places to balance tags on input
</span><span class="cx"> foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
</span><span class="cx">         add_filter( $filter, 'balanceTags', 50 );
</span></span></pre></div>
<a id="trunkwpincludesformattingphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/formatting.php (17993 => 17994)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/formatting.php        2011-05-22 23:19:12 UTC (rev 17993)
+++ trunk/wp-includes/formatting.php        2011-05-22 23:19:42 UTC (rev 17994)
</span><span class="lines">@@ -2889,4 +2889,17 @@
</span><span class="cx">
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Sanitize a mime type
+ *
+ * @since 3.2.0
+ *
+ * @param string $mime_type Mime type
+ * @return string Sanitized mime type
+ */
+function sanitize_mime_type( $mime_type ) {
+        $sani_mime_type = preg_replace( '/[^-*.a-zA-Z0-9\/]/', '', $mime_type );
+        return apply_filters( 'sanitize_mime_type', $sani_mime_type, $mime_type );
+}
+
</ins><span class="cx"> ?>
</span></span></pre></div>
<a id="trunkwpincludesmetaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/meta.php (17993 => 17994)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/meta.php        2011-05-22 23:19:12 UTC (rev 17993)
+++ trunk/wp-includes/meta.php        2011-05-22 23:19:42 UTC (rev 17994)
</span><span class="lines">@@ -45,6 +45,7 @@
</span><span class="cx">         // expected_slashed ($meta_key)
</span><span class="cx">         $meta_key = stripslashes($meta_key);
</span><span class="cx">         $meta_value = stripslashes_deep($meta_value);
</span><ins>+        $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type );
</ins><span class="cx">
</span><span class="cx">         $check = apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique );
</span><span class="cx">         if ( null !== $check )
</span><span class="lines">@@ -113,6 +114,7 @@
</span><span class="cx">         // expected_slashed ($meta_key)
</span><span class="cx">         $meta_key = stripslashes($meta_key);
</span><span class="cx">         $meta_value = stripslashes_deep($meta_value);
</span><ins>+        $meta_value = sanitize_meta( $meta_key, $meta_value, $meta_type );
</ins><span class="cx">
</span><span class="cx">         $check = apply_filters( "update_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $prev_value );
</span><span class="cx">         if ( null !== $check )
</span><span class="lines">@@ -576,4 +578,33 @@
</span><span class="cx">
</span><span class="cx">         return $wpdb->$table_name;
</span><span class="cx"> }
</span><ins>+
+/**
+ * Determine whether a meta key is protected
+ *
+ * @since 3.2.0
+ *
+ * @param string $meta_key Meta key
+ * @return bool True if the key is protected, false otherwise.
+ */
+function is_protected_meta( $meta_key, $meta_type = null ) {
+        $protected = ( '_' == $meta_key[0] );
+
+        return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
+}
+
+/**
+ * Sanitize meta value
+ *
+ * @since 3.2.0
+ *
+ * @param string $meta_key Meta key
+ * @param mixed $meta_value Meta value to sanitize
+ * @param string $meta_type Type of meta
+ * @return mixed Sanitized $meta_value
+ */
+function sanitize_meta( $meta_key, $meta_value, $meta_type = null ) {
+        return apply_filters( 'sanitize_meta', $meta_value, $meta_key, $meta_type );
+}
+
</ins><span class="cx"> ?>
</span></span></pre></div>
<a id="trunkwpincludesthemephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/theme.php (17993 => 17994)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/theme.php        2011-05-22 23:19:12 UTC (rev 17993)
+++ trunk/wp-includes/theme.php        2011-05-22 23:19:42 UTC (rev 17994)
</span><span class="lines">@@ -1440,7 +1440,7 @@
</span><span class="cx">         else
</span><span class="cx">                 $url = str_replace( 'https://', 'http://', $url );
</span><span class="cx">
</span><del>-        return $url;
</del><ins>+        return esc_url_raw( $url );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -1525,7 +1525,7 @@
</span><span class="cx">                 return array();
</span><span class="cx">
</span><span class="cx">         foreach ( (array) $headers as $header ) {
</span><del>-                $url = $header->guid;
</del><ins>+                $url = esc_url_raw( $header->guid );
</ins><span class="cx">                 $header = basename($url);
</span><span class="cx">                 $header_images[$header] = array();
</span><span class="cx">                 $header_images[$header]['url'] = $url;
</span></span></pre>
</div>
</div>
</body>
</html>