Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds additional escaping throughout plugin (VIP) #1495

Merged
merged 37 commits into from
Jun 22, 2018
Merged

Adds additional escaping throughout plugin (VIP) #1495

merged 37 commits into from
Jun 22, 2018

Conversation

tomjn
Copy link
Contributor

@tomjn tomjn commented May 16, 2018

There's a number of issues flagged during VIP review, I'm currently going through and fixing them by adding in the missing escaping. WIP PR, questions welcome

@@ -139,7 +139,7 @@ public function get_listings() {
'orderby' => $orderby,
'order' => sanitize_text_field( $_REQUEST['order'] ),
'offset' => ( absint( $_REQUEST['page'] ) - 1 ) * absint( $_REQUEST['per_page'] ),
'posts_per_page' => absint( $_REQUEST['per_page'] ),
'posts_per_page' => max( 1, absint( $_REQUEST['per_page'] ) ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a behavior change, I might cherry-pick this commit to a separate PR, if that works for you? There could be some themes doing things they shouldn't with -1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

Copy link
Member

@jom jom May 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started doing this and then realized absint() prevented -1 😉 . This commit could probably be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh but it does prevent passing 0, I wanted to add a min too so there was an upper limit but i figured that would be problematic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In testing, 0 resulted in the default per_page, but oh well.

jom
jom previously requested changes May 23, 2018
Copy link
Member

@jom jom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR, @tomjn! Huge improvement. I've added some (mostly linting) notes.

Did some general testing and seems to work well. I've marked it for 1.31.1. I can update the template versions before merging.

@@ -48,18 +48,23 @@ public function __construct() {
public function add_bulk_actions_legacy() {
global $post_type, $wp_post_types;

$bulk_actions = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WPJM still has PHP 5.2 compat, unfortunately. Please expand short array syntax to old school array().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -48,18 +48,23 @@ public function __construct() {
public function add_bulk_actions_legacy() {
global $post_type, $wp_post_types;

$bulk_actions = [];
foreach( $this->get_bulk_actions() as $key => $bulk_action ) {
$bulk_actions[] = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

foreach( $this->get_bulk_actions() as $key => $bulk_action ) {
$bulk_actions[] = [
'key' => $key,
'label' => sprintf( $bulk_action[ 'label' ], $wp_post_types[ 'job_listing' ]->labels->name )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint: spacing around single apostrophes in array key.

@@ -372,16 +371,15 @@ public function jobs_meta_filters() {
private function jobs_filter_dropdown( $param, $options ) {
$selected = isset( $_GET[ $param ] ) ? $_GET[ $param ] : '';

$output = "<select name=\"$param\" id=\"dropdown_$param\">";
echo '<select name="'.esc_attr( $param ).'" id="dropdown_'.esc_attr( $param ).'">';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint: spacing around . in string concatenation.

@@ -753,17 +755,17 @@ public function extend_submitdiv_post_status() {
$selected AND $display = $name;

// Build the options
$options .= "<option{$selected} value='{$status}'>{$name}</option>";
$options .= "<option{$selected} value='{$status}'>".esc_html( $name )."</option>";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint: spacing around . in string concatenation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -40,7 +40,7 @@

<?php foreach ( $job_fields as $key => $field ) : ?>
<fieldset class="fieldset-<?php echo esc_attr( $key ); ?>">
<label for="<?php echo esc_attr( $key ); ?>"><?php echo $field['label'] . apply_filters( 'submit_job_form_required_label', $field['required'] ? '' : ' <small>' . __( '(optional)', 'wp-job-manager' ) . '</small>', $field ); ?></label>
<label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label']) . wp_kses_post( apply_filters( 'submit_job_form_required_label', $field['required'] ? '' : ' <small>' . __( '(optional)', 'wp-job-manager' ) . '</small>', $field ) ); ?></label>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint: Spacing around argument list (esc_html( $field['label'])).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -144,7 +144,7 @@ public function convert_to_exception( $errno, $errstr, $errfile, $errline ) {

// PHP 5.2 doesn't show the error from Exceptions.
if ( version_compare( phpversion(), '5.3.0', '<' ) ) {
echo "Error ($errno) - $description\n";
echo "Error (".esc_html( $errno ) ."( - ".esc_html( $description )."\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint: spacing around string concatenation (.).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -1388,10 +1387,9 @@ function job_manager_duplicate_listing( $post_id ) {
/*
* Duplicate post meta, aside from some reserved fields.
*/
$post_meta = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM {$wpdb->postmeta} WHERE post_id=%d", $post_id ) );
$post_meta = get_post_meta( $post_id );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced by #1503; please remove from this PR.

(Also line change below)

@@ -1066,11 +1072,10 @@ function the_company_twitter( $before = '', $after = '', $echo = true, $post = n
if ( strlen( $company_twitter ) == 0 )
return;

$company_twitter = esc_attr( strip_tags( $company_twitter ) );
$company_twitter = $before . '<a href="http://twitter.com/' . $company_twitter . '" class="company_twitter" target="_blank">' . $company_twitter . '</a>' . $after;
$company_twitter = $before . '<a href="'.esc_url( 'https://twitter.com/' . $company_twitter ) . '" class="company_twitter" target="_blank">' . esc_html( wp_strip_all_tags( $company_twitter ) ) . '</a>' . $after;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint: spacing around string concatenation (.).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

<?php endif; ?>

<?php elseif ( $account_required ) : ?>

<?php echo apply_filters( 'submit_job_form_login_required_message', __('You must sign in to create a new listing.', 'wp-job-manager' ) ); ?>
<?php echo wp_kses_post( apply_filters( 'submit_job_form_login_required_message', __('You must sign in to create a new listing.', 'wp-job-manager' ) ) ); ?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an original lint issue, but while editing line, there is a spacing issue in the argument list for __().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@jom
Copy link
Member

jom commented May 23, 2018

cc: @tripflex I don't think the escaping happening in the fields/*.php templates will affect your plugin, but just wanted to flag you.

@jom jom added this to the 1.31.1 milestone May 23, 2018
@tomjn tomjn dismissed jom’s stale review June 6, 2018 16:30

issues resolved, needs re-reviewing

@jom jom force-pushed the vip_escaping branch 2 times, most recently from 1198a46 to d72e567 Compare June 19, 2018 14:58
@@ -122,7 +123,8 @@ jQuery( document ).ready( function ( $ ) {
if ( result ) {
try {
if ( result.showing ) {
$( showing ).show().html( '<span>' + result.showing + '</span>' + result.showing_links );
var showing_el = jQuery('<span>').text(result.showing)
$( showing ).show().html( '').text(result.showing_links).prepend(showing_el);
Copy link
Member

@jom jom Jun 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result.showing_links contains HTML and gets encoded using $.text().

screen shot 2018-06-19 at 4 55 28 pm

@jom
Copy link
Member

jom commented Jun 19, 2018

I've force pushed a modified version of that commit with #1503's content removed. I want to test that change with WPML before merging and don't want it to hold up this commit. For further changes, you'll need to do a hard reset to the remote branch.... sorry, since I'm planning on squashing this PR anyway I could have just done a partial revert commit.

Can we revert the change to line 125 in ajax-filters.js? I don't mind doing it if you're fine with that. Once we do that, I'll update the template versions for 1.31.1.

There were a few more lint errors not resolved yet but I did them in 09fc708.

@tomjn
Copy link
Contributor Author

tomjn commented Jun 20, 2018

@jom my bandwidth at the moment is quite tight, and we've a client waiting on these changes for quite a while now, anything you can do to expedite things would be super helpful

@jom
Copy link
Member

jom commented Jun 20, 2018

@tomjn I'll revert the change mentioned in ajax-filters.js so the raw HTML doesn't show up (unless you have another preferred method) and then we should be good for this PR.

@jom jom changed the title Vip escaping Adds additional escaping throughout plugin (VIP) Jun 22, 2018
@jom jom merged commit 55197d5 into master Jun 22, 2018
@jom jom deleted the vip_escaping branch June 22, 2018 08:34
@jom jom mentioned this pull request Jul 4, 2018
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants