Skip to content

Commit

Permalink
Merge pull request #545 from Freemius/feature/2.5.0-rc.2-linear-secur…
Browse files Browse the repository at this point in the history
…ity-fix

Reapply security patches on develop branch for 2.5.0-rc.2 tag
  • Loading branch information
swashata authored Mar 3, 2022
2 parents 0592b3b + e4d29e7 commit 60bf619
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 26 deletions.
27 changes: 25 additions & 2 deletions includes/class-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -3781,6 +3781,8 @@ static function _add_debug_section() {
* @since 1.1.7.3
*/
static function _toggle_debug_mode() {
check_admin_referer( 'fs_toggle_debug_mode' );

if ( ! is_super_admin() ) {
return;
}
Expand All @@ -3802,10 +3804,19 @@ static function _toggle_debug_mode() {
* @since 1.2.1.6
*/
static function _get_debug_log() {
check_admin_referer( 'fs_get_debug_log' );

if ( ! is_super_admin() ) {
return;
}

$limit = min( ! empty( $_POST['limit'] ) ? absint( $_POST['limit'] ) : 200, 200 );
$offset = min( ! empty( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 200, 200 );

$logs = FS_Logger::load_db_logs(
fs_request_get( 'filters', false, 'post' ),
! empty( $_POST['limit'] ) && is_numeric( $_POST['limit'] ) ? intval( $_POST['limit'] ) : 200,
! empty( $_POST['offset'] ) && is_numeric( $_POST['offset'] ) ? intval( $_POST['offset'] ) : 0
$limit,
$offset
);

self::shoot_ajax_success( $logs );
Expand Down Expand Up @@ -4717,6 +4728,12 @@ function _add_connectivity_issue_message( $api_result, $is_first_failure = true
* @since 1.0.9
*/
function _email_about_firewall_issue() {
check_admin_referer( 'fs_resolve_firewall_issues' );

if ( ! current_user_can( is_multisite() ? 'manage_options' : 'activate_plugins' ) ) {
return;
}

$this->_admin_notices->remove_sticky( 'failed_connect_api' );

$pong = $this->ping();
Expand Down Expand Up @@ -4791,6 +4808,12 @@ function _email_about_firewall_issue() {
* @since 1.1.7.4
*/
function _retry_connectivity_test() {
check_admin_referer( 'fs_retry_connectivity_test' );

if ( ! current_user_can( is_multisite() ? 'manage_options' : 'activate_plugins' ) ) {
return;
}

$this->_admin_notices->remove_sticky( 'failed_connect_api_first' );

$pong = $this->ping();
Expand Down
9 changes: 7 additions & 2 deletions includes/managers/class-fs-admin-notice-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ protected function __construct(
*
*/
function dismiss_notice_ajax_callback() {
$this->_sticky_storage->remove( $_POST['message_id'] );
check_admin_referer( 'fs_dismiss_notice_action' );

if ( ! is_numeric( $_POST['message_id'] ) ) {
$this->_sticky_storage->remove( $_POST['message_id'] );
}

wp_die();
}

Expand Down Expand Up @@ -518,4 +523,4 @@ private function get_notices_type() {
}

#endregion
}
}
6 changes: 5 additions & 1 deletion includes/sdk/Exceptions/ArgumentNotExistException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! class_exists( 'Freemius_InvalidArgumentException' ) ) {
exit;
}

if ( ! class_exists( 'Freemius_ArgumentNotExistException' ) ) {
class Freemius_ArgumentNotExistException extends Freemius_InvalidArgumentException {
}
}
}
6 changes: 5 additions & 1 deletion includes/sdk/Exceptions/EmptyArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! class_exists( 'Freemius_InvalidArgumentException' ) ) {
exit;
}

if ( ! class_exists( 'Freemius_EmptyArgumentException' ) ) {
class Freemius_EmptyArgumentException extends Freemius_InvalidArgumentException {
}
}
}
6 changes: 5 additions & 1 deletion includes/sdk/Exceptions/Exception.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! class_exists( 'Freemius_Exception' ) ) {
/**
* Thrown when an API call returns an exception.
Expand Down Expand Up @@ -71,4 +75,4 @@ public function __toString() {
return $str . $this->getMessage();
}
}
}
}
6 changes: 5 additions & 1 deletion includes/sdk/Exceptions/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! class_exists( 'Freemius_Exception' ) ) {
exit;
}

if ( ! class_exists( 'Freemius_InvalidArgumentException' ) ) {
class Freemius_InvalidArgumentException extends Freemius_Exception { }
}
}
6 changes: 5 additions & 1 deletion includes/sdk/Exceptions/OAuthException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! class_exists( 'Freemius_Exception' ) ) {
exit;
}
Expand All @@ -9,4 +13,4 @@ public function __construct( $pResult ) {
parent::__construct( $pResult );
}
}
}
}
4 changes: 4 additions & 0 deletions includes/sdk/FreemiusBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
* under the License.
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! defined( 'FS_API__VERSION' ) ) {
define( 'FS_API__VERSION', '1' );
}
Expand Down
5 changes: 4 additions & 1 deletion includes/sdk/FreemiusWordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

require_once dirname( __FILE__ ) . '/FreemiusBase.php';

Expand Down Expand Up @@ -709,4 +712,4 @@ private static function ThrowSquidAclException( $pResult = '' ) {
}

#endregion
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": "Freemius, Inc.",
"license": "GPL-3.0",
"homepage": "https://freemius.com",
"version": "2.5.0",
"version": "2.5.0.1",
"main": "gulpfile.js",
"dependencies": {},
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion require.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* @since 1.1.9
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

// Configuration should be loaded first.
require_once dirname( __FILE__ ) . '/config.php';
require_once WP_FS__DIR_INCLUDES . '/fs-core-functions.php';
Expand Down Expand Up @@ -47,4 +51,4 @@
require_once WP_FS__DIR_INCLUDES . '/class-fs-admin-notices.php';
require_once WP_FS__DIR_INCLUDES . '/class-freemius-abstract.php';
require_once WP_FS__DIR_INCLUDES . '/sdk/Exceptions/Exception.php';
require_once WP_FS__DIR_INCLUDES . '/class-freemius.php';
require_once WP_FS__DIR_INCLUDES . '/class-freemius.php';
2 changes: 1 addition & 1 deletion start.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @var string
*/
$this_sdk_version = '2.5.0';
$this_sdk_version = '2.5.0.1';

#region SDK Selection Logic --------------------------------------------------------------------

Expand Down
7 changes: 6 additions & 1 deletion templates/account/partials/addon.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* @var array $VARS
* @var Freemius $fs
Expand Down Expand Up @@ -443,4 +448,4 @@ class="edit"><?php echo esc_html( $activate_text ) ?></a>
</td>
<!--/ Optional Delete Action -->
<?php endif ?>
</tr>
</tr>
7 changes: 6 additions & 1 deletion templates/ajax-loader.php
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
<div class="fs-ajax-loader" style="display: none"><?php for ( $i = 1; $i <= 8; $i ++ ) : ?><div class="fs-ajax-loader-bar fs-ajax-loader-bar-<?php echo $i ?>"></div><?php endfor ?></div>
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div class="fs-ajax-loader" style="display: none"><?php for ( $i = 1; $i <= 8; $i ++ ) : ?><div class="fs-ajax-loader-bar fs-ajax-loader-bar-<?php echo $i ?>"></div><?php endfor ?></div>
10 changes: 8 additions & 2 deletions templates/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

$.post( ajaxurl, {
action: 'fs_toggle_debug_mode',
// As such we don't need to use `wp_json_encode` method but using it to follow wp.org guideline.
_wpnonce : <?php echo wp_json_encode( wp_create_nonce( 'fs_toggle_debug_mode' ) ); ?>,
is_on : ($(this).hasClass( 'fs-on' ) ? 1 : 0)
}, function ( response ) {
if ( 1 == response ) {
Expand Down Expand Up @@ -121,7 +123,8 @@
if (optionName) {
$.post(ajaxurl, {
action : 'fs_get_db_option',
_wpnonce : '<?php echo wp_create_nonce( 'fs_get_db_option' ) ?>',
// As such we don't need to use `wp_json_encode` method but using it to follow wp.org guideline.
_wpnonce : <?php echo wp_json_encode( wp_create_nonce( 'fs_get_db_option' ) ); ?>,
option_name: optionName
}, function (response) {
if (response.data.value)
Expand All @@ -141,7 +144,8 @@
if (optionValue) {
$.post(ajaxurl, {
action : 'fs_set_db_option',
_wpnonce : '<?php echo wp_create_nonce( 'fs_set_db_option' ) ?>',
// As such we don't need to use `wp_json_encode` method but using it to follow wp.org guideline.
_wpnonce : <?php echo wp_json_encode( wp_create_nonce( 'fs_set_db_option' ) ); ?>,
option_name : optionName,
option_value: optionValue
}, function () {
Expand Down Expand Up @@ -738,6 +742,8 @@ class="dashicons dashicons-download"></i> <?php fs_esc_html_echo_inline( 'Downlo

$.post(ajaxurl, {
action : 'fs_get_debug_log',
// As such we don't need to use `wp_json_encode` method but using it to follow wp.org guideline.
_wpnonce : <?php echo wp_json_encode( wp_create_nonce( 'fs_get_debug_log' ) ); ?>,
filters: filters,
offset : offset,
limit : limit
Expand Down
16 changes: 10 additions & 6 deletions templates/firewall-issues-js.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
notice = $( this ).parents( '.fs-notice' ),
ajaxActionSuffix = notice.attr( 'data-manager-id' ).replace( ':', '-' );

var data = {
action : 'fs_resolve_firewall_issues_' + ajaxActionSuffix,
error_type: error_type
};
var data = {
action : 'fs_resolve_firewall_issues_' + ajaxActionSuffix,
// As such we don't need to use `wp_json_encode` method but using it to follow wp.org guideline.
_wpnonce : <?php echo wp_json_encode( wp_create_nonce( 'fs_resolve_firewall_issues' ) ); ?>,
error_type: error_type
};

if ( 'squid' === error_type ) {
data.hosting_company = prompt( 'What is the name or URL of your hosting company?' );
Expand All @@ -39,7 +41,9 @@
}

if ( 'retry_ping' === error_type ) {
data.action = 'fs_retry_connectivity_test_' + ajaxActionSuffix;
data.action = 'fs_retry_connectivity_test_' + ajaxActionSuffix;
// As such we don't need to use `wp_json_encode` method but using it to follow wp.org guideline.
data._wpnonce = <?php echo wp_json_encode( wp_create_nonce( 'fs_retry_connectivity_test' ) ); ?>;
}

$( this ).css({'cursor': 'wait'});
Expand All @@ -56,4 +60,4 @@
});
});
});
</script>
</script>
7 changes: 6 additions & 1 deletion templates/partials/network-activation.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* @var array $VARS
* @var Freemius $fs
Expand Down Expand Up @@ -86,4 +91,4 @@
</tbody>
</table>
</div>
</div>
</div>
6 changes: 4 additions & 2 deletions templates/sticky-admin-notice-js.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

notice.fadeOut( 'fast', function() {
var data = {
action : 'fs_dismiss_notice_action_' + ajaxActionSuffix,
action : 'fs_dismiss_notice_action_' + ajaxActionSuffix,
// As such we don't need to use `wp_json_encode` method but using it to follow wp.org guideline.
_wpnonce : <?php echo wp_json_encode( wp_create_nonce( 'fs_dismiss_notice_action' ) ); ?>,
message_id: id
};

Expand All @@ -36,4 +38,4 @@
});
});
});
</script>
</script>

0 comments on commit 60bf619

Please sign in to comment.