<!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>[23578] trunk: Ensure the referer functions operate completely on unslashed data: wp_referer_field(), wp_original_referer_field(), wp_get_referer(), wp_get_original_referer().</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://core.trac.wordpress.org/changeset/23578">23578</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2013-03-01 17:58:43 +0000 (Fri, 01 Mar 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Ensure the referer functions operate completely on unslashed data: wp_referer_field(), wp_original_referer_field(), wp_get_referer(), wp_get_original_referer().

Use wp_slash() instead of addslashes().

see <a href="http://core.trac.wordpress.org/ticket/21767">#21767</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmineditcommentsphp">trunk/wp-admin/edit-comments.php</a></li>
<li><a href="#trunkwpadmineditformcommentphp">trunk/wp-admin/edit-form-comment.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="#trunkwpincludesfunctionsphp">trunk/wp-includes/functions.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmineditcommentsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit-comments.php (23577 => 23578)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit-comments.php        2013-03-01 17:57:49 UTC (rev 23577)
+++ trunk/wp-admin/edit-comments.php        2013-03-01 17:58:43 UTC (rev 23578)
</span><span class="lines">@@ -21,7 +21,7 @@
</span><span class="cx"> 
</span><span class="cx">         if ( 'delete_all' == $doaction &amp;&amp; !empty( $_REQUEST['pagegen_timestamp'] ) ) {
</span><span class="cx">                 $comment_status = wp_unslash( $_REQUEST['comment_status'] );
</span><del>-                $delete_time = wp_unslash ( $_REQUEST['pagegen_timestamp'] );
</del><ins>+                $delete_time = wp_unslash( $_REQUEST['pagegen_timestamp'] );
</ins><span class="cx">                 $comment_ids = $wpdb-&gt;get_col( $wpdb-&gt;prepare( &quot;SELECT comment_ID FROM $wpdb-&gt;comments WHERE comment_approved = %s AND %s &gt; comment_date_gmt&quot;, $comment_status, $delete_time ) );
</span><span class="cx">                 $doaction = 'delete';
</span><span class="cx">         } elseif ( isset( $_REQUEST['delete_comments'] ) ) {
</span></span></pre></div>
<a id="trunkwpadmineditformcommentphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit-form-comment.php (23577 => 23578)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit-form-comment.php        2013-03-01 17:57:49 UTC (rev 23577)
+++ trunk/wp-admin/edit-form-comment.php        2013-03-01 17:58:43 UTC (rev 23578)
</span><span class="lines">@@ -132,7 +132,7 @@
</span><span class="cx"> 
</span><span class="cx"> &lt;input type=&quot;hidden&quot; name=&quot;c&quot; value=&quot;&lt;?php echo esc_attr($comment-&gt;comment_ID) ?&gt;&quot; /&gt;
</span><span class="cx"> &lt;input type=&quot;hidden&quot; name=&quot;p&quot; value=&quot;&lt;?php echo esc_attr($comment-&gt;comment_post_ID) ?&gt;&quot; /&gt;
</span><del>-&lt;input name=&quot;referredby&quot; type=&quot;hidden&quot; id=&quot;referredby&quot; value=&quot;&lt;?php echo esc_url(wp_unslash(wp_get_referer())); ?&gt;&quot; /&gt;
</del><ins>+&lt;input name=&quot;referredby&quot; type=&quot;hidden&quot; id=&quot;referredby&quot; value=&quot;&lt;?php echo esc_url( wp_get_referer() ); ?&gt;&quot; /&gt;
</ins><span class="cx"> &lt;?php wp_original_referer_field(true, 'previous'); ?&gt;
</span><span class="cx"> &lt;input type=&quot;hidden&quot; name=&quot;noredir&quot; value=&quot;1&quot; /&gt;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/media.php (23577 => 23578)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/media.php        2013-03-01 17:57:49 UTC (rev 23577)
+++ trunk/wp-admin/includes/media.php        2013-03-01 17:58:43 UTC (rev 23578)
</span><span class="lines">@@ -467,11 +467,11 @@
</span><span class="cx">                 $post = apply_filters('attachment_fields_to_save', $post, $attachment);
</span><span class="cx"> 
</span><span class="cx">                 if ( isset($attachment['image_alt']) ) {
</span><del>-                        $image_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
-                        if ( $image_alt != wp_unslash($attachment['image_alt']) ) {
-                                $image_alt = wp_strip_all_tags( wp_unslash($attachment['image_alt']), true );
</del><ins>+                        $image_alt = wp_unslash( $attachment['image_alt'] );
+                        if ( $image_alt != get_post_meta($attachment_id, '_wp_attachment_image_alt', true) ) {
+                                $image_alt = wp_strip_all_tags( $image_alt, true );
</ins><span class="cx">                                 // update_meta expects slashed
</span><del>-                                update_post_meta( $attachment_id, '_wp_attachment_image_alt', addslashes($image_alt) );
</del><ins>+                                update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/post.php (23577 => 23578)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/post.php        2013-03-01 17:57:49 UTC (rev 23577)
+++ trunk/wp-admin/includes/post.php        2013-03-01 17:58:43 UTC (rev 23578)
</span><span class="lines">@@ -197,7 +197,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if ( isset( $post_data[ '_wp_format_url' ] ) ) {
</span><del>-                update_post_meta( $post_ID, '_wp_format_url', addslashes( esc_url_raw( wp_unslash( $post_data['_wp_format_url'] ) ) ) );
</del><ins>+                update_post_meta( $post_ID, '_wp_format_url', wp_slash( esc_url_raw( wp_unslash( $post_data['_wp_format_url'] ) ) ) );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         $format_keys = array( 'quote', 'quote_source', 'image', 'gallery', 'media' );
</span><span class="lines">@@ -235,11 +235,11 @@
</span><span class="cx">         // Attachment stuff
</span><span class="cx">         if ( 'attachment' == $post_data['post_type'] ) {
</span><span class="cx">                 if ( isset( $post_data[ '_wp_attachment_image_alt' ] ) ) {
</span><del>-                        $image_alt = get_post_meta( $post_ID, '_wp_attachment_image_alt', true );
-                        if ( $image_alt != wp_unslash( $post_data['_wp_attachment_image_alt'] ) ) {
-                                $image_alt = wp_strip_all_tags( wp_unslash( $post_data['_wp_attachment_image_alt'] ), true );
</del><ins>+                        $image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] );
+                        if ( $image_alt != get_post_meta( $post_ID, '_wp_attachment_image_alt', true ) ) {
+                                $image_alt = wp_strip_all_tags( $image_alt, true );
</ins><span class="cx">                                 // update_meta expects slashed
</span><del>-                                update_post_meta( $post_ID, '_wp_attachment_image_alt', addslashes( $image_alt ) );
</del><ins>+                                update_post_meta( $post_ID, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/functions.php (23577 => 23578)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/functions.php        2013-03-01 17:57:49 UTC (rev 23577)
+++ trunk/wp-includes/functions.php        2013-03-01 17:58:43 UTC (rev 23578)
</span><span class="lines">@@ -1233,8 +1233,7 @@
</span><span class="cx">  * @return string Referer field.
</span><span class="cx">  */
</span><span class="cx"> function wp_referer_field( $echo = true ) {
</span><del>-        $ref = esc_attr( $_SERVER['REQUEST_URI'] );
-        $referer_field = '&lt;input type=&quot;hidden&quot; name=&quot;_wp_http_referer&quot; value=&quot;'. $ref . '&quot; /&gt;';
</del><ins>+        $referer_field = '&lt;input type=&quot;hidden&quot; name=&quot;_wp_http_referer&quot; value=&quot;'. esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '&quot; /&gt;';
</ins><span class="cx"> 
</span><span class="cx">         if ( $echo )
</span><span class="cx">                 echo $referer_field;
</span><span class="lines">@@ -1257,9 +1256,10 @@
</span><span class="cx">  * @return string Original referer field.
</span><span class="cx">  */
</span><span class="cx"> function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
</span><del>-        $jump_back_to = ( 'previous' == $jump_back_to ) ? wp_get_referer() : $_SERVER['REQUEST_URI'];
-        $ref = ( wp_get_original_referer() ) ? wp_get_original_referer() : $jump_back_to;
-        $orig_referer_field = '&lt;input type=&quot;hidden&quot; name=&quot;_wp_original_http_referer&quot; value=&quot;' . esc_attr( stripslashes( $ref ) ) . '&quot; /&gt;';
</del><ins>+        if ( ! $ref = wp_get_original_referer() ) {
+                $ref = 'previous' == $jump_back_to ? wp_get_referer() : wp_unslash( $_SERVER['REQUEST_URI'] );
+        }
+        $orig_referer_field = '&lt;input type=&quot;hidden&quot; name=&quot;_wp_original_http_referer&quot; value=&quot;' . esc_attr( $ref ) . '&quot; /&gt;';
</ins><span class="cx">         if ( $echo )
</span><span class="cx">                 echo $orig_referer_field;
</span><span class="cx">         return $orig_referer_field;
</span><span class="lines">@@ -1278,11 +1278,11 @@
</span><span class="cx"> function wp_get_referer() {
</span><span class="cx">         $ref = false;
</span><span class="cx">         if ( ! empty( $_REQUEST['_wp_http_referer'] ) )
</span><del>-                $ref = $_REQUEST['_wp_http_referer'];
</del><ins>+                $ref = wp_unslash( $_REQUEST['_wp_http_referer'] );
</ins><span class="cx">         else if ( ! empty( $_SERVER['HTTP_REFERER'] ) )
</span><del>-                $ref = $_SERVER['HTTP_REFERER'];
</del><ins>+                $ref = wp_unslash( $_SERVER['HTTP_REFERER'] );
</ins><span class="cx"> 
</span><del>-        if ( $ref &amp;&amp; $ref !== $_SERVER['REQUEST_URI'] )
</del><ins>+        if ( $ref &amp;&amp; $ref !== wp_unslash( $_SERVER['REQUEST_URI'] ) )
</ins><span class="cx">                 return wp_unslash( $ref );
</span><span class="cx">         return false;
</span><span class="cx"> }
</span><span class="lines">@@ -1298,7 +1298,7 @@
</span><span class="cx">  */
</span><span class="cx"> function wp_get_original_referer() {
</span><span class="cx">         if ( !empty( $_REQUEST['_wp_original_http_referer'] ) )
</span><del>-                return $_REQUEST['_wp_original_http_referer'];
</del><ins>+                return wp_unslash( $_REQUEST['_wp_original_http_referer'] );
</ins><span class="cx">         return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -3906,7 +3906,7 @@
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="cx">  * Output the JS that shows the wp-login iframe when the user is no longer logged in
</span><del>- */ 
</del><ins>+ */
</ins><span class="cx"> function wp_auth_check_js() {
</span><span class="cx">         ?&gt;
</span><span class="cx">         &lt;script type=&quot;text/javascript&quot;&gt;
</span></span></pre>
</div>
</div>

</body>
</html>