Skip to content

Commit

Permalink
Merge pull request #55 from Strategy11/fix/quick-start
Browse files Browse the repository at this point in the history
Apply access control and nonce verification
  • Loading branch information
stephywells authored Mar 20, 2024
2 parents 98d9e33 + 729745a commit ec9c41a
Show file tree
Hide file tree
Showing 75 changed files with 5,526 additions and 5,326 deletions.
28 changes: 15 additions & 13 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ module.exports = function( grunt ) {
this.registered[ id ] = config;

config.pluginPath = config.folder + '/';
if ( id === 'awpcp' ) {
config.pluginPath = '';
}

grunt.config.set( 'path.' + id, config.pluginPath );
grunt.wpbdp.registerSetVersionTasks( config );
Expand All @@ -33,7 +30,6 @@ module.exports = function( grunt ) {
}

if ( config.concat ) {
console.log('register js');
grunt.wpbdp.registerJavaScriptTasks( config );
}

Expand Down Expand Up @@ -210,39 +206,45 @@ module.exports = function( grunt ) {
},

registerLessTask: function( config ) {
var path = '<%= path.' + config.name + ' %>';
var folder = '<%= path.' + config.name + ' %>';

grunt.config.set( 'less.' + config.slug, config.less );
grunt.config.set( 'watch.' + config.name + '-css', {
files: [ path + '/less/**/*.less' ],
files: [ folder + '/less/**/*.less' ],
tasks: [ 'less:' + config.slug ]
} );
},

registerJavaScriptTasks: function( config ) {
var path = '<%= path.' + config.name + ' %>', targetFiles;
const basedir = config.pluginPath

grunt.config.set( 'concat.' + config.slug, config.concat );

grunt.config.set( 'watch.' + config.name + '-js', {
files: [path + '/js/**/*.js', '!' + path + '/js/**/*.src.js', '!' + path + '/js/**/*.min.js'],
files: [
path.join(basedir, '**/*.js'),
'!' + path.join(basedir, 'vendors/**/*'),
'!' + path.join(basedir, '**/*.src.js'),
'!' + path.join(basedir, '**/*.min.js'),
'!' + path.join(basedir, 'assets/vendor/**/*')
],
tasks: ['concat:' + config.slug, 'uglify:' + config.slug]
} );

targetFiles = grunt.task.normalizeMultiTaskFiles( config.concat );
let targetFiles = grunt.task.normalizeMultiTaskFiles( config.concat );

grunt.wpbdp.registerJSHintTask( config, targetFiles );
grunt.wpbdp.registerUglifyTask( config, targetFiles );
},

registerJSHintTask: function( config, targetFiles ) {
var path = '<%= path.' + config.name + ' %>', filesToCheck;
const folder = '<%= path.' + config.name + ' %>';

filesToCheck = _.flatten( _.map( targetFiles, function( value ) {
let filesToCheck = _.flatten( _.map( targetFiles, function( value ) {
return value.orig.src;
} ) );

grunt.config.set( 'jshint.' + config.slug, filesToCheck.concat( ['!' + path + '/js/**/*.min.js'] ) );
grunt.config.set( 'jshint.' + config.slug, filesToCheck.concat( ['!' + folder + '/js/**/*.min.js'] ) );
},

registerUglifyTask: function( config, targetFiles ) {
Expand Down Expand Up @@ -344,7 +346,7 @@ module.exports = function( grunt ) {
grunt.loadTasks( '../awpcp-zip-code-search/grunt' );
*/

grunt.registerTask('default', ['concat', 'jshint', 'uglify', 'less']);
grunt.registerTask('default', ['watch', 'concat', 'jshint', 'uglify', 'less']);

grunt.registerTask('i18n', '', function(t) {
grunt.task.run('makepot:' + t);
Expand Down
8 changes: 7 additions & 1 deletion README.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: listings, classified ads, classified, classifieds, directory plugin, class
Requires at least: 4.9
Requires PHP: 5.6
Tested up to: 6.2.2
Stable tag: 4.3.1
Stable tag: 4.3.2
License: GPLv2 or later

Create a classified listings directory, from auto listings to yard sales with AWP Classifieds plugin.
Expand Down Expand Up @@ -166,6 +166,12 @@ Yes it can. Our Classifieds directory plugin comes with many user-provided trans
Yes it is. However, you cannot "network-activate" the plugin (as this will share the database). Activate it on only the subsites on which you need a directory. This can be done under Plugins->Add New as the Administrator user. Do not "network activate" AWPCP as the "super admin".

== Changelog ==
= 4.3.2 =
* New: Updates for better PHP 8 support.
* Security: Add more nonce and user role protection for uninstalling and other ajax functions.
* Update SelectWoo script version.
* Fix: Fallback to native dropdowns if there is a conflict with Select2.

= 4.3.1 =
* Security update against CSRF attacks in some admin pages. add CSRF tokens "nonce".
* Fix: Pagination show the correct number of ads per page based on "number ads per page plugin" settings instead of 10 ads per page.
Expand Down
10 changes: 6 additions & 4 deletions admin/admin-panel-users.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ private function get_table() {
}

public function scripts() {
wp_enqueue_script('awpcp-admin-users');
$options = array(
'nonce' => wp_create_nonce( 'awpcp_ajax' ),
);
wp_localize_script( 'awpcp-admin-users', 'AWPCPAjaxOptions', $options );
wp_enqueue_script( 'awpcp-admin-users' );
}

public function get_columns($columns) {
Expand Down Expand Up @@ -97,9 +101,7 @@ public function ajax_edit_balance($user_id, $action) {
}

public function ajax() {
if (!awpcp_current_user_is_admin()) {
return false;
}
awpcp_check_admin_ajax();

$user_id = awpcp_get_var( array( 'param' => 'user', 'default' => 0 ), 'post' );
$action = awpcp_get_var( array( 'param' => 'action' ), 'post' );
Expand Down
6 changes: 5 additions & 1 deletion admin/admin-panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public function notices() {
return;
}

if ( awpcp_get_var( array( 'param' => 'page' ) ) == 'awpcp-admin-upgrade' ) {
if ( awpcp_get_var( array( 'param' => 'page' ) ) === 'awpcp-admin-upgrade' ) {
return;
}

Expand Down Expand Up @@ -643,12 +643,16 @@ public function upgrade() {
}

public function disable_quick_start_guide_notice() {
awpcp_check_admin_ajax();

global $awpcp;
$awpcp->settings->update_option('show-quick-start-guide-notice', false);
die('Success!');
}

public function disable_widget_modification_notice() {
awpcp_check_admin_ajax();

global $awpcp;
$awpcp->settings->update_option('show-widget-modification-notice', false);
die('Success!');
Expand Down
5 changes: 5 additions & 0 deletions admin/class-debug-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class AWPCP_DebugAdminPage {
*/
private $settings_manager;

/**
* @var TemplateRenderer
*/
protected $template_renderer;

/**
* @var wpdb
*/
Expand Down
2 changes: 2 additions & 0 deletions admin/class-dismiss-notice-ajax-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function __construct( $request, $ajax_response ) {
}

public function ajax() {
awpcp_check_admin_ajax();

delete_option( 'awpcp-show-' . $this->request->post( 'notice' ) );
return $this->success();
}
Expand Down
4 changes: 2 additions & 2 deletions admin/class-export-listings-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function dispatch() {
}

public function ajax() {
$verify_nonce = check_ajax_referer( 'awpcp-export-csv' );
if ( ! current_user_can( 'administrator' ) || ! $verify_nonce ) {
check_ajax_referer( 'awpcp-export-csv' );
if ( ! current_user_can( 'administrator' ) ) {
wp_send_json_error();
}

Expand Down
1 change: 1 addition & 0 deletions admin/class-table-entry-action-ajax-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public function __construct( $action_handler, $response ) {
}

public function ajax() {
check_ajax_referer( 'awpcp_ajax', 'nonce' );
if ( ! awpcp_current_user_is_admin() ) {
return $this->error_response( __( 'You are not authorized to perform this action.', 'another-wordpress-classifieds-plugin' ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public function __construct( $form_fields, $request, $response ) {
* Handles ajax request.
*/
public function ajax() {
awpcp_check_admin_ajax();

$fields = $this->form_fields->get_listing_details_form_fields();
$fields_order = array();

Expand Down
3 changes: 3 additions & 0 deletions admin/import/class-csv-import-sessions-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class AWPCP_CSV_Import_Sessions_Manager {
private $csv_importer_factory;
private $csv_importer_delegate_factory;
private $csv_reader_factory;

public $settings;

private $wordpress;

public function __construct( $csv_importer_factory, $csv_importer_delegate_factory, $csv_reader_factory, $settings, $wordpress ) {
Expand Down
5 changes: 5 additions & 0 deletions admin/import/class-csv-importer-delegate-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
*/
class AWPCP_CSV_Importer_Delegate_Factory {

/**
* @var object
*/
public $container;

/**
* Constructor.
*/
Expand Down
4 changes: 4 additions & 0 deletions admin/import/class-import-listings-ajax-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class AWPCP_Import_Listings_Ajax_Handler extends AWPCP_AjaxHandler {

private $import_sessions_manager;

protected $csv_importer_factory;

public function __construct( $import_sessions_manager, $csv_importer_factory, $response ) {
parent::__construct( $response );

Expand All @@ -20,6 +22,8 @@ public function __construct( $import_sessions_manager, $csv_importer_factory, $r
}

public function ajax() {
awpcp_check_admin_ajax();

$import_session = $this->import_sessions_manager->get_current_import_session();

$csv_importer = $this->csv_importer_factory->create_importer( $import_session );
Expand Down
4 changes: 2 additions & 2 deletions awpcp.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Plugin Name: AWP Classifieds Plugin
* Plugin URI: https://awpcp.com/
* Description: Run a free or paid classified ads service on your WordPress site.
* Version: 4.3.1
* Version: 4.3.2
* Author: AWP Classifieds Team
* Author URI: https://awpcp.com/
* License: GPLv2 or any later version
Expand Down Expand Up @@ -56,7 +56,7 @@
global $hasregionsmodule;
global $hasextrafieldsmodule;

$awpcp_db_version = '4.3.1';
$awpcp_db_version = '4.3.2';

$awpcp_imagesurl = AWPCP_URL . '/resources/images';
$hascaticonsmodule = 0;
Expand Down
1 change: 1 addition & 0 deletions frontend/class-awpcp-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AWPCP_Meta {
private $request = null;

private $doing_opengraph = false;
public $doin_description_meta_tag = false;

public function __construct( $listings_collection, $categories_collection, $title_builder, $meta_tags_genertor, $query, $request ) {
$this->listings_collection = $listings_collection;
Expand Down
6 changes: 5 additions & 1 deletion frontend/placeholders.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ function awpcp_replace_placeholders( $placeholders, $listing, $content, $context
$callback = $available_placeholders[ $placeholder ]['callback'];

if ( is_callable( $callback ) ) {
$replacement = call_user_func( $callback, $listing, $placeholder, $context );
$replacement = call_user_func( $callback, $listing, $placeholder, $context );
if ( is_null( $replacement ) ) {
$replacement = '';
}

$content = str_replace( $match, $replacement, $content );
$processed_placeholders[ $match ] = true;
}
Expand Down
12 changes: 9 additions & 3 deletions frontend/shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class AWPCP_Pages {

public $browse_ads;

public $place_ad_page = null;

public $edit_ad_page = null;

public $renew_ad_page = null;

public function __construct( $container ) {
$this->container = $container;

Expand Down Expand Up @@ -83,7 +89,7 @@ public function place_ad() {
if ( ! isset( $this->output['place-ad'] ) ) {
do_action( 'awpcp-shortcode', 'place-ad' );

if ( ! isset( $this->place_ad_page ) ) {
if ( is_null( $this->place_ad_page ) ) {
$this->place_ad_page = $this->container['SubmitListingPage'];
}

Expand All @@ -97,7 +103,7 @@ public function edit_ad() {
if ( ! isset( $this->output['edit-ad'] ) ) {
do_action( 'awpcp-shortcode', 'edit-ad' );

if ( ! isset( $this->edit_ad_page ) ) {
if ( is_null( $this->edit_ad_page ) ) {
$this->edit_ad_page = $this->container['EditListingPage'];
}

Expand All @@ -108,7 +114,7 @@ public function edit_ad() {
}

public function renew_ad() {
if ( ! isset( $this->renew_ad_page ) ) {
if ( is_null( $this->renew_ad_page ) ) {
$this->renew_ad_page = awpcp_renew_listing_page();
}

Expand Down
12 changes: 12 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,18 @@ function awpcp_user_is_admin($id) {
return awpcp_roles_and_capabilities()->user_is_administrator( $id );
}

/**
* Check the nonce and user role.
*
* @since 4.3.2
*/
function awpcp_check_admin_ajax() {
check_ajax_referer( 'awpcp_ajax', 'nonce' );
if ( ! awpcp_current_user_is_admin() ) {
wp_die( esc_html__( 'You are not authorized to perform this action.', 'another-wordpress-classifieds-plugin' ) );
}
}

function awpcp_get_grid_item_css_class($classes, $pos, $columns, $rows) {
if ($pos < $columns)
$classes[] = 'first-row';
Expand Down
4 changes: 1 addition & 3 deletions grunt/grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function(grunt) {
grunt.wpbdp.registerModule( {
name: 'awpcp',
slug: 'awpcp',
folder: pluginName,
folder: '../' + pluginName,
path: pluginName + '/resources',
concat: {
files: {
Expand Down Expand Up @@ -80,8 +80,6 @@ module.exports = function(grunt) {
less: {
files: {
'<%= path.awpcp %>resources/css/awpcpstyle.css': '<%= path.awpcp %>resources/less/frontend.less',
'<%= path.awpcp %>resources/css/awpcpstyle-ie-6.css': '<%= path.awpcp %>resources/less/frontend-ie6.less',
'<%= path.awpcp %>resources/css/awpcpstyle-lte-ie-7.css': '<%= path.awpcp %>resources/less/frontend-lte-ie-7.less',
'<%= path.awpcp %>resources/css/awpcp-admin.css': '<%= path.awpcp %>resources/less/admin.less',
'<%= path.awpcp %>resources/css/awpcp-admin-menu.css': '<%= path.awpcp %>resources/less/admin-menu.less',
}
Expand Down
4 changes: 1 addition & 3 deletions includes/admin/debug/class-test-ssl-client-ajax-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class AWPCP_TestSSLClientAjaxHandler {
* @since 4.0.0
*/
public function ajax() {
if ( ! awpcp_current_user_is_admin() ) {
die();
}
awpcp_check_admin_ajax();

if ( ! function_exists( 'curl_init' ) ) {
die( 'cURL not available.' );
Expand Down
5 changes: 5 additions & 0 deletions includes/admin/tools/class-tools-admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class AWPCP_ToolsAdminPage {
*/
private $template = '/admin/tools/tools-admin-page.tpl.php';

/**
* @var object
*/
protected $template_renderer;

/**
* @var array
*/
Expand Down
Loading

0 comments on commit ec9c41a

Please sign in to comment.