Skip to content

Commit

Permalink
Ensure the referer functions operate completely on unslashed data: wp…
Browse files Browse the repository at this point in the history
…_referer_field(), wp_original_referer_field(), wp_get_referer(), wp_get_original_referer().

Use wp_slash() instead of addslashes().

see #21767.



git-svn-id: http://core.svn.wordpress.org/trunk@23578 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
nacin committed Mar 1, 2013
1 parent 76c0307 commit 7b47322
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion wp-admin/edit-comments.php
Expand Up @@ -21,7 +21,7 @@


if ( 'delete_all' == $doaction && !empty( $_REQUEST['pagegen_timestamp'] ) ) { if ( 'delete_all' == $doaction && !empty( $_REQUEST['pagegen_timestamp'] ) ) {
$comment_status = wp_unslash( $_REQUEST['comment_status'] ); $comment_status = wp_unslash( $_REQUEST['comment_status'] );
$delete_time = wp_unslash ( $_REQUEST['pagegen_timestamp'] ); $delete_time = wp_unslash( $_REQUEST['pagegen_timestamp'] );
$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s AND %s > comment_date_gmt", $comment_status, $delete_time ) ); $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s AND %s > comment_date_gmt", $comment_status, $delete_time ) );
$doaction = 'delete'; $doaction = 'delete';
} elseif ( isset( $_REQUEST['delete_comments'] ) ) { } elseif ( isset( $_REQUEST['delete_comments'] ) ) {
Expand Down
2 changes: 1 addition & 1 deletion wp-admin/edit-form-comment.php
Expand Up @@ -132,7 +132,7 @@


<input type="hidden" name="c" value="<?php echo esc_attr($comment->comment_ID) ?>" /> <input type="hidden" name="c" value="<?php echo esc_attr($comment->comment_ID) ?>" />
<input type="hidden" name="p" value="<?php echo esc_attr($comment->comment_post_ID) ?>" /> <input type="hidden" name="p" value="<?php echo esc_attr($comment->comment_post_ID) ?>" />
<input name="referredby" type="hidden" id="referredby" value="<?php echo esc_url(wp_unslash(wp_get_referer())); ?>" /> <input name="referredby" type="hidden" id="referredby" value="<?php echo esc_url( wp_get_referer() ); ?>" />
<?php wp_original_referer_field(true, 'previous'); ?> <?php wp_original_referer_field(true, 'previous'); ?>
<input type="hidden" name="noredir" value="1" /> <input type="hidden" name="noredir" value="1" />


Expand Down
8 changes: 4 additions & 4 deletions wp-admin/includes/media.php
Expand Up @@ -467,11 +467,11 @@ function media_upload_form_handler() {
$post = apply_filters('attachment_fields_to_save', $post, $attachment); $post = apply_filters('attachment_fields_to_save', $post, $attachment);


if ( isset($attachment['image_alt']) ) { if ( isset($attachment['image_alt']) ) {
$image_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); $image_alt = wp_unslash( $attachment['image_alt'] );
if ( $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( wp_unslash($attachment['image_alt']), true ); $image_alt = wp_strip_all_tags( $image_alt, true );
// update_meta expects slashed // update_meta expects slashed
update_post_meta( $attachment_id, '_wp_attachment_image_alt', addslashes($image_alt) ); update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
} }
} }


Expand Down
10 changes: 5 additions & 5 deletions wp-admin/includes/post.php
Expand Up @@ -197,7 +197,7 @@ function edit_post( $post_data = null ) {
} }


if ( isset( $post_data[ '_wp_format_url' ] ) ) { if ( isset( $post_data[ '_wp_format_url' ] ) ) {
update_post_meta( $post_ID, '_wp_format_url', addslashes( esc_url_raw( wp_unslash( $post_data['_wp_format_url'] ) ) ) ); update_post_meta( $post_ID, '_wp_format_url', wp_slash( esc_url_raw( wp_unslash( $post_data['_wp_format_url'] ) ) ) );
} }


$format_keys = array( 'quote', 'quote_source', 'image', 'gallery', 'media' ); $format_keys = array( 'quote', 'quote_source', 'image', 'gallery', 'media' );
Expand Down Expand Up @@ -235,11 +235,11 @@ function edit_post( $post_data = null ) {
// Attachment stuff // Attachment stuff
if ( 'attachment' == $post_data['post_type'] ) { if ( 'attachment' == $post_data['post_type'] ) {
if ( isset( $post_data[ '_wp_attachment_image_alt' ] ) ) { if ( isset( $post_data[ '_wp_attachment_image_alt' ] ) ) {
$image_alt = get_post_meta( $post_ID, '_wp_attachment_image_alt', true ); $image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] );
if ( $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( wp_unslash( $post_data['_wp_attachment_image_alt'] ), true ); $image_alt = wp_strip_all_tags( $image_alt, true );
// update_meta expects slashed // update_meta expects slashed
update_post_meta( $post_ID, '_wp_attachment_image_alt', addslashes( $image_alt ) ); update_post_meta( $post_ID, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
} }
} }


Expand Down
20 changes: 10 additions & 10 deletions wp-includes/functions.php
Expand Up @@ -1233,8 +1233,7 @@ function wp_nonce_field( $action = -1, $name = "_wpnonce", $referer = true , $ec
* @return string Referer field. * @return string Referer field.
*/ */
function wp_referer_field( $echo = true ) { function wp_referer_field( $echo = true ) {
$ref = esc_attr( $_SERVER['REQUEST_URI'] ); $referer_field = '<input type="hidden" name="_wp_http_referer" value="'. esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';
$referer_field = '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';


if ( $echo ) if ( $echo )
echo $referer_field; echo $referer_field;
Expand All @@ -1257,9 +1256,10 @@ function wp_referer_field( $echo = true ) {
* @return string Original referer field. * @return string Original referer field.
*/ */
function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) { function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
$jump_back_to = ( 'previous' == $jump_back_to ) ? wp_get_referer() : $_SERVER['REQUEST_URI']; if ( ! $ref = wp_get_original_referer() ) {
$ref = ( wp_get_original_referer() ) ? wp_get_original_referer() : $jump_back_to; $ref = 'previous' == $jump_back_to ? wp_get_referer() : wp_unslash( $_SERVER['REQUEST_URI'] );
$orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . esc_attr( stripslashes( $ref ) ) . '" />'; }
$orig_referer_field = '<input type="hidden" name="_wp_original_http_referer" value="' . esc_attr( $ref ) . '" />';
if ( $echo ) if ( $echo )
echo $orig_referer_field; echo $orig_referer_field;
return $orig_referer_field; return $orig_referer_field;
Expand All @@ -1278,11 +1278,11 @@ function wp_original_referer_field( $echo = true, $jump_back_to = 'current' ) {
function wp_get_referer() { function wp_get_referer() {
$ref = false; $ref = false;
if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) if ( ! empty( $_REQUEST['_wp_http_referer'] ) )
$ref = $_REQUEST['_wp_http_referer']; $ref = wp_unslash( $_REQUEST['_wp_http_referer'] );
else if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) else if ( ! empty( $_SERVER['HTTP_REFERER'] ) )
$ref = $_SERVER['HTTP_REFERER']; $ref = wp_unslash( $_SERVER['HTTP_REFERER'] );


if ( $ref && $ref !== $_SERVER['REQUEST_URI'] ) if ( $ref && $ref !== wp_unslash( $_SERVER['REQUEST_URI'] ) )
return wp_unslash( $ref ); return wp_unslash( $ref );
return false; return false;
} }
Expand All @@ -1298,7 +1298,7 @@ function wp_get_referer() {
*/ */
function wp_get_original_referer() { function wp_get_original_referer() {
if ( !empty( $_REQUEST['_wp_original_http_referer'] ) ) if ( !empty( $_REQUEST['_wp_original_http_referer'] ) )
return $_REQUEST['_wp_original_http_referer']; return wp_unslash( $_REQUEST['_wp_original_http_referer'] );
return false; return false;
} }


Expand Down Expand Up @@ -3906,7 +3906,7 @@ function wp_auth_check_load() {


/** /**
* Output the JS that shows the wp-login iframe when the user is no longer logged in * Output the JS that shows the wp-login iframe when the user is no longer logged in
*/ */
function wp_auth_check_js() { function wp_auth_check_js() {
?> ?>
<script type="text/javascript"> <script type="text/javascript">
Expand Down

0 comments on commit 7b47322

Please sign in to comment.